From e804bea9fd0ade00d6d48a2473db1e8c4932b1f8 Mon Sep 17 00:00:00 2001 From: Mathias Rav Date: Wed, 1 Mar 2017 11:04:53 -0500 Subject: [PATCH 1/3] Change confusing docstring --- plugin/clang/cindex.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugin/clang/cindex.py b/plugin/clang/cindex.py index 6f805d88..9d1c6f55 100644 --- a/plugin/clang/cindex.py +++ b/plugin/clang/cindex.py @@ -1086,9 +1086,9 @@ def is_static_method(self): def get_definition(self): """ - If the cursor is a reference to a declaration or a declaration of - some entity, return a cursor that points to the definition of that - entity. + If the cursor is a declaration of some entity or a reference to a + declaration of some entity, return a cursor that points to the + definition of that entity. """ # TODO: Should probably check that this is either a reference or # declaration prior to issuing the lookup. From 608fe38a8002dabece9df11aa5beb4db117d1f38 Mon Sep 17 00:00:00 2001 From: Mathias Rav Date: Wed, 1 Mar 2017 11:05:39 -0500 Subject: [PATCH 2/3] Make gotoDeclaration support going to the type declaration (e.g. typedef statement) --- plugin/libclang.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugin/libclang.py b/plugin/libclang.py index fe35e828..e068c59a 100644 --- a/plugin/libclang.py +++ b/plugin/libclang.py @@ -549,7 +549,7 @@ def jumpToLocation(filename, line, column, preview): if not preview: vim.current.window.cursor = (line, column - 1) -def gotoDeclaration(preview=True): +def gotoDeclaration(preview=True, type_declaration=False): global debug debug = int(vim.eval("g:clang_debug")) == 1 params = getCompileParams(vim.current.buffer.name) @@ -567,7 +567,10 @@ def gotoDeclaration(preview=True): f = File.from_name(tu, vim.current.buffer.name) loc = SourceLocation.from_position(tu, f, line, col + 1) cursor = Cursor.from_location(tu, loc) - defs = [cursor.get_definition(), cursor.referenced] + if type_declaration: + defs = [cursor.type.get_declaration() if cursor.type else None] + else: + defs = [cursor.get_definition(), cursor.referenced] for d in defs: if d is not None and loc != d.location: From 896ecd6f2390a595ec3412dcbeb2da5ba2405834 Mon Sep 17 00:00:00 2001 From: Mathias Rav Date: Wed, 1 Mar 2017 11:06:13 -0500 Subject: [PATCH 3/3] Add type_declaration argument to s:GotoDeclaration and functions g:ClangFollowReference[Preview] --- plugin/clang_complete.vim | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/plugin/clang_complete.vim b/plugin/clang_complete.vim index a2bd90d4..1b706f2f 100644 --- a/plugin/clang_complete.vim +++ b/plugin/clang_complete.vim @@ -629,9 +629,10 @@ function! s:CompleteColon() return ':' . s:LaunchCompletion() endfunction -function! s:GotoDeclaration(preview) +function! s:GotoDeclaration(preview, type_declaration) try - execute s:py_cmd "gotoDeclaration(vim.eval('a:preview') == '1')" + execute s:py_cmd "gotoDeclaration(vim.eval('a:preview') == '1', " + \."vim.eval('a:type_declaration') == '1')" catch /^Vim\%((\a\+)\)\=:E37/ echoe "The current file is not saved, and 'hidden' is not set." \ "Either save the file or add 'set hidden' in your vimrc." @@ -645,13 +646,23 @@ function! g:ClangUpdateQuickFix() return '' endfunction +function! g:ClangFollowReference() + call s:GotoDeclaration(0, 1) + return '' +endfunction + +function! g:ClangFollowReferencePreview() + call s:GotoDeclaration(1, 1) + return '' +endfunction + function! g:ClangGotoDeclaration() - call s:GotoDeclaration(0) + call s:GotoDeclaration(0, 0) return '' endfunction function! g:ClangGotoDeclarationPreview() - call s:GotoDeclaration(1) + call s:GotoDeclaration(1, 0) return '' endfunction