ctrl+shift+p filters: :st2 :st3 :win :osx :linux
Browse

Include Autocomplete

A Sublime Text plugin that enables autocompletion of .h files in #include directives

Details

Installs

  • Total 3K
  • Win 2K
  • Mac 359
  • Linux 872
Apr 20 Apr 19 Apr 18 Apr 17 Apr 16 Apr 15 Apr 14 Apr 13 Apr 12 Apr 11 Apr 10 Apr 9 Apr 8 Apr 7 Apr 6 Apr 5 Apr 4 Apr 3 Apr 2 Apr 1 Mar 31 Mar 30 Mar 29 Mar 28 Mar 27 Mar 26 Mar 25 Mar 24 Mar 23 Mar 22 Mar 21 Mar 20 Mar 19 Mar 18 Mar 17 Mar 16 Mar 15 Mar 14 Mar 13 Mar 12 Mar 11 Mar 10 Mar 9 Mar 8 Mar 7 Mar 6
Windows 0 0 0 0 0 0 0 0 0 0 2 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 2
Mac 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Linux 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 1 0 0

Readme

Source
raw.​githubusercontent.​com

Include Autocomplete

A Sublime Text plugin that enables autocompletion for .h files in #include directives.

Synopsis

This plugin will try to autocomplete file names for #include "" directives in C files. By default it will (recursively) look in the same directory as the file for which we are trying to autocomplete the #include, but you can set custom search locations in the .sublime-project file (see Settings).

When an item from the autocomplete suggestions is selected, the path relative to the include location is added to the include directive, together with the filename. For example, given the following layout for your include location:

/include/loctaion/
├── dir1
│   └── include
│       └── x.h
└── dir2
    └── include
        └── y.h

Selecting x.h from the autocomplete suggestions, will be autocompleted as dir1/include/x.h.

Also, if you already have a path in your #include directive, that path will be taken into account when searching for .h files. Using the same include location directory layout as before, autocompletion for #include "dir1/<...>" will only look for files in the dir1, not dir2.

Installation

The recommended way of installation is through Sublime Package Control.

Settings

Manual Setup

To add locations where the plugin should look for .h files, add the following to your .sublime-project file:

{
    "include_autocomplete_settings":
    {
        "include_locations":
        [
            {
                "path": ".",
                "ignore": []
            },
            {
                "path": "<path/to/include/directory>",
                "ignore": ["<exclude1>", "<exclude2>", ...]
            },
            ...
        ]
    }
}

The “include locations” key is a list of dictionaries, each containing the following keys:

  • path: The directory where we should (recursively) look for .h files. This path can be either absolute or relative. In the latter case, we will look relative to the directory of the file in which we are trying to autocomplete an #include directive. This variable supports snippet-like variables, e.g. ${project_path}/include.
  • ignore: A list of paths relative to path, that we should ignore when searching for .h files.

Compilation Database

The plugin can also take a compilation database into account. When you use EasyClangComplete to specify your compilation database, you have to do nothing at all. The plugin will use EasyClangComplete's settings in your .sublime-project. To clarify, the plugin expects something of the form

{
    "settings":
    {
        "ecc_flags_sources":
        [
            {
                "file": "compile_commands.json",
                "search_in": "$project_base_path/build"
            }
        ]
    }
}

If this key is not present in "settings", the plugin also attempts to look for a "compile_commands" key that specifies the directory where compile_commands.json lives. Again, arbitrary snippet-like variables are possible. To clarify, the plugin looks for something of the form

{
    "settings":
    {
        "compile_commands": "${project_path}/build"
    }
}

If a compilation database is found, and we are inside a header file, the plugin will collect all possible include locations from the compilation database. If we're in an implementation file, the plugin will only add the include directories for that specific implementation file. If the implementation file is not present in the compilation database, a warning is printed to the console informing you that the implementation file is not in the compilation database.

No .sublime-project file

If the current file does not have an associated .sublime-project file, or the associated .sublime-project file does not contain the “include_locations” key, the following defaults will be used:

{
    "include_autocomplete_settings":
    {
        "include_locations":
        [
            {
                "path": ".",
                "ignore": []
            }
        ]
    }
}