Sublime Forum

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

#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

#55

Sublime normally uses 64MB after start. With this plugin it quickly raises up to 800MB. :smile:
Is it the price I have to pay for using this plugin or something might be wrong? Granted, the project I’m working on is quite big.

BTW. Another question. When I have header file opened, usually the “Go to implementation/definition” won’t work. Is that normal? I suppose that plugin works in context of opened file only and then resolves all includes from here. In which case it’s probably normal as only cpp file includes the main include with all configurations.

0 Likes

#56

It could be the price, it could be something wrong. I’ve not investigated, and probably won’t unless I notice memory usage drifts higher and higher (in other words a definite memory leak somewhere).

It’s a compiler so it works with the current file only. If you don’t include the definitions needed for that specific file, then the compiler does not know about them and can’t go to the definition.

0 Likes

#57

I tried it out on a reasonably big project, and when I opened about 15 files, it was using 4GB of RAM. From what I saw of the source, it just accumulates translation units in the cache and never flushes them out?

0 Likes

#58

They are flushed when you close the file or you can do it manually via “alt+d,alt+c”.

0 Likes

#59

BTW, you might also be interested in setting:

[code] // If set to true will warm up the cache for supported files
// when they are opened
“cache_on_load”: false,

// When set to true a reparse command will be triggered
// when a view is activated
"reparse_on_activated": false,

// When set to true a reparse command will be triggered
// when a view is saved
"reparse_on_save": false,

[/code]
in your SublimeClang user settings. This way the file is only parsed when you trigger an auto complete event or a go to definition/implementation request. You’ll have to wait for a couple of seconds while the file is being compiled though.

You might also want to tweak the following value to something other than the default:

// This is the bitmask sent to index.parse. // For example, to be able to go to the definition of // preprocessed macros, set it to 1, for using an implicit // precompiled header set it to 4 and for caching completion // results, set it to 8. Or all together 1+4+8=13. // // See http://clang.llvm.org/doxygen/group__CINDEX__TRANSLATION__UNIT.html#gab1e4965c1ebe8e41d71e90203a723fe9 // and http://clang.llvm.org/doxygen/Index_8h_source.html // for more details "index_parse_options": 13,

0 Likes

#60

What do you think about only keeping the N most recently-activated TUs in memory? Or even better, the N most recent megabytes worth of TUs? Another idea is to persist the TUs to disk when they are unloaded from memory so it won’t need to recompile the file the next time it’s opened/activated.

0 Likes

#61

I’m unlikely to look into that myself, but feel free to submit a patch/pull request.

0 Likes

#62

Don’t know what I’m doing wrong here. It seems like nothing is being found from my project. I’m not at all certain what I have to include.

I’ve dragged the entire source for this project into sublime edit, and added the source directory (and package directory which includes more src) to the clang settings like so [1]. I’m getting the following error:

D:\blahcompany\MadScience\Project\blah\dev\Source\UI\blah_Screens\Pod\Online\UIScreenPublishReview.cpp:8,10 - Fatal - 'Creation/CreationManager.hpp' file not found Did you configure the include path used by clang properly?

on the line:

#include <Creation/CreationManager.hpp>

This Creation/CreationManager should be found in “D:/blahcompany/MadScience/Project/blah/dev/Source/Creation/CreationManager.hpp”

[1] my settings:

"options":
    
        "-Wall",
        "-I/usr/lib/clang/3.0/include/",
        "-I/usr/lib/clang/2.1/include/",
        "-I/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/",
        "-I/usr/lib/gcc/i686-apple-darwin11/4.2.1/include/",
        // If you code for iOS, you want to have something like the following here:
        //"-isysroot",
        //"/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk",
        //"-D__IPHONE_OS_VERSION_MIN_REQUIRED=40300",
        "-IC:/MinGW/include",
        "-I/path/to/sources/1",
        "-I/path/to/sources/2",
        "-I/D:/blahcompany/MadScience/Project/blah/dev/Package/",
        "-I/D:/blahcompany/MadScience/Project/blah/dev/Source/"
    ]
0 Likes

#63

[quote] "-I/D:/blahcompany/MadScience/Project/blah/dev/Package/", "-I/D:/blahcompany/MadScience/Project/blah/dev/Source/"[/quote]

Try removing the first “/” before D:

0 Likes

#64

[quote=“quarnster”]
Try removing the first “/” before D:[/quote]

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/"

0 Likes

#65

+1 tiktaalik

My project tree :

~/myproject/Makefile
~/myproject/src/*.cpp
~/myproject/include/*.hpp

My project’s settings :

{
	"settings":
	{
		"sublimeclang_options":
		
			"-W",
			"-Wall",
			"-Wextra",
			"-Werror",

			"-I${home}/myproject/include",

			"-I/usr/lib/clang/3.0/include/",
			"-I/usr/lib/clang/2.1/include/",
			"-I/usr/lib/gcc/i686-apple-darwin10/4.2.1/include/",
			"-I/usr/lib/gcc/i686-apple-darwin11/4.2.1/include/"
		]
	},
	"folders":
	
		{
			"path": "myproject"
		}
	]
}

What’s wrong?

0 Likes

#66

Try clearing the cache (alt+d,alt+c) and if that doesn’t work open up sublimeclang.py and add a “print opts” before the return in the function “get_opts”. Then check the python console for what options are actually used to see if that gives you any clues.

0 Likes

#67

That still doesn’t work. I tried everything (absolute, relative path, in my projects settings and in general settings of sublimeclang …)

0 Likes