pl-ca/ClangAutoComplete

Hangs on Completion

Closed this issue · 17 comments

The plugin is configured as expected, and clang builds successfully from the command line. However, on use of one of the autocomplete selectors, the entire sublime text instance will hang.

pl-ca commented

I've never seen this before, I need some more information to understand/reproduce the problem.
What OS are you on?
If you open the console View->Show Console, do you see any errors appearing?

Nothing is output to console when it hangs.

The issue happens with use of any of the selectors.

pl-ca commented

What OS are you using?
What version of clang?

Can you edit the plugin, add this line in ClangAutoComplete.py, line 113:

clang_cmd = clang_bin + " " + clang_flags + " " + clang_target + clang_includes
+print(clang_cmd)

Then, open the Sublime console, when the plugin triggers on auto-completion, see if you can a print with the clang command.

You can attempt to paste and run this command in a separate terminal and see if it gets stuck.

My best guess is that the clang binary itself is hanging and won't return.

OS is Windows 8.1 x64, Clang is 3.5.2

I already tried that when debugging it initially. There's nothing printed to the python console on selector input. I'm using '.' for the testing, but I can reproduce it with '>'.

I suspected a possible clash with SublimeLinter-contrib-Clang, but disabling that package produces no change in the behaviour.

It's times like these I curse the closed-source nature of Sublime - I could find out exactly where the crash was happening for you otherwise.

is there any more information that I can provide that would help?

pl-ca commented

I'm not sure how to reproduce, as it works for me with similar setup as you (also using SublimeLinter-contrib-clang).

If you wish to debug more, I can suggest you to add at the top of the file (ClangAutoComplete.py),

import inspect

and put this print everywhere in the file (from the very beginning of the function on_query_completions())

print(inspect.stack()[0][2])

It will print the line where the code has reached. Then, when you trigger the completion see in the console again if prints appear, and at what line they stop appearing. It might give us some insight into where it is hanging.

Interestingly enough, I get the following trace, but only after I kill the clang process.

66
69
76
85
95
112
117
121
126
131
clang -cc1 -x c++ -fsyntax-only -code-completion-at c:\users\%usr%\appdata\local\temp/auto_complete_tmp:10:6 c:\users\%usr%\appdata\local\temp/auto_complete_tmp -I . -I "\src" -I "\workspace\\src"
137

If I added more print statements it's likely that I would see them all the way to the return of the function. I'm printing the command in there from earlier debug work.

pl-ca commented

Can you try to open a command line and run that same command, see if it resolves without going through sublime?

clang -cc1 -x c++ -fsyntax-only -code-completion-at c:\users\%usr%\appdata\local\temp/auto_complete_tmp:10:6 c:\users\%usr%\appdata\local\temp/auto_complete_tmp -I . -I "\src" -I "\workspace\\src"

I've tried on my side to purposefully mess with the clang command and I could not get it to hang.
Worst thing is that no suggestions appear.

I noticed that I'm using clang version 3.6.0 and you have 3.5.2. I would have to see if it makes a difference but I would not hold my breath.

It gives me an error as follows:

In file included from c:\users\Ara\appdata\local\temp/auto_complete_tmp:1:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/iostream:39:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/ostream:38:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/ios:38:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/iosfwd:40:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/bits/postypes.h:40:
In file included from /usr/lib/gcc/x86_64-pc-cygwin/4.9.3/include/c++/cwchar:44:
In file included from /usr/include/wchar.h:6:
/usr/include/sys/reent.h:14:10: fatal error: 'stddef.h' file not found
#include <stddef.h>
         ^

However, it proceeds to give me a correct set of autocompletions after that. Strangely enough, compilation of the file works fine!

You can find the list of completions here.

pl-ca commented

This seems pretty standard. The error should not really be a concern if the completion results appear.
After you had run this command the prompt came back by itself or you had to Ctrl-C out of it ?

The prompt returned by itself.

Have the same issue with clang 3.5.2. Sublime text hangs on completion and there is no any output in console. The command works well if i run it from my shell.

pl-ca commented

For reference the plugin is working for me on:

  • Windows 10
  • Sublime Text 3 Stable Channel, Build 3083.
  • Clang version 3.6.0

And on :

  • Centos 6.6
  • Sublime Text 3 Stable Channel, Build 3083
  • Clang version 3.4.2

I'm suspecting that for some reason the instruction output = subprocess.check_output(clang_cmd, shell=True) in the script is hanging.

Could you edit the plugin script (ClangAutoComplete.py) and put a print("test") before, and after that line? Then open the console and trigger completion to see if both lines are printing before the hang.

If you can confirm that this instruction is hanging I'll investigate if something else can be used.

image
And it hangs with no any output in console. Thanks for such a fast reply!

Also after crushing a editor it leaves a clang and it's shell processes running.
I am using Windows 10 and ST 3083.

pl-ca commented

That is weird. I'm not sure why you don't see the print. However, considering what the previous submitter said

Interestingly enough, I get the following trace, but only after I kill the clang process.

and your new information, it looks to me that something is different with clang 3.5.2 that you both are using that causes it to hang when invoked through the check_output command.

Can you try installing newer clang version? In my case (for Windows) I had directly downloaded binaries from here http://llvm.org/releases/download.html

If I get some free time I'll try to install clang 3.5.2 on my side and see.

Thank you! Installing a new clang fixed the problem. I guess the issue was in cygwin clang.

pl-ca commented

Glad you could fix this issue! I assume that it would also resolve the issue iamrecursion was facing.
I updated the Readme to warn other users against this problem and will close this bug.

Can confirm that Cygwin Clang appeared to be the issue! Thanks. 👍