Fast C++ auto completion plugin based on clang. The downside is that it has a compiled component. I made a pre-release on GitHub with binaries that you can download and try.
It’s very much experimental at this point, so I would be very grateful if you report any issues or crashes. Currently only Linux/OSX 64-bit builds are present.
The way this plugin works in practice is as follows. You’re working on a big CMake-enabled project and you have your build folder somewhere with your build artifacts. In your top-level CMakeLists.txt file, you must have the line
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
somewhere, or you could configure your build folder with the option
$ cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ...
So that’s the first step. The second step is to let Clara know where that build folder is. You do that by having a .sublime-project
file, and in that project file you add the following dictionary:
"cmake":
{
"build_folder": "${project_path}/build"
}
Indeed, this supports any of the sublime-provided ${...}
variables, so you can point to the build folder relative to your project source folder.
The above two steps need to be performed for every new project. There are also some settings that need to be set up for the Clara plugin itself. In particular, Clara needs to know where all of the system headers on your platform are located. You can set that up by running the command
Clara: Generate System Headers
from the command palette. This calls a subprocess and assumes that the clang
binary is present on your system.
Another optional thing you can do for set up is to write default C+±syntax-specific completion settings to your Packages/User directory. You can do that by running the command
Clara: Create Auto-Complete Triggers
If such a file already exists, it will prompt you.
And that’s it, at that point you should get auto-completion results in implementation files (.cpp
) of your project.
I use this plugin myself (of course), and I am aware that in some rare cases it might crash the plugin_host
executable. Just restart sublime in that case and everything should be fine. These issues seem to stem from the clang library, so I’m not sure how to deal with that.
Some limitations:
- Doesn’t do auto-completion in header files.
- Must parse an implementation file before use.
- Doesn’t cache parsed files for later use.
- Might crash
plugin_host
in some cases.
Points (1) and (3) I’d like to fix sometime in the future. Point (2) is unavoidable, although with point (3) should not be a nuisance. Fixing point (4) would require me to analyze the clang library, which could be time-consuming.
Some pros:
- Very responsive.
- Easy to get up and running.
- Compilation-options-aware.
You can tweak the options by going to Preferences -> Packages Settings -> Clara -> Settings. Copy and paste some of the settings from the Default settings to your User settings and tweak them however you like. For instance, in the Default settings there is the line
"include_brief_comments": true
which will embed brief doxygen comments in the auto-completer widget. You can disable that by adding
"include_brief_comments": false
to your user settings.