Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed snippets expand key mapping #467

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*.vmb
*.cache
tags
*.swp
15 changes: 0 additions & 15 deletions README

This file was deleted.

64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
This plugin uses clang for accurately completing C and C++ code.

## Installation

- To build and install in one step, type: `$ make install`

- To build and install in two steps, type:

```
$ make
$ vim clang_complete.vmb -c 'so %' -c 'q'
```

- Alternatively, you can also put the files in `~/.vim/`

You need Vim 7.3 or higher, compiled with python support and ideally, with
the conceal feature.

## Minimum Configuration

- Set the `clang_library_path` to the directory containing file named
libclang.{dll,so,dylib} (for Windows, Unix variants and OS X respectively) or
the file itself, example:

```vim
" path to directory where library can be found
let g:clang_library_path='/usr/lib/llvm-3.8/lib'
" or path directly to the library file
let g:clang_library_path='/usr/lib64/libclang.so.3.8'
```

- Compiler options can be configured in a `.clang_complete` file in each project
root. Example of `.clang_complete` file:

```
-DDEBUG
-include ../config.h
-I../common
-I/usr/include/c++/4.5.3/
-I/usr/include/c++/4.5.3/x86_64-slackware-linux/
```

## Usage

The plugin provides list of matches, after that you pick completion from a
generic completion menu where <kbd>Ctrl+N</kbd>, <kbd>Ctrl+P</kbd> and alike
work and wrap around ends of list.

## License

See doc/clang_complete.txt for help and license.

## Troubleshooting

The first step is to check values of `'omnifunc'` and `'completefunc'` options
in a C++ buffer where completion doesn't work (the value should be
`ClangComplete`). This can be done with the following command:
`:set omnifunc? completefunc?`

Output of `:messages` command after startup could also show something useful in
case there were problems with plugin initialization.

If everything is fine, next step might be to load only clang_complete plugin
and see if anything changes.
8 changes: 8 additions & 0 deletions bin/cc_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ def parseArguments(arguments):
nextIsInclude = False
nextIsDefine = False
nextIsIncludeFile = False
nextIsIsystem = False

includes = []
defines = []
include_file = []
options = []
isystem = []

for arg in arguments:
if nextIsInclude:
Expand All @@ -44,6 +46,9 @@ def parseArguments(arguments):
elif nextIsIncludeFile:
include_file += [arg]
nextIsIncludeFile = False
elif nextIsIsystem:
isystem += [arg]
nextIsIsystem = False
elif arg == "-I":
nextIsInclude = True
elif arg == "-D":
Expand All @@ -54,6 +59,8 @@ def parseArguments(arguments):
defines += [arg[2:]]
elif arg == "-include":
nextIsIncludeFile = True
elif arg == "-isystem":
nextIsIsystem = True
elif arg.startswith('-std='):
options.append(arg)
elif arg == '-ansi':
Expand All @@ -66,6 +73,7 @@ def parseArguments(arguments):
result = list(map(lambda x: "-I" + x, includes))
result.extend(map(lambda x: "-D" + x, defines))
result.extend(map(lambda x: "-include " + x, include_file))
result.extend(map(lambda x: "-isystem" + x, isystem))
result.extend(options)

return result
Expand Down
87 changes: 87 additions & 0 deletions bin/generate_kinds.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#!/usr/bin/env python
#-*- coding: utf-8 -*-

import re
import sys
import os.path
import clang.cindex

# you can use this dictionary to map some kinds to better
# textual representation than just the number
mapping = {
1 : 't' , # CXCursor_UnexposedDecl (A declaration whose specific kind is not
# exposed via this interface)
2 : 't' , # CXCursor_StructDecl (A C or C++ struct)
3 : 't' , # CXCursor_UnionDecl (A C or C++ union)
4 : 't' , # CXCursor_ClassDecl (A C++ class)
5 : 't' , # CXCursor_EnumDecl (An enumeration)
6 : 'm' , # CXCursor_FieldDecl (A field (in C) or non-static data member
# (in C++) in a struct, union, or C++ class)
7 : 'e' , # CXCursor_EnumConstantDecl (An enumerator constant)
8 : 'f' , # CXCursor_FunctionDecl (A function)
9 : 'v' , # CXCursor_VarDecl (A variable)
10 : 'a' , # CXCursor_ParmDecl (A function or method parameter)
20 : 't' , # CXCursor_TypedefDecl (A typedef)
21 : 'f' , # CXCursor_CXXMethod (A C++ class method)
22 : 'n' , # CXCursor_Namespace (A C++ namespace)
24 : '+' , # CXCursor_Constructor (A C++ constructor)
25 : '~' , # CXCursor_Destructor (A C++ destructor)
27 : 'a' , # CXCursor_TemplateTypeParameter (A C++ template type parameter)
28 : 'a' , # CXCursor_NonTypeTemplateParameter (A C++ non-type template
# parameter)
29 : 'a' , # CXCursor_TemplateTemplateParameter (A C++ template template
# parameter)
30 : 'f' , # CXCursor_FunctionTemplate (A C++ function template)
31 : 'p' , # CXCursor_ClassTemplate (A C++ class template)
33 : 'n' , # CXCursor_NamespaceAlias (A C++ namespace alias declaration)
36 : 't' , # CXCursor_TypeAliasDecl (A C++ alias declaration)
72 : 'u' , # CXCursor_NotImplemented
501 : 'd' , # CXCursor_MacroDefinition
601 : 'ta', # CXCursor_TypeAliasTemplateDecl (Template alias declaration).
700 : 'oc', # CXCursor_OverloadCandidate A code completion overload candidate.
}

if len(sys.argv) != 2:
print("Usage:", sys.argv[0], "<path-to-Index.h>")
exit(-1)

index = clang.cindex.Index.create()
tu = index.parse(sys.argv[1])

kinds = None
for child in tu.cursor.get_children():
if (child.spelling == "CXCursorKind"):
kinds = child
break
else:
print("Index.h doesn't contain CXCursorKind where it is expected, please report a bug.")
exit(-1)

kinds_py_path = os.path.join(
os.path.dirname(
os.path.dirname(
os.path.abspath(__file__)
)
),
"plugin",
"kinds.py"
)

with open(kinds_py_path, "w") as f:
# First/Last pattern
fl = re.compile("CXCursor_(First|Last)[A-Z].*")

f.write("# !! GENERATED FILE, DO NOT EDIT\n")
f.write("kinds = {\n")

for kind in kinds.get_children():
# filter out First/Last markers from the enum
if fl.match(kind.spelling) is not None:
continue

text = mapping.get(kind.enum_value, kind.enum_value)
f.write("{0} : '{1}', # {2} {3}\n".format(kind.enum_value, text, kind.spelling, kind.brief_comment))

f.write("}\n")

# vim: set ts=2 sts=2 sw=2 expandtab :
27 changes: 17 additions & 10 deletions doc/clang_complete.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*clang_complete.txt* For Vim version 7.3. Last change: 2014 Apr 13
*clang_complete.txt* For Vim version 7.3. Last change: 2016 Sep 24


clang_complete plugin documentation
Expand Down Expand Up @@ -184,7 +184,7 @@ Default: 0

*clang_complete-user_options*
*g:clang_user_options*
Additionnal compilation argument passed to libclang.
Additional compilation argument passed to libclang.

Example: >
" compile all sources as c++11 (just for example, use .clang_complete for
Expand Down Expand Up @@ -239,11 +239,18 @@ Default: 1

*clang_complete-library_path*
*g:clang_library_path*
If libclang is not in your library search path, set this to the absolute path
where libclang is available. This should either be a directory containing a
file named libclang.[dll/so/dylib] or the clang shared library file itself.
If libclang is not in the library search path of your system, you should set
this variable to the absolute path of either directory containing
libclang.{dll,so,dylib} (for Windows, Unix variants and OS X respectively) or
to that file itself.
Default: ""

Example: >
" path to directory where library can be found
let g:clang_library_path='/usr/lib/llvm-3.8/lib'
" or path directly to the library file
let g:clang_library_path='/usr/lib64/libclang.so.3.8'
<
*clang_complete-sort_algo*
*g:clang_sort_algo*
How results are sorted (alpha, priority, none). Currently only works with
Expand All @@ -258,26 +265,26 @@ Default: 0
*clang_complete-complete_patterns*
*g:clang_complete_patterns*
If clang should complete code patterns, i.e loop constructs etc.
Defaut: 0
Default: 0

*clang_complete-jumpto_declaration_key*
*g:clang_jumpto_declaration_key*
Set the key used to jump to declaration.
Defaut: "<C-]>"
Default: "<C-]>"
Note: You could use the g:ClangGotoDeclaration() to do the same with a mapping.

*clang_complete-jumpto_declaration_in_preview_key*
*g:clang_jumpto_declaration_in_preview_key*
Set the key used to jump to declaration in a preview window.
Defaut: "<C-W>]"
Default: "<C-W>]"
Note: You could use the g:ClangGotoDeclarationPreview() to do the same with a mapping.

*clang_complete-jumpto_back_key*
*g:clang_jumpto_back_key*
Set the key used to jump back.
Note: Effectively this will be remapped to <C-O>. The default value is chosen
to be coherent with ctags implementation.
Defaut: "<C-T>"
Default: "<C-T>"

*clang_complete-make_default_keymappings*
*g:clang_make_default_keymappings*
Expand All @@ -290,7 +297,7 @@ Default: 1
Omnicppcomplete compatibility mode. Keeps omni auto-completion in control of
omnicppcomplete, disables clang's auto-completion (|g:clang_complete_auto|)
and enables only <C-X><C-U> as main clang completion function.
Defaut: 0
Default: 0

==============================================================================
6. Known issues *clang_complete-issues*
Expand Down
Loading