EasyClangComplete
Plugin for Sublime Text 3 for easy to use, out of the box autocompletions for C and C++.
Jump right in!
You are just three simple steps away!
1. Install this plugin
- Best is to use Package Control
- CTRL+Shift+P and install
EasyClangComplete
- CTRL+Shift+P and install
- If you don't have Package Control (you should)
- download one of the releases from here.
2. Install clang
- Ubuntu:
sudo apt-get install clang
- Windows: install the latest release from
clang
website (v >= 3.9) - OSX: ships
clang
by default. You are all set! - on other systems refer to their package managers or install from
clang
website
3. Configure your includes
Using CMake?
Plugin will run cmake on a proper CMakeLists.txt
in your project folder and
will use information from it to complete your code out of the box.
Have a compilation database?
Plugin will search for a compilation database compile_commands.json
in the
project folder and will load it to complete your code. If you want to specify a custom path to a comilation database you can do it in settings:
"flags_sources": [
{"file": "compile_commands.json", "search_in": "<YOUR_PATH>"},
],
None of the above?
You will need a little bit of manual setup for now. Clang
will automatically
search for headers in the folder that contains the file you are working on and
its parent. If you have a more sophisticated project you will need to help
clang
just a little bit. There are three ways to do it.
Pick ANY of the following:
-
Set include dirs in
"common_flags"
setting inUser Settings
:- See default settings to get started. These flags will be included in every project you run.
-
Add
.clang_complete
file to the root of your project folder.- This file should contain all includes and macroses you want to use.
- Example file contents:
-Isrc -I/usr/include
-
Override
"common_flags"
setting in your project file! Just define the same setting in project specific settings with either one of two prefixes:"ecc_"
or"easy_clang_complete_"
. See the project file in this repo for a working example. Minimal example for clarity:{ "settings": { "ecc_common_flags": ["-Isrc", "-I/usr/include"], "easy_clang_complete_verbose": true } }
That's it! You're ready to use the plugin!
More on the plugin
All the essential information to make the plugin run is written above. If you are still interested in more details - please read on.
General info
The plugin has two modes:
- [DEFAULT]: uses
libclang
with its python bindings. This is the better method as it fully utilizes saving compilation database which makes your completions blazingly fast. It is a default method. It is also unit tested to complete STL functions on Linux and OSX platforms. It will also fully work for Windows as soon as clang 4.0 is released. See issue - [FALLBACK]: one that parses the output from
clang -Xclang -code-completion-at
run from the command line. This is a fallback method if something is wrong with the first one.
This plugin is intended to be easy to use. It should autocomplete STL out of
the box and is capable of working with multiple flag storages, such as a
compilation database or a .clang_complete
file. If you experience problems -
create an issue. I will try to respond as soon as possible.
Commands
Here are some highlights for the commands. You can see all commands in command pallet. Open it by pressing:
- Windows/Linux: Ctrl + Shift + P
- OSX: Cmd + Shift + P
All the commands of this plugin start with EasyClangComplete:
and should be
self explanatory. Open an issue if they are not.
Settings
Please see the default settings file shipped with the plugin for explanations and sane default values.
PLEASE RESTART SUBLIME TEXT AFTER EACH SETTINGS CHANGE
Credits
The whole work seen here was originally a fork of another repository: ClangAutoComplete
However, with time this plugin has grown quite different from its origin and
this is why you see it as a separate package now. Anyway, I encourage you to
check out what ClangAutoComplete
has to offer and come back if you still like
this plugin more.
The trick with multiple clang.cindex
files is inspired by this repo:
clangHelper. Thanks for inspiration!
If you are an experienced python developer and find that something in my code sucks completely - DO tell me. Python is not my main language and I am always willing to learn.
Some functionality is there only because of the help of the following users (in no particualr order):
@Ventero, @riazanovskiy, @rchl, @Mischa-Alff, @jdumas, @simia, @tastytea, @brupelo, @randy3k, @david9991.
Tests
Most crucial functionality is covered with unit tests using UnitTesting Sublime Text plugin.
Contributing
Contributions are welcome! Look at the issue list. If there is something you think you can tackle, write about it in that issue and submit a Pull Request.
There are two branches:
master
: should be stable and generally following the last release. Used for bug fixing.dev
: used to develop new features. Merges with master right before a new release.
Code style:
- Line width is
80
characters - Every public function should be documented.
- The code passes linters:
pep8
pep257
: ignoring["D209", "D203", "D204"]
Please ensure, that your code conforms to this.
Support it!
Current sponsor of this project is my sleep. Please buy me a cup of tea if you appreciate the effort.
Also, pull requests are welcome! And don't forget to tell people about this plugin! The more people use it - the merrier.