Permalink
Browse files

Add support for goto-declaration.

  • Loading branch information...
1 parent 7293cd9 commit 07f77e0b60098185a5d6ad54f436d8cc2c35830e @Rip-Rip committed Jan 29, 2013
Showing with 60 additions and 14 deletions.
  1. +23 −13 doc/clang_complete.txt
  2. +7 −0 plugin/clang_complete.vim
  3. +30 −1 plugin/libclang.py
View
@@ -7,11 +7,11 @@
clang_complete plugin *clang_complete*
1. Description |clang_complete-description|
-2. Completion kinds |clang_complete-compl_kinds|
-3. Configuration |clang_complete-configuration|
-4. Options |clang_complete-options|
-5. Known issues |clang_complete-issues|
-6. PCH |clang_complete-pch|
+2. Key bindings |clang_complete-keybindings|
+3. Completion kinds |clang_complete-compl_kinds|
+4. Configuration |clang_complete-configuration|
+5. Options |clang_complete-options|
+6. Known issues |clang_complete-issues|
7. cc_args.py script |clang_complete-cc_args|
8. To do |clang_complete-todo|
9. FAQ |clang_complete-faq|
@@ -29,7 +29,17 @@ unconditionnaly set mapping done by omnicppcomplete. So don't forget to
suppress it before using this plugin.
==============================================================================
-2. Completion kinds *clang_complete-compl_kinds*
+2. Key bindings *clang_complete-keybindings*
+
+Completion is started with CTRL-X CTRL-U |i_CTRL-X_CTRL-U|, or automatically
+depending on the value of |clang_complete-auto|.
+
+You can also jump to the declaration of the symbol under the cursor with
+<CTRL-]>. Jumping back is done with <CTRL-T>. Since clang_complete uses
+|jumplist|, you can navigate through the jumps with <CTRL-O> and <CTRL-I>
+
+==============================================================================
+3. Completion kinds *clang_complete-compl_kinds*
Because libclang provides a lot of information about completion, there are
some additional kinds of completion along with standard ones (see
@@ -43,7 +53,7 @@ some additional kinds of completion along with standard ones (see
'p' - template ('p' from "pattern")
==============================================================================
-3. Configuration *clang_complete-configuration*
+4. Configuration *clang_complete-configuration*
Each project can have a .clang_complete at his root, containing the compiler
options. This is useful if you're using some non-standard include paths or
@@ -73,7 +83,7 @@ Example .clang_complete file: >
-I/usr/include/c++/4.5.3/x86_64-slackware-linux/
<
==============================================================================
-4. Options *clang_complete-options*
+5. Options *clang_complete-options*
*clang_complete-auto_select*
*g:clang_auto_select*
@@ -224,7 +234,7 @@ If clang should complete code patterns, i.e loop constructs etc.
Defaut: 0
==============================================================================
-5. Known issues *clang_complete-issues*
+6. Known issues *clang_complete-issues*
If you get following error message while trying to complete anything: >
E121: Undefined variable: b:should_overload
@@ -235,7 +245,7 @@ Ubuntu users may need to install libclang-dev: >
apt-get install libclang-dev
==============================================================================
-6. cc_args.py script *clang_complete-cc_args*
+7. cc_args.py script *clang_complete-cc_args*
This script, installed at ~/.vim/bin/cc_args.py, could be used to generate or
update the .clang_complete file. It works similar to gccsence's gccrec and
@@ -251,14 +261,14 @@ new options. If you don't want to update an existing configuration file,
delete it before running make.
==============================================================================
-7. To do *clang_complete-todo*
+8. To do *clang_complete-todo*
- Write some unit tests
- Explore "jump to declaration/definition" with libclang FGJ
- Think about supertab (<C-X><C-U> with supertab and clang_auto_select)
==============================================================================
-8. FAQ *clang_complete-faq*
+9. FAQ *clang_complete-faq*
*) clang_complete doesn't work! I always get the message "pattern not found".
@@ -295,7 +305,7 @@ adding the following line to your vimrc:
set completeopt=menu,longest
==============================================================================
-9. License *clang_complete-license*
+10. License *clang_complete-license*
Copyright (c) 2010, 2011, 2012, 2013 Xavier Deguillard, Tobias Grosser
All rights reserved.
@@ -139,6 +139,8 @@ function! s:ClangCompleteInit()
inoremap <expr> <buffer> > <SID>CompleteArrow()
inoremap <expr> <buffer> : <SID>CompleteColon()
inoremap <expr> <buffer> <CR> <SID>HandlePossibleSelectionEnter()
+ nnoremap <buffer> <silent> <C-]> :call <SID>GotoDeclaration()<CR><Esc>
+ nnoremap <buffer> <silent> <C-T> <C-O>
@taketwo

taketwo Mar 21, 2013

Contributor

Is there any particular reason to have this proxy mapping? Why not just using Ctrl+O?
I have Ctrl-T already mapped to something else, so the plugin breaks my mapping. Is it possible to get rid of this remapping or at least make it optional?

@Rip-Rip

Rip-Rip Mar 23, 2013

Owner

The only reason is to be coherent with ctags implementation that uses Ctrl+] and Ctrl+T.

@taketwo

taketwo Mar 23, 2013

Contributor

Thanks for the answer.
What do you think about making the remapping keys user-settable? Something like introducing g:clang_jumpto_declaration_key and g:clang_jumpto_back_key options with the defaults set to <C-]> and <C-T>. If you are not opposed to this I could go ahead and implement it.

@Rip-Rip

Rip-Rip Mar 23, 2013

Owner

Go ahead :). It was already proposed on another issue, but didn't have the time to look at it.

@taketwo

taketwo Mar 23, 2013

Contributor

Done, sent a pull request.
I did not find the issue you referred to, so did not mention it in the commit message.

if g:clang_snippets == 1
call g:ClangSetSnippetEngine(g:clang_snippets_engine)
@@ -454,6 +456,11 @@ function! s:CompleteColon()
return ':' . s:LaunchCompletion()
endfunction
+function! s:GotoDeclaration()
+ python gotoDeclaration()
+ return ''
+endfunction
+
" May be used in a mapping to update the quickfix window.
function! g:ClangUpdateQuickFix()
call s:DoPeriodicQuickFix()
View
@@ -159,7 +159,8 @@ def getCurrentTranslationUnit(args, currentFile, fileName, timer,
timer.registerEvent("Reparsing")
return tu
- flags = TranslationUnit.PARSE_PRECOMPILED_PREAMBLE
+ flags = TranslationUnit.PARSE_PRECOMPILED_PREAMBLE | \
+ TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD
tu = index.parse(fileName, args, [currentFile], flags)
timer.registerEvent("First parse")
@@ -499,6 +500,34 @@ def getAbbr(strings):
return chunks.spelling
return ""
+def jumpToLocation(filename, line, column):
+ if filename != vim.current.buffer.name:
+ vim.command("edit! %s" % filename)
+ else:
+ vim.command("normal m'")
+ vim.current.window.cursor = (line, column - 1)
+
+def gotoDeclaration():
+ global debug
+ debug = int(vim.eval("g:clang_debug")) == 1
+ params = getCompileParams(vim.current.buffer.name)
+ line, col = vim.current.window.cursor
+ timer = CodeCompleteTimer(debug, vim.current.buffer.name, line, col, params)
+
+ with workingDir(params['cwd']):
+ with libclangLock:
+ tu = getCurrentTranslationUnit(params['args'], getCurrentFile(),
+ vim.current.buffer.name, timer,
+ update = 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)
+ if cursor.referenced is not None and loc != cursor.referenced.location:
+ loc = cursor.referenced.location
+ jumpToLocation(loc.file.name, loc.line, loc.column)
+
+ timer.finish()
+
# Manually extracted from Index.h
# Doing it by hand is long, error prone and horrible, we must find a way
# to do that automatically.

0 comments on commit 07f77e0

Please sign in to comment.