Home Download Buy Blog Forum Support

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

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

Postby quarnster on Thu Dec 01, 2011 6:32 pm

I started a plugin for clang autocompletion. It's pretty functional already, but does need more work. Check it out if you're coding in C/C++
http://github.com/quarnster/SublimeClang
Last edited by quarnster on Sun Dec 04, 2011 10:42 am, edited 1 time in total.
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am

Re: clang (C/C++) autocomplete

Postby dwm on Sun Dec 04, 2011 3:58 am

Hey, this is really cool!

It seems a little bit buggy still with the completions (it listed several symbols that weren't valid), but still it's a great idea and a good start for sure.

I mostly code in objective-C and objective-C++ when I use the C family of languages, so I modified line 116 in sublimeclang.py to include it as an allowed language:

Code: Select all
if language != "c++" and language != "c" and language != "objc":


I was happy to find that that seemed to at least make auto-completion work in my .m file. It didn't seem to pick up unused variables and stuff like that though which worked for regular .c files.

Could you take a look at adding objective-C support? Perhaps the -ObjC flag needs to be passed to clang.

Also, does this hook into the clang static analyzer, or just scan for standard warnings?

Anyway, I'm really looking forward to see where this goes. It's great to be able to get some of the power xcode has from clang integration in sublime text :)
dwm
 
Posts: 10
Joined: Tue Nov 22, 2011 11:35 pm

Re: clang (C/C++) autocomplete

Postby quarnster on Sun Dec 04, 2011 10:39 am

I'm not too familiar with Objective-C/Objective-C++, but I've just submitted a shot at adding basic support.

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.

It's not hooked up to the static analyzer, just the regular compiler. The static analyzer looks cool though, maybe I'll dig into that as time allows.
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am

Re: clang (C/C++/Objective-C/Objective-C++) autocomplete

Postby jeberius on Sun Dec 04, 2011 1:55 pm

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:
Code: Select all
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
Code: Select all
unsaved_files = [(view.file_name(), view.substr(Region(0, view.size())))]


Greetings, and keep up the great work!
Julian
jeberius
 
Posts: 7
Joined: Fri Feb 04, 2011 1:16 pm

Re: clang (C/C++/Objective-C/Objective-C++) autocomplete

Postby quarnster on Sun Dec 04, 2011 3:03 pm

Only reason for the 65536 would be not being too familiar with the plugin api. Thanks for the fix and the visual marker changes :)
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am

Re: clang (C/C++/Objective-C/Objective-C++) autocomplete

Postby pthiben on Sun Dec 04, 2011 6:39 pm

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:
Code: Select all
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
pthiben
 
Posts: 2
Joined: Sun Dec 04, 2011 6:33 pm

Re: clang (C/C++/Objective-C/Objective-C++) autocomplete

Postby quarnster on Sun Dec 04, 2011 8:18 pm

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:

Code: Select all
    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)
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am

Re: clang (C/C++/Objective-C/Objective-C++) autocomplete

Postby pthiben on Mon Dec 05, 2011 12:34 am

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
pthiben
 
Posts: 2
Joined: Sun Dec 04, 2011 6:33 pm

Re: clang (C/C++) autocomplete

Postby dwm on Tue Dec 06, 2011 3:41 am

quarnster wrote:I'm not too familiar with Objective-C/Objective-C++, but I've just submitted a shot at adding basic support.


Great, thanks :)

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.

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.


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.
dwm
 
Posts: 10
Joined: Tue Nov 22, 2011 11:35 pm

Re: clang (C/C++/Objective-C/Objective-C++) autocomplete

Postby quarnster on Tue Dec 06, 2011 12:41 pm

FYI just got a chance to test it on Linux and it's not working there due to http://sublimetext.userecho.com/topic/8 ... -in-linux/ so upvote that one if you'd like to see Linux support.
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am

Next

Return to Plugin Announcements

Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 27 guests