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

Add g:ClangListSymbols() to list symbols #562

Open
wants to merge 1 commit 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
60 changes: 59 additions & 1 deletion plugin/clang/cindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,11 @@ def from_offset(tu, file, offset):
"""
return conf.lib.clang_getLocationForOffset(tu, file, offset)

@property
def isFromMainFile(self):
"""Get the file represented by this source location."""
return conf.lib.clang_Location_isFromMainFile(self)

@property
def file(self):
"""Get the file represented by this source location."""
Expand Down Expand Up @@ -732,10 +737,14 @@ def __repr__(self):
# A reference to a labeled statement.
CursorKind.LABEL_REF = CursorKind(48)

# A reference toa a set of overloaded functions or function templates
# A reference to a set of overloaded functions or function templates
# that has not yet been resolved to a specific function or function template.
CursorKind.OVERLOADED_DECL_REF = CursorKind(49)

# A reference to a variable that occurs in some non-expression
# context, e.g., a C++ lambda capture list.
CursorKind.VARIABLE_REF = CursorKind(50)

###
# Invalid/Error Kinds

Expand Down Expand Up @@ -919,6 +928,26 @@ def __repr__(self):
# pack.
CursorKind.SIZE_OF_PACK_EXPR = CursorKind(143)

# Represents a C++ lambda expression that produces a local function
# object.
#
# \code
# void abssort(float *x, unsigned N) {
# std::sort(x, x + N,
# [](float a, float b) {
# return std::abs(a) < std::abs(b);
# });
# }
# \endcode
CursorKind.LAMBDA_EXPR = CursorKind(144)

# Objective-c Boolean Literal.
CursorKind.OBJ_BOOL_LITERAL_EXPR = CursorKind(145)

# Represents the "self" expression in a ObjC method.
CursorKind.OBJ_SELF_EXPR = CursorKind(146)


# A statement whose specific kind is not exposed via this interface.
#
# Unexposed statements have the same operations as any other kind of statement;
Expand Down Expand Up @@ -1010,6 +1039,9 @@ def __repr__(self):
# Windows Structured Exception Handling's finally statement.
CursorKind.SEH_FINALLY_STMT = CursorKind(228)

# A MS inline assembly statement extension.
CursorKind.MS_ASM_STMT = CursorKind(229)

# The null statement.
CursorKind.NULL_STMT = CursorKind(230)

Expand Down Expand Up @@ -1039,6 +1071,20 @@ def __repr__(self):
CursorKind.CXX_OVERRIDE_ATTR = CursorKind(405)
CursorKind.ANNOTATE_ATTR = CursorKind(406)
CursorKind.ASM_LABEL_ATTR = CursorKind(407)
CursorKind.PACKED_ATTR = CursorKind(408)
CursorKind.PURE_ATTR = CursorKind(409)
CursorKind.CONST_ATTR = CursorKind(410)
CursorKind.NODUPLICATE_ATTR = CursorKind(411)
CursorKind.CUDACONSTANT_ATTR = CursorKind(412)
CursorKind.CUDADEVICE_ATTR = CursorKind(413)
CursorKind.CUDAGLOBAL_ATTR = CursorKind(414)
CursorKind.CUDAHOST_ATTR = CursorKind(415)
CursorKind.CUDASHARED_ATTR = CursorKind(416)

CursorKind.VISIBILITY_ATTR = CursorKind(417)

CursorKind.DLLEXPORT_ATTR = CursorKind(418)
CursorKind.DLLIMPORT_ATTR = CursorKind(419)

###
# Preprocessing
Expand All @@ -1047,6 +1093,14 @@ def __repr__(self):
CursorKind.MACRO_INSTANTIATION = CursorKind(502)
CursorKind.INCLUSION_DIRECTIVE = CursorKind(503)

###
# Extra declaration

# A module import declaration.
CursorKind.MODULE_IMPORT_DECL = CursorKind(600)
# A type alias template declaration
CursorKind.TYPE_ALIAS_TEMPLATE_DECL = CursorKind(601)

### Cursors ###

class Cursor(Structure):
Expand Down Expand Up @@ -3027,6 +3081,10 @@ def cursor(self):
[Type],
bool),

("clang_Location_isFromMainFile",
[SourceLocation],
bool),

("clang_parseTranslationUnit",
[Index, c_char_p, c_void_p, c_int, c_void_p, c_int, c_int],
c_object_p),
Expand Down
5 changes: 5 additions & 0 deletions plugin/clang_complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ function! s:DoPeriodicQuickFix()
call s:ClangQuickFix()
endfunction

function! g:ClangListSymbols()
execute s:py_cmd "vim.command('let l:list = ' + json.dumps(listSymbols()))"
return l:list
endfunction

function! s:ClangQuickFix()
" Clear the bad spell, the user may have corrected them.
syntax clear SpellBad
Expand Down
25 changes: 25 additions & 0 deletions plugin/libclang.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,31 @@ def getCompileParams(fileName):
return { 'args' : args,
'cwd' : params['cwd'] }

def listSymbols():
global debug
debug = int(vim.eval("g:clang_debug")) == 1
params = getCompileParams(vim.current.buffer.name)
timer = CodeCompleteTimer(debug, vim.current.buffer.name, -1, -1, params)

list = []
def listSymbols(cursor):
for c in cursor.get_children():
if c.location.file is None or \
c.location.file.name.startswith('/usr/include') or \
not c.location.isFromMainFile or \
not c.kind.is_declaration():
continue
list.append(c.spelling)
listSymbols(c)

with libclangLock:
tu = getCurrentTranslationUnit(params['args'], getCurrentFile(),
vim.current.buffer.name, timer)
listSymbols(tu.cursor)
timer.finish()

return list

def updateCurrentDiagnostics():
global debug
debug = int(vim.eval("g:clang_debug")) == 1
Expand Down