Sublime Forum

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

#35

Great work, it took me a while to get it up an running since I am parsing Linux system headers on a Windows machine but now it’s good. Only one question though, is there a way to enable auto-completion in the global namespace without using ::? if I start typing something like ‘epoll_’, I want to see all the possible completion options right away. Right now it doesn’t show anything unless I type ‘::epoll_’.

0 Likes

#36

The default key-binding for triggering autocomplete operations in Sublime Text 2 is “ctrl+space”, so typing ‘epoll_’ and then hitting ctrl+space should work. You can also start typing and hit tab to select the highest scoring completion (another built in Sublime Text 2 feature).

If you are using the dev branch of Sublime Text 2 autocomplete will pop up automatically after typing a few characters, but personally I’ve turned that off since the completions in my sources takes too long :wink:

0 Likes

#37

Wow, this is a great little plugin.

On Mac, is there any way to pick which copy of libclang is used? I don’t know how much the ABI changes, but whichever version you are using / picking up is older than the (svn) copy of clang I am using (which has better c++0x support).

Hope that makes sense!

0 Likes

#38

azumanga, while I haven’t tried it myself, I see no reason why this wouldn’t be possible. Try to replace libclang.dylib in ~/Library/Application\ Support/Sublime\ Text\ 2/Packages/SublimeClang/ with the one you’ve compiled. Not sure if libclang is compiled by default as part of compiling clang, so you might need to specifically compile it as a separate step.

0 Likes

#39

What is preventing this plugin from working in the 64 bit version of Sublime Text for Windows? is it just the clang DLL file that needs to be recompiled or are there are things?

0 Likes

#40

In theory only the libclang.dll needs to be compiled in 64 bit mode. However ttvd tried that and still ran into issues. If someone gets it to work I’d be happy to accept a pull request/patch.

0 Likes

#41

Hi !

I can’t get to work sublimClang.
I’ve followed the tuto for the libclang.so and copy it in the root directory of the package, put I get the error message :

[code]"It looks like libclang.so couldn’t be loaded. On Linux you have to compile it yourself, or install it via your package manager. Please note that this plugin uses features from clang 3.0 so make sure that is the version you have installed.

Once installed, you need to copy libclang.so into the root of this plugin. See http://github.com/quarnster/SublimeClang for more details."[/code]

I’m runnig sabayon. I’have clang3.0 installed and I get the .so from “/usr/lib/llvm/libclang.so”

any idée? thanks

0 Likes

#42

Try putting it in /usr/lib/

0 Likes

#43

same problem

0 Likes

#44

What’s printed in the sublime console?

0 Likes

#45

[code]Reloading plugin /home/zaibon/.config/sublime-text-2/Packages/SublimeClang/errormarkers.py
Reloading plugin /home/zaibon/.config/sublime-text-2/Packages/SublimeClang/sublimeclang.py
Traceback (most recent call last):
File “./clang/cindex.py”, line 117, in get_cindex_library
return cdll.LoadLibrary(“libclang.so”)
File “/opt/SublimeText2/lib/python2.6/ctypes/init.py”, line 431, in LoadLibrary
return self._dlltype(name)
File “/opt/SublimeText2/lib/python2.6/ctypes/init.py”, line 353, in init
self._handle = _dlopen(self._name, mode)
OSError: libLLVM-3.0.so: Ne peut ouvrir le fichier d’objet partagé: Aucun fichier ou dossier de ce type
error: It looks like libclang.so couldn’t be loaded. On Linux you have to compile it yourself, or install it via your package manager. Please note that this plugin uses features from clang 3.0 so make sure that is the version you have installed.

Once installed, you need to copy libclang.so into the root of this plugin. See http://github.com/quarnster/SublimeClang for more details.

Traceback (most recent call last):
File “./sublime_plugin.py”, line 57, in reload_plugin
File “./sublimeclang.py”, line 33, in
from clang import cindex
File “./clang/cindex.py”, line 1233, in
_clang_getNumDiagnostics = lib.clang_getNumDiagnostics
AttributeError: ‘NoneType’ object has no attribute ‘clang_getNumDiagnostics’
found 9 files for base name Default.sublime-keymap
found 6 files for base name Main.sublime-menu
theme loaded[/code]

0 Likes

#46

My french is rusty, but it looks like your libclang.so depends on libLLVM-3.0.so. Try putting that file in /usr/lib also and repeat as needed until there is no more “.so” files listed in an error message like that.

0 Likes

#47

Fixed !

copying “/usr/lib/llvm/libLLVM-3.0.so” into the root directory of the Package did the trick !

thanks for your work ! Now I can fully switch to SublimText.

0 Likes

#48

Cool, I’ve updated the readme with information on libLLVM-3.0.so for other users if they run into this problem, thanks for letting me know

0 Likes

#49

The plugin is wonderful!
Finally get this plugin working for Objective C project with the following change to the options: ( you might want to change some of the path to fit your sdk/project )

    "add_language_option": false, // I set this to false and added -ObjC so that .h file will be parsed as Objective-C even when the syntax selected as c/c++; alternative choice is to force all .h open as Objective-C

    // Any options you want to give to clang
    "options":
    
        "-Wall",
        "-ObjC",
        "-fexceptions",
        "-fasm-blocks",
        "-mmacosx-version-min=10.6",
        "-gdwarf-2",
        "-Wno-sign-conversion",
        "-fobjc-abi-version=2",
        "-fobjc-legacy-dispatch",
        "-D__IPHONE_OS_VERSION_MIN_REQUIRED=30000",
        "-isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk",
        "-F/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/System/Library/Frameworks",
        "-I/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/usr/include",
        "-I/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/usr/include/libxml2",
        "-I/MyCode/Interface",
        "-I/MyCode/Core",
        "-I/MyCode/Headers"
    ]

A wish list (no pressing):

  • parsing configuration on per project basis, currently it seems not possible as the plugin load setting by sublime.load_settings(), maybe consider read it from view.settings() as well?
  • showing a “syntax error” indicate for the view on the status bar (view.set_status(“clang”, “Clang: Syntax Error”))
  • command to navigate through error positions
  • option to show error panel only when check after saved ( a bit annoy when it keeps show up when writing code )
0 Likes

#50

Thanks for the suggestions, I’ve opened up feature request issues on the project page so that I don’t forget about them.

If any one else suggested something and it’s not implemented already, please let me know or file a feature request issue for that yourself.

0 Likes

#51

MikeSmith and freewizard, Per project settings is now possible. See here and here for more details

0 Likes

#52

Shortcuts starting with ctrl+d works quite well on Mac but on Windows they interfere with very useful expand selection shortcut.

0 Likes

#53

@quarnster

Thank you for this excellent patch! Seems to be working properly on Windows, Sublime x64 build.

There are certain issues with Clang not being able to properly parse MS headers, but that’s something else. Also for some reason I cannot settings / sublimeclang_options in .sublime-project … it does not work. However modifying options in SublimeClang.sublime-settings (adding compile options, include paths, etc) seems to work.

Thanks again, pretty awesome.

0 Likes

#54

The cache isn’t cleared when modifying the project settings, so you might have to issue a manual clear cache for the project settings to take effect.

There are some command line options related to parsing MS headers, see clang.llvm.org/docs/UsersManual.html#c_ms.

0 Likes