Sublime Forum

Clang (C/C++/Objective-C/Objective-C++) autocomplete

#75

There seems to be a problem with the latest build of Sublime Text (2181) and this plugin. Per-project settings donā€™t work at all and the Sublimeclang error pane makes the caret disappear and re-appear every time you move it while the pane is visible. Downgrading to 2165 resolves these issues.

0 Likes

#76

Under Windows to autocomplete filenames in my ā€˜includeā€™ directories (like stdio.h) Iā€™ve added these lines to my ā€˜SublimeClang.sublime-settingsā€™ file (in ā€œoptionsā€ section) as below:

ā€œoptionsā€:

  ....
     .
     .
     .

    //include path for minGW
    ,"-IC:\\Program Files\\MinGW\\include"
    ,"-IC:\\Program Files\\MinGW\\lib\\gcc\\mingw32\\4.6.1\\include"
],

Nice coding!
(Iā€™ve typed commas first to know which line is added to the file and to remove just the lines if needed)
P.S. Your ā€˜SublimeClang.sublime-settingsā€™ file is in ā€˜%Appdata%\Sublime Text 2\Packages\SublimeClangā€™ folder.

0 Likes

#77

[quote=ā€œsujzā€]Try to use ā€œ//ā€ or ā€œ\ā€ instead of ā€œā€ for Windows.

[quote=ā€œtiktaalikā€]

Tried this but didnā€™t have an effect. Currently looks like so:

"-ID:/blah/MadScience/Project/blahproj/dev/Package/", "-ID:/blah/MadScience/Project/blahproj/dev/Source/"[/quote]

On Windows I have found that you should not have a trailing ā€˜/ā€™ in the path. Additionally I tend to use ā€˜\ā€™ instead of ā€˜/ā€™ because ā€˜ā€™ is the native character on Windows for file separation (and because its an escape character you need two of them).

0 Likes

#78

I thought Iā€™d replied previously but it looks otherwise - thank you for adding this feature, it is proving to be very useful.

0 Likes

#79

[quote=ā€œadnā€]Under Windows to autocomplete filenames in my ā€˜includeā€™ directories (like stdio.h) Iā€™ve added these lines to my ā€˜SublimeClang.sublime-settingsā€™ file (in ā€œoptionsā€ section) as below:

ā€œoptionsā€:

  ....
     .
     .
     .

    //include path for minGW
    ,"-IC:\\Program Files\\MinGW\\include"
    ,"-IC:\\Program Files\\MinGW\\lib\\gcc\\mingw32\\4.6.1\\include"
],

Nice coding!
(Iā€™ve typed commas first to know which line is added to the file and to remove just the lines if needed)
P.S. Your ā€˜SublimeClang.sublime-settingsā€™ file is in ā€˜%Appdata%\Sublime Text 2\Packages\SublimeClangā€™ folder.[/quote]

This works for me very well but I get a lot of errors from mingw files like this:
img651.imageshack.us/img651/3976 ā€¦ 181953.png

Any solution to fix/disable this ?

Temporarily i set show_output_panel to false to disable this annoying errors.

My options:

  "options":
  
    "-Wall",
    "-Wextra",
    "-ferror-limit=0",
    "-IE:/Dev/Tools/MinGW64/include",
    "-IE:/Dev/Tools/MinGW64/lib/gcc/x86_64-w64-mingw32/4.6.1/include",
    "-IE:/Dev/Libs/gmock-1.6.0/include",
    "-IE:/Dev/Libs/gmock-1.6.0/gtest/include",
    "-IE:/Dev/Libs/glfw-2.7.2/include",
    // projects paths here
  ]
0 Likes

#80

First of all, thanks for a great plugin!

I have stumbled upon a very annoying problem, that forces me to disable auto completion. :cry:

The problem I have is that auto completion does not seem to understand anonymous unions.
The library iā€™m trying to use has a struct that contains a type and a union with type dependent data.
The problem is that the type will always be auto completed (like there was no other members in the struct).
This makes it impossible to write code to access the members within the union.

I supply a minimal code example that can reproduce the problem.

struct MyStruct
{
   int type;
   union
   {
      int value_int;
      double value_double;
   };
};

int main(int argc, char const *argv])
{
   struct MyStruct my_struct;

   // try to use my_struct here with autocompletion enabled.
   // type is always auto completed and it is impossible
   // to write code to access value_int or value_double with auto complete enabled.

   return 0;
}
0 Likes

#81

Iā€™ve opened an issue for this on the SublimeClang homepage: github.com/quarnster/SublimeClang/issues/54

BTW, you can toggle the plugin on and off via the default keybinding alt+d,alt+t.

0 Likes

#82

This has now been fixed.

0 Likes

#83

Great! Thanks for the super quick fix!

0 Likes

#84

Iā€™ve been reading through this thread and am still wondering if there is a definitive answer on whether or not clang autocomplete works properly on Windows 64 Sublime 2 using MinGW for C++ STL. I have the following in my User Options for SublimeClang:

[code]{
ā€œoptionsā€:

    "-Wall",
    "-IC:\\MinGW\\include",
    "-IC:\\MinGW\\lib",
    "-IC:\\MinGW\\lib\\gcc\\mingw32\\4.6.2\\include\\c++",
    "-IC:\\MinGW\\lib\\gcc\\mingw32\\4.6.2\\include\\c++\\mingw32"
]

}
[/code]

and while it looks like the plugin is doing something, I keep getting the following error:

C:\MinGW\include\wchar.h:26,10 - Fatal - ā€˜stddef.hā€™ file not found

stddef.h is sitting in C:\MinGW\lib\gcc\mingw32\4.6.2\include and when I alter the options to include that directory, the previous error goes and I am confronted with:

C:\MinGW\lib\gcc\mingw32\4.6.2\include\c++\cwchar:145,11 - Error - no member named ā€˜fgetwsā€™ in the global namespace
C:\MinGW\lib\gcc\mingw32\4.6.2\include\c++\cwchar:147,11 - Error - no member named ā€˜fputwsā€™ in the global namespace
C:\MinGW\lib\gcc\mingw32\4.6.2\include\c++\cwchar:151,11 - Error - no member named ā€˜getwcā€™ in the global namespace
C:\MinGW\lib\gcc\mingw32\4.6.2\include\c++\cwchar:152,11 - Error - no member named ā€˜getwcharā€™ in the global namespace
C:\MinGW\lib\gcc\mingw32\4.6.2\include\c++\cwchar:157,11 - Error - no member named ā€˜putwcā€™ in the global namespace
C:\MinGW\lib\gcc\mingw32\4.6.2\include\c++\cwchar:158,11 - Error - no member named ā€˜putwcharā€™ in the global namespace
C:\MinGW\lib\gcc\mingw32\4.6.2\include\c++\bits/basic_ios.h:249,26 - Error - expected ā€˜)ā€™
C:\MinGW\lib\gcc\mingw32\4.6.2\include\c++\bits/basic_ios.h:249,17 - Note - to match this ā€˜(ā€™

Any suggestions would be greatly appreciated.

0 Likes

#85

Iā€™ve found a problem that if in my sublimeclang_options I include a directory with a large number of files (1249 to be exact), sublime crashes with the following error:

https://dl.dropbox.com/u/427616/crash.png

I happen to have VS10 installed, and this is the assertion in question:

_Myiter& operator++()
		{	// preincrement
 #if _ITERATOR_DEBUG_LEVEL == 2
		if (this->_Getcont() == 0
			|| this->_Ptr == 0
			|| ((_Myvec *)this->_Getcont())->_Mylast <= this->_Ptr)
			{	// report error
			_DEBUG_ERROR("vector iterator not incrementable");
			_SCL_SECURE_OUT_OF_RANGE;
			}

The Sublime console shows the following after the crash:

Exception AttributeError: "Cache instance has no attribute 'cache'" in <bound method Cache.__del__ of <translationunitcache.Cache instance at 0x000000000552F808>> ignored
Traceback (most recent call last):
  File ".\common.py", line 173, in worker
  File ".\translationunitcache.py", line 723, in task_reparse
  File ".\translationunitcache.py", line 849, in get_translation_unit
  File ".\translationunitcache.py", line 640, in __init__
  File ".\translationunitcache.py", line 108, in __init__
WindowsError: [Error -2147483645] One or more arguments are invalid

Sublime itself doesnā€™t crash until I click ā€˜abortā€™, so Iā€™m actually guessing the assertion is actually in libclang.dll.
This is with ST 2181 (Windows obviously).

Thanks.

0 Likes

#86

Iā€™ve opened up a new issue on github for this. Is your code base shareable so that I can get a copy of what you are seeing? If not, do you have a small test where this reproduces? Otherwise itā€™s unlikely to be fixed from my side as I donā€™t code on Windows and itā€™s not something Iā€™ve seen from my limited testing on Windows.

0 Likes

#87

Thanks. Iā€™m not able to share the codebase Iā€™m working on, but Iā€™ll try to reproduce the problem with test code. Barring that, I can help debug it a bit for you if you have some things youā€™d like me to try.

0 Likes

#88

I had a quick play with this yesterday on windows and was getting lockups

I seem to recall reading that clang hardcodes visual studio/mingw paths?

Does anyone know if itā€™s possible to steer it towards sources on a linux vm?

0 Likes

#89

castles_made_of_sand, if your lockups are the same as RyanJā€™s then maybe it has been fixed now. You could disable all the standard includes via ā€œ-nostdincā€. As long as the vm sources are available as a windows file path you should be able to steer it that way.

RyanJ, I think your issue has been fixed. As issue 74 hasnā€™t been fixed yet, could you use package control to remove SublimeClang, quit Sublime Text 2, delete the SublimeClang package folder and then re-install it via Package Control and see if the issue is gone now please?

0 Likes

#90

Awesome :smile: Thanks. Iā€™ll give it a crack.

0 Likes

#91

So, I just got a lockup, the console was open and there was a traceback:

[code]Traceback (most recent call last):

File ".\sublimeclang.py", line 553, in recompile
File ".\translationunitcache.py", line 776, in reparse
File ".\translationunitcache.py", line ???, in get_opts_script
File ".\common.py", line 82, in expand_path

TypeError: unsupported operand type(s) for %: ā€˜NoneTypeā€™ and ā€˜dictā€™
[/code]

(FFFF I just typed that in by hand and seem to have fucked up one of the line numbers :smile:)

Dunno how itā€™s related to the lockup, but that 's the last bit info in the console.

0 Likes

#92

From a superficial look, not really understanding the why/what/how of the locking , I can see a lack of try/finally with some uses of the locks, so an exception will mean the lock doesnā€™t get released.

Seems like itā€™s a dictlike.get(key, None) % dict() situation

Will take a look

0 Likes

#93

Ah, using a Lock() instead of a reentrant lock, which if you grab in the same thread again, wonā€™t cause these locks.

I made a 1 character change to RLock and that same exception no longer causes the freeze.

Traceback (most recent call last): File ".\sublimeclang.py", line 553, in recompile File ".\translationunitcache.py", line 776, in reparse File ".\translationunitcache.py", line 806, in get_opts_script File ".\common.py", line 82, in expand_path TypeError: unsupported operand type(s) for %: 'NoneType' and 'dict'

Iā€™ll patch LockedVariable to make it a context manager.

0 Likes

#94

Is there any way to get contextually aware auto completion?

For example, say I have my cursor, represented as ā€œ|ā€, inside #include <|, Iā€™m getting completion choices for macros and what have you.

0 Likes