Skip to content

Commit

Permalink
Resolve object attributes to standard library identifiers.
Browse files Browse the repository at this point in the history
The plug-in now tries to resolve object attributes using a
progressively smaller suffix of the identifier at the cursor.
This enables resolving identifiers like "self.parser.add_option"
to their global variant, e.g. "optparse.OptionParser.add_option".
  • Loading branch information
xolox committed May 31, 2010
1 parent dd6901c commit bf6751d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pyref.vim
@@ -1,6 +1,6 @@
" Vim plug-in
" Maintainer: Peter Odding <peter@peterodding.com>
" Last Change: May 28, 2010
" Last Change: June 1, 2010
" URL: http://peterodding.com/code/vim/pyref
" License: MIT

Expand Down Expand Up @@ -178,6 +178,19 @@ function! s:PyRef()
return
endif

" Split the expression on all dots and search for a progressively smaller
" suffix to resolve object attributes like "self.parser.add_option" to
" global identifiers like "optparse.OptionParser.add_option". This relies
" on the uniqueness of the method names in the standard library.
let parts = split(ident, '\.')
while len(parts) > 1
call remove(parts, 0)
let pattern = join(parts, '\.') . '$'
if s:JumpToEntry(lines, pattern)
return
endif
endwhile

" As a last resort, search all of http://docs.python.org/ using Google.
call s:OpenBrowser('http://google.com/search?btnI&q=inurl:docs.python.org/+' . ident)

Expand Down

0 comments on commit bf6751d

Please sign in to comment.