Sublime Forum

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

#95

You can disable the fast completions with alt+d,alt+f which will then fall back to clang’s built in autocomplete functionality which is more accurate but slower.

0 Likes

#96

Sweet, cheers :smiley:

I’ll be sending you some paypal love when I have some credit.

I’ve been getting paid cash via western union so nothing in the pig atm :unamused:

0 Likes

#97

How did you end up in the situation where options_script is None anyway? Because by default it’s set to “” so wouldn’t trigger this issue…

09:11 /tmp/SublimeClang $ curl -O http://cloud.github.com/downloads/quarnster/SublimeClang/SublimeClang.sublime-package % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 11.1M 100 11.1M 0 0 4207k 0 0:00:02 0:00:02 --:--:-- 4330k 09:11 /tmp/SublimeClang $ unzip SublimeClang.sublime-package Archive: SublimeClang.sublime-package inflating: Context.sublime-menu inflating: Default.sublime-commands inflating: Default.sublime-keymap inflating: Main.sublime-menu inflating: README.creole inflating: SublimeClang.sublime-settings creating: clang/ inflating: clang/__init__.py inflating: clang/cindex.py creating: clang/include/ inflating: clang/include/altivec.h inflating: clang/include/arm_neon.h inflating: clang/include/avxintrin.h inflating: clang/include/emmintrin.h inflating: clang/include/float.h inflating: clang/include/immintrin.h inflating: clang/include/iso646.h inflating: clang/include/limits.h inflating: clang/include/mm3dnow.h inflating: clang/include/mm_malloc.h inflating: clang/include/mmintrin.h inflating: clang/include/nmmintrin.h inflating: clang/include/pmmintrin.h inflating: clang/include/smmintrin.h inflating: clang/include/stdalign.h inflating: clang/include/stdarg.h inflating: clang/include/stdbool.h inflating: clang/include/stddef.h inflating: clang/include/stdint.h inflating: clang/include/tgmath.h inflating: clang/include/tmmintrin.h inflating: clang/include/varargs.h inflating: clang/include/wmmintrin.h inflating: clang/include/x86intrin.h inflating: clang/include/xmmintrin.h inflating: common.py inflating: errormarkers.py inflating: libcache.dll inflating: libcache.dylib inflating: libcache_x64.dll inflating: libclang.dll inflating: libclang.dylib inflating: libclang_x64.dll inflating: package.json creating: parsehelp/ extracting: parsehelp/__init__.py inflating: parsehelp/parsehelp.py creating: src/ creating: src/clang-c/ inflating: src/clang-c/Index.h inflating: src/CMakeLists.txt inflating: src/main.cpp inflating: staticanalyzer.py inflating: sublimeclang.py inflating: sublimeclang.sublime-project inflating: translationunitcache.py 09:11 /tmp/SublimeClang $ cat SublimeClang.sublime-settings | grep options_script "options_script": "", 09:11 /tmp/SublimeClang $

The right fix is to do try finally blocks as there shouldn’t be a need for reentrance. I’ll patch this up.

0 Likes

#98
return expand_path(get_setting("options_script", None, view), view.window())

I think after nuking/recloning fresh I just rewound the history on the settings file using a backups plugin. The keys must have changed.

I’ll revert it to make sure I have all the latest settings.

Yeah, I just changed it to use RLock as it was a quick 1 character fix to stop it locking so I could take a look at the code.

I don’t like editing in notepad LOL

Context managers, ie with blocks, are nice for that. Saves having try/finally every where.

0 Likes

#99

Thanks, no luck though. I’ve tried making a test project with the same include paths, but the error is sporadic. I don’t think that the one path which caused the error before is really the issue – it seems to be something else which happened to be triggered in this case.

I printed out the filename & opts in translationunitcache.py in the parse/reparse functions, but nothing seemed unusual.

0 Likes

#100

RyanJ, You could compile libcache (and possibly libclang too) yourself with debug symbols enabled, and you should be able to attach a debugger to Sublime Text 2 and get a proper stacktrace for this issue.

0 Likes

#101

FYI, it looks like one of your recent changes seems to have fixed the issue I was seeing. If I do see it again I’ll build the libs to debug it more (I’d been too busy to attempt that yet).

so… thanks! :smiley:

0 Likes

#102

Cool, thanks for the update :smile:

0 Likes

#103

edit:

Never mind. It did find my include files, but it throws numerous errors on the new header files from the Windows 8 SDK, so I’ll just leave it for now and try again later.

0 Likes

#104

Hey folks,

I’m trying to get SublimeClang to play friendly with Objective-C. I’ve followed the suggestions on this forum and the GitHub Page and added the following to my “options”:

"/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.2.sdk", "-D__IPHONE_OS_VERSION_MIN_REQUIRED=40300", "-I/Users/CVSS/Documents/Reader"

However, I still get the following error when I open a file in my project:

Fatal - 'UIKit/UIKit.h' file not found Did you configure the include path used by clang properly? See http://github.com/quarnster/SublimeClang for more details on how to configure SublimeClang.

I’m using the latest SDK, lateste build of ST2 and Running on Lion.

Any ideas? Thanks.

0 Likes

#105

I’m currently trying to get SublimeClang to work on my Windows notebook, but somehow I can’t (be aware, I’m not really a C++ pro :wink:).
I already figured out that somehow the header include paths are hard coded and therefore don’t match my GCC 4.7.0 installation under C:\MinGW\lib\gcc\mingw32\4.7.0 so I create an NTFS symlink from C:\MinGW\lib\gcc\mingw32\4.7.0 to C:\MinGW\lib\gcc\mingw32\4.6.2 which seems to work.
Alternatively I could pass the parameters -IC:/MinGW/lib/gcc/mingw32/4.7.0/include/c++ -IC:/MinGW/lib/gcc/mingw32/4.7.0/include/c++/mingw32 -IC:/MinGW/lib/gcc/mingw32/4.7.0/include/c++/backward each time when calling clang++ to get it to compiling something without telling me that it can’t find the headers files (which is quite tedious, of course).

But in Sublime Text neither of these solutions work. I always get the message, that some header file (e.g. ) could not be found. And when I add this to my user config:

[code]{
“options”:

    "-Wall",
    "-IC:/MinGW/lib/gcc/mingw32/4.7.0/include/c++",
    "-IC:/MinGW/lib/gcc/mingw32/4.7.0/include/c++/mingw32",
    "-IC:/MinGW/lib/gcc/mingw32/4.7.0/include/c++/backward"
]

}[/code]It can find that file, but then I get the message:

[quote]C:/MinGW/lib/gcc/mingw32/4.6.2/include/c++\cwchar:46,10 - Fatal - ‘wchar.h’ file not found
Did you configure the include path used by clang properly?
See github.com/quarnster/SublimeClang for more details on how to configure SublimeClang.[/quote]

What am I doing wrong?

I have MinGW installed to C:\MinGW and Clang to C:\MinGW\clang. Both their bin directories are in my $PATH variable. Compiling with clang works fine. Only SublimeClang does not.

Another issue:
I also tried installing SublimeClang on my Linux workstation, but that doesn’t work either. Building Python 2.6 fails with the message:

[quote]gcc: error: directory": No such file or directory
make: *** [Modules/getbuildinfo.o] Error 1[/quote]

And BTW what do I need Python 2.6 for? Why doesn’t it work Python 2.7 as well, which is installed anyway?

Would be great if someone could help me out with this.
Thanks. :smile:

0 Likes

#106

I’m trying to get SublimeClang to work for my dev setup. I’m currently running under Ubuntu 12.04, and have followed the instructions on the github page for installation/configuration. Whenever clang attempts to parse files, I keep getting an error like this:

sublime_text: /home/jasedit/.config/sublime-text-2/Packages/SublimeClang/src/build/llvm/tools/clang/lib/Lex/PreprocessingRecord.cpp:256: clang::PreprocessingRecord::PPEntityID clang::PreprocessingRecord::addPreprocessedEntity(clang::PreprocessedEntity*): Assertion `(PreprocessedEntities.empty() || !SourceMgr.isBeforeInTranslationUnit(BeginLoc, PreprocessedEntities.back()->getSourceRange().getBegin())) && "a macro directive was encountered out-of-order"' failed.
libclang: crash detected during parsing: {
  'source_filename' : '(null)'
  'command_line_args' : '-I/home/jasedit/.config/sublime-text-2/Packages/SublimeClang/clang/include', '-I/home/jasedit/project1/include', '-I/home/jasedit/project1/externals/include', '-x', 'c++', '/home/jasedit/project1/src/Main.cpp'],
  'unsaved_files' : ],
  'options' : 13,
}

Every time it attempts to parse a file. I’m not entirely sure what’s going on here, but I’m not getting any auto-completion results. Any ideas?

0 Likes

#107

I use Windows 7 x64, Sublime Text 2 dev channel, build 2216, MinGW 4.7.0


Clang analysis shows errors in headers mingw, but i compile the project with mingw32-g++ without errors or warnings.
Sorry for my english.

0 Likes

#108

My guess is missing include paths or a missing preprocessor define.

0 Likes

#109

Am I missing smth, but where is the autocompletion? I’ve passed headers path to the plugin (include in 10.8 SDK folder under the xcode.app) but still nothing is being autocompleted. Is there a way to get full-featured autocompletion like xcode and VS have? It’s so inconvenient to open a manpage every time I need to call a function =. No, srsly, how can people work this way? :open_mouth:
PS
I’m talking about plain C autocomplete. You now, strlen, sprintf, mkfifo, other stuff.

0 Likes

#110

My bad. Opened an issue: github.com/quarnster/SublimeClang/issues/136.

0 Likes

#111

[quote=“RyanJ”]

My guess is missing include paths or a missing preprocessor define.[/quote]

Yes. This is my experience after spending a couple of days fiddling with the plugin to get everything working, hope it helps someone.

Turning off the error limit (-ferror-limit=0) is helpful for debugging this kind of stuff.

To fix the winbase.h DECLSPEC_NORETURN error add the define GNUC=4

To fix “no member named ‘fgetws’ in the global namespace” etc in cwchar when using add the define MSVCRT

Include paths will vary by MinGW distribution and/or version, this is what works for me using the 4.7.2 package from nuwen.net;

[code] “options”:

"-ferror-limit=0",
"-D__GNUC__=4",
"-D__MSVCRT__",
"-isystem", "C:\\MinGW\\lib\\gcc\\i686-pc-mingw32\\4.7.2",
"-isystem", "C:\\MinGW\\lib\\gcc\\i686-pc-mingw32\\4.7.2\\include",
"-isystem", "C:\\MinGW\\lib\\gcc\\i686-pc-mingw32\\4.7.2\\include-fixed",
"-isystem", "C:\\MinGW\\include",
"-isystem", "C:\\MinGW\\include\\c++\\4.7.2",
"-isystem", "C:\\MinGW\\include\\c++\\4.7.2\\i686-pc-mingw32",
"-Wall"

]
[/code]

Great plugin, thanks very much :smile:

0 Likes

#112

And now a question. Is there any way to get the plugin to provide auto-complete parameters for functions defined as a macro?

E.g. In the windows headers any function that takes a string has two versions, which are selected based on whether UNICODE is defined or not;

WINUSERAPI int WINAPI MessageBoxA(HWND,LPCSTR,LPCSTR,UINT);
WINUSERAPI int WINAPI MessageBoxW(HWND,LPCWSTR,LPCWSTR,UINT);

#ifdef UNICODE
#define MessageBox MessageBoxW
#else
#define MessageBox MessageBoxA
#endif

The auto-complete will show the MessageBox macro at the top of the list, but choosing it just enters MessageBox with no parameters. I have to go down the list and select MessageBoxA or MessageBoxW to get the parameters, which is a bit annoying.

0 Likes

#113

Hi guys.

First, thank you quarnster (and any other developer I’m not aware of) for this incredibly useful plugin.

I’m attempting to switch from VS to Sublime for all my C++ coding needs on Win7. I’ve successfully built my C++ code from within SLT2 using MSVC. The functionality I miss the most that’s left to integrate is code competition / checking. I’ve been following this plugin for awhile and unfortunately I do not know enough to figure this one out. I’ve researched and have attempted numerous times but to no avail. Please help.

I’m writing a game and have my code separated into two directories under a single folder.

F:/Game/EngineCode
“” / “” /GameCode

My VS install is standard.

Whenever I open a game source file, clang freaks out claiming that it cannot find any includes. Here is my sublime options and project settings.

[code]{
“folders”:

	{
		"path": "/F/C4-2.10/VisualStudio2012/C4"
	},
	{
		"path": "/F/C4-2.10/EngineCode"
	},
	{
		"path": "/F/C4-2.10/GameCode"
	}
],

"settings":
{
	"sublimeclang_options":
	
    	"-IF:/C4-2.10/EngineCode"
	]
}

}[/code]


    "options":
    
        "-isystem", "F:/C4-2.10/EngineCode",
        "-IF:/C4-2.10/GameCode",
        "-ferror-limit=0",
        "-Wall"
    ],

And for the strange part. In my game code, sometimes it will report the file locations with their directory slash reversed. It’s not uncommon to see

F:\Game\GameCode/someFile.h:19,10 - Fatal - ‘someInclude.h’ file not found (“someInclude” is not ever in the same directory as “someFile”).

If anyone would assist I’d be very grateful.

Thank you in advanced.

JM

0 Likes

#114

I absolutely love SublimeCLang!
One question: “sometimes”, SublimeCLang slows down the whole ST2. I mean: on a project that is normally working fine… at some point in time using CLang blocks ST2 every time I press a letter, waiting for the autocomplete. This is due to Clang, since if I disable it, (“enabled”: false) everything works
Sometimes, I also get messages from ST2 saying “A plugin clang is locking ST…” (or something similar).

I know my question is quite “vague”, but I have no further details, nor ideas what to look for…

Thank you in advance for any help.

0 Likes