/EasyClangComplete

:boom: C/C++ autocompletion in Sublime Text 3 for human beings

Primary LanguagePythonMIT LicenseMIT

EasyClangComplete

Plugin for Sublime Text 3 for easy to use, out of the box autocompletions for C, C++, Objective-C, and Objective-C++.

Example

Release Downloads Month Travis Build Windows Build Codacy Badge Coverage Badge Donate Gratipay

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
  • If you don't have Package Control (you should)
    • download one of the releases from here and restart Sublime Text after unpacking.

2. Install clang

  • Ubuntu : sudo apt-get install clang
  • OSX : ships clang by default. You are all set!
  • Windows : install the latest release from clang website.
  • Other Systems : use your package manager or install from clang website.
  • clang website: http://llvm.org/releases/download.html

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 in User 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
      }
    }

These settings are prioritized in a configurable way. Check out the settings to learn more about it.

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 uses libclang with its python bindings. This method fully utilizes caching from libclang that makes your completions blazingly fast. It is unit tested to complete STL functions on Linux, OSX and Windows platforms.

There is also a fallback mode if something is wrong with the libclang one that parses the output from clang -Xclang -code-completion-at which is called from the command line.

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.

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, feel free 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!

The progress indicator idea is from ColorSublime plugin.

Some functionality is there only because of the awesome contributors to this project. To see their names plese check out the contributors page.

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.

Pull requests and some issues are partially managed by maintainerd.

Please don't jump into creating a Pull Request straight away and open an issue first. This way, we can synchronize our views on the problem, so that everyone avoids losing time.

There are two branches:

  • master: should be stable and generally following the last release. Used for urgent 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 must pass linters:
    • pep8
    • pep257: ignoring ["D209", "D203", "D204", "D213", "D406", "D407"]

Please ensure, that your code conforms to this.

Support it!

Donate Flattr this git repo Bountysource Beerpay Gratipay

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.

                     ╔═╗┌─┐┌─┐┬ ┬  ╔═╗┬  ┌─┐┌┐┌┌─┐  ╔═╗┌─┐┌┬┐┌─┐┬  ┌─┐┌┬┐┌─┐
                     ║╣ ├─┤└─┐└┬┘  ║  │  ├─┤││││ ┬  ║  │ ││││├─┘│  ├┤  │ ├┤
                     ╚═╝┴ ┴└─┘ ┴   ╚═╝┴─┘┴ ┴┘└┘└─┘  ╚═╝└─┘┴ ┴┴  ┴─┘└─┘ ┴ └─┘