Sublime Forum

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

#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

#68

I have the same issue as GMath. I’m less informed than he is probably. Could anyone help me?

My current setup below-
*(http://i.imgur.com/dYtSz.jpg)

Windows 7 64, running ST2 32bit*

0 Likes

#69

[quote=“JesseMeyer”]I have the same issue as GMath. I’m less informed than he is probably. Could anyone help me?

My current setup below-
(http://i.imgur.com/dYtSz.jpg)
That spaces in path look suspicious. Maybe try to move project to path without spaces.[/quote]

0 Likes

#70

Thanks for the suggestion. Unfortunately, after removing spaces (and other “special” characters) from both the directories and the include paths, and clearing the cache, the problem persists.

0 Likes

#71

I’m very thankful to the author of this excellent plugin! I’d add the following to the list of suggestions:

]When a header with #pragma once is analyzed, clang emits a warning #pragma once in main file As I can reason after skimming through the sources of clang, that warning can’t be disabled per se, only with -w and the like, which can obviously be an overkill. Maybe the plugin could filter out such warnings when analyzing headers (or any sources, really, it wouldn’t harm)./]
]Don’t know if that’s possible, but it would be great if the clang output window doesn’t pop out during the build, thus preventing to see whether the build was successful./]

0 Likes

#72

Is it possible that the “new” autocompletion present in the recent build will interfere with SublimeClang?

I was able to configure one of my smaler projects to generate a valid cache and I (sometimes) have completion
but along the clang-completion there seems to be the normal autocomplete list. In some cases this seems to
go as far as completely replacing the clang completions (you can distinguish them by the type-signature in the completion).

I really think this plugin is a great idea - I’ve been using something similar on vim for quiet some time now.

One other thing I notice is that SublimeClang sometimes - without a reason - claims no to find a header it was
finding five minutes ago without any problems. Is there any way (or line of code) I can use to get the plugin to
display what it is passing to clang so I can check if my paths are configured correctly?

P.S. I’m able to test against linux / osx clang (3.1)

0 Likes

#73

[quote=“mnus”]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![/quote]

I’m using openSUSE 12.1 with python2.7. And I did the symlink by running the command:

# ln -s /usr/lib/python2.7/ /usr/share/SublimeText2/lib/

It did work for the plugin, as the “ctypes” error message no longer appear.
However, other problems arose after I’ve done the linkage. When I start st2 from Konsole(/usr/share/SublimeText2/sublime_text), an error message is shown in the Konsole:

'import site' failed; use -v for traceback

while the st2 is still able to run.
And the terminal inside st2 shows much more error messages:

Traceback (most recent call last): File "./sublime_plugin.py", line 1, in <module> import os ImportError: No module named os plugin init time: 0.116299 loading bindings loading pointer bindings found 1 files for base name Default.sublime-theme theme loaded app ready pre session restore time: 0.213486 using gamma: 1 (err: 0) AttributeError: 'module' object has no attribute 'on_activated'
The Clang did not work well once I did the linkage, and it’s the same when I did the linkage to python2.6 in another folder. So the solution seems dose not work at my laptop.
Hope the problem could be solved in next update~

0 Likes