Sublime Forum

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

#4

Wow, this bundle works much better than I expected.

I have to admit, I expected it to fail on a complex project. I just tried it out on the source code of Postgresql. After pointing it to the correct include dir in clang.sublime-settings, it completes function calls (showing the correct parameter names and types) and structures (showing member names and types), and it does so very quickly!

Very nice plugin indeed!

I had only one problem: with very long C files it would show errors where there are none. I found the following line in sublimeclang.py to cause the problem:

unsaved_files = (view.file_name(), view.substr(Region(0, 65536)))]

I do not know why you introduced the artificial length limit. If I remove it, everything works beautifully for me. Specifically, I replaced the above line with

unsaved_files = (view.file_name(), view.substr(Region(0, view.size())))]

Greetings, and keep up the great work!
Julian

0 Likes

#5

Only reason for the 65536 would be not being too familiar with the plugin api. Thanks for the fix and the visual marker changes :smile:

0 Likes

#6

Hey guys,

I wanted to give this plugin a try with ST2 (x86 version) on Windows 7 64-bits and plugin version 5c43973 (latest today).

I get the following python error:

Traceback (most recent call last): File ".\sublimeclang.py", line 190, in recompile File ".\clang\cindex.py", line 208, in location ValueError: Procedure called with not enough arguments (4 bytes missing) or wrong calling convention
I believe it has something to do with the communication between Clang and the python plugin, but since my python skills are quite weak, Iā€™m not sure how to fix it.

Cheers

0 Likes

#7

Hmm. I get the same thing on my Windows installation, but nothing I tried seemed to fix it. Iā€™m starting to think that the dll itself is broken, I used the precompiled 2.9 from the llvm website.

Is anyone using this plugin successfully on windows? If I get no replies Iā€™ll just hack it to look like the following until someone can provide a proper fix:

    def location(self):
        import platform
        if platform.system() == "Windows":
            class hack:
                def __init__(self):
                    self.file = None
                    self.line = 0
                    self.column = 0
            return hack()

        return _clang_getDiagnosticLocation(self)
0 Likes

#8

FWIW, the hack seems to work on my machine as well. Iā€™ll try to figure out why I still have include problems, though the -I parameter seems to point to the proper directory.

Thanks

0 Likes

#9

Great, thanks :smile:

Iā€™m seeing a bit more of it working now. It does highlighting and stuff in my objective-C files. Unfortunately, it seems it still needs some flags set because clang is giving me some errors where there shouldnā€™t be. Iā€™ll try to take a look and see if I can figure out what the problem is and maybe submit a patch or something.

[quote]
As for listing symbols that arenā€™t available, I only list the completions provided by clang + some filtering. If you have any suggestions for how to better filter or any options that should be provided to clang to suggest better completions, Iā€™d be happy to change.[/quote]

Well, I just tried it again and I didnā€™t seem to notice the same behavior as before. But if it comes up again Iā€™ll try to investigate a bit more.

0 Likes

#10

FYI just got a chance to test it on Linux and itā€™s not working there due to sublimetext.userecho.com/topic/8 ā€¦ -in-linux/ so upvote that one if youā€™d like to see Linux support.

0 Likes

#11

Compiling libclang using Visual C++ was trivial so with the latest version in git getting the location of errors and warnings should be fine on Windows.

As for it not picking up your include paths, try modifying the user settings rather than the default settings. You can access those by ctrl+shift+P and typing ā€œSublimeClangā€.

0 Likes

#12

Regarding Linux errors

Iā€™m running Ubuntu 11.10 64bit. I was able to get this plugin working by symlinking /usr/lib/python2.6/ to sublime2ā€™s lib directory, and recompiling libclang.so to target a 64bit architecture.

1.) Install python2.6 via apt-get or synpactic.
2.) Backup python26.zip in sublime2ā€™s lib directory (just for safe measure). I did mv ā€œpython26.zip backup.python26.zipā€
3.) Symlink /usr/lib/python2.6/ to sublime2ā€™s lib directory.
4.) Download and compile clang. (You can probably get away with installing clang from the ubuntu repos)
5.) Copy libclang.so from the installed location into /.config/sublime-text-2/Packages/SublimeClang/

Iā€™m still left with the issue of Clang not being able to find ā€œstdarg.hā€, but I believe thatā€™s a clang bug and has nothing to do with this plugin.

Note to the the author of this plugin: Itā€™s probably best not to include the compiled library for linux in your repository, given that each architecture requires its own build. It may be a better idea just to have a text file instructing linux users to build and copy libclang themselves. Thanks for this awesome plugin!

0 Likes

#13

Thanks for the tip, Iā€™ve deleted the default libclang.so and added your work around to the readme at github.com/quarnster/SublimeClang/.

0 Likes

#14

Hi, I tried installing SublimeClang on Windows 7 x64 (x64 sublime 2), however it did not work. During install through Package manager I get:

Reloading plugin C:\Users\radix\AppData\Roaming\Sublime Text 2\Packages\SublimeClang\sublimeclang.py
Traceback (most recent call last):
  File ".\sublime_plugin.py", line 57, in reload_plugin
  File ".\sublimeclang.py", line 31, in <module>
    from clang import cindex
  File ".\clang\cindex.py", line 86, in <module>
    lib = get_cindex_library()
  File ".\clang\cindex.py", line 76, in get_cindex_library
    return cdll.LoadLibrary('libclang.dll')
  File ".\ctypes\__init__.py", line 431, in LoadLibrary
  File ".\ctypes\__init__.py", line 353, in __init__
WindowsError: [Error 193] %1 is not a valid Win32 application

Thanks.

0 Likes

#15

Until someone contributes a 64-bit libclang.dll, youā€™ll have to make do with using the 32 bit Sublime Text 2 if you want to use this plugin.

0 Likes

#16

Yeah I thought this was the case. I did manage to build libclang in 64 mode for windows. However, now I get these when itā€™s trying to autocomplete on -> or ::

Perhaps thereā€™s an issue with how I built itā€¦

Traceback (most recent call last):
  File ".\sublime_plugin.py", line 175, in on_query_completions
  File ".\sublimeclang.py", line 596, in on_query_completions
  File ".\clang\cindex.py", line 1568, in codeComplete
WindowsError: exception: access violation writing 0x00000000000C0000
Traceback (most recent call last):
  File ".\sublimeclang.py", line 175, in worker
  File ".\clang\cindex.py", line 1546, in reparse
WindowsError: exception: access violation writing 0x0000000004EC0000

Hereā€™s my libclang (x64, compiled using vc2010).
ttvd.org/temp/libclang_x64_vc2010.rar

Thanks!

0 Likes

#17

Are you working with huge files or is there any other reason you must use the 64-bit executable of Sublime Text 2?

0 Likes

#18

Hi,
I got it working on Arch Linux.
You have to add the header search path /usr/lib/clang/3.0/include to SublimeClangā€™s config. If your distribution doesnā€™t have clang 3.0 yet, you can find those headers in clang-3.0.src/lib/Headers of llvm.org/releases/3.0/clang-3.0.tar.gz

Thanks for your work, quarnster!

0 Likes

#19

Wowā€¦ this is utterly mind blowing even in its early state. My vote for best pluginā€¦ever?

I would have killed for the equivalent of visual studioā€™s f12, and now i have it, plus really good code completion that just works (still a bit rough, but its great still)ā€¦ props to you quarnster.

Edit: To help other newbies, to get the most out of it I had to change my options and add them to the User version of SublimeClang.sublime-settings like so: (on mac os lion, will try win 7 64 bit eventually)

"options":
	    
	        "-Wall",
	        "-std=c++11",
	        "-I/usr/lib/clang/3.0/include/",
	        "-I/Developer/usr/llvm-gcc-4.2/lib/gcc/i686-apple-darwin11/4.2.1",
	        "-I/Users/alanandersen/dev"
	    ]

Also, it seems once you install Xcode 4.2, all the gcc stuff is moved from /usr/ into /Developer, took a bit to figure that outā€¦

0 Likes

#20

Cheers for the props guys :smile:

Please let me know if you have any specific requests or suggestions for making it better. Pull requests with new features are welcome.

0 Likes

#21

Hi, sorry for the newbyness but, on windows, how do you specify the include path ? It seems to never find my standard c includes.

[quote]Z:\local\pegasusmanager\LIBPEGASUSMANAGER_01_00_00\bins\fpgaconfig\fpgaconfig.c:15,10 - Fatal - ā€˜stdint.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]

Thanks a lot :smile:

0 Likes

#22

You need to open up the SublimeClang settings and tweak the ā€œoptionsā€ list by adding ā€œ-IC:/wherever/your/include/files/areā€. A good start would be to search for stdint.h. Please let me know what path it resides in on your Windows installation and Iā€™ll add it as a default path.

0 Likes

#23

No i do not work with large files, but I found that x64 version of sublime is faster on my machine than x32 for w/e reason. Do you have any suggestion as to what might be the problem with my x64 libclang ?

Thanks.

0 Likes