Sublime Forum

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

#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

#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