mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
started with the vim interface
This commit is contained in:
16
functions.py
Normal file
16
functions.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import pyfuzzyparser
|
||||||
|
|
||||||
|
def complete(source, row, colum, file_callback=None):
|
||||||
|
"""
|
||||||
|
An auto completer for python files.
|
||||||
|
|
||||||
|
:param source: The source code of the current file
|
||||||
|
:type source: string
|
||||||
|
:param row: The row to complete in.
|
||||||
|
:type row: int
|
||||||
|
:param col: The column to complete in.
|
||||||
|
:type col: int
|
||||||
|
:return: list
|
||||||
|
:rtype: list
|
||||||
|
"""
|
||||||
|
return []
|
||||||
63
py_functions.vim
Normal file
63
py_functions.vim
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
"py_fuzzycomplete.vim - Omni Completion for python in vim
|
||||||
|
" Maintainer: David Halter <davidhalter88@gmail.com>
|
||||||
|
" Version: 0.1
|
||||||
|
"
|
||||||
|
" This part of the software is just the vim interface. The main source code
|
||||||
|
" lies in the python files around it.
|
||||||
|
|
||||||
|
if !has('python')
|
||||||
|
echo "Error: Required vim compiled with +python"
|
||||||
|
finish
|
||||||
|
endif
|
||||||
|
|
||||||
|
function! pythoncomplete#Complete(findstart, base)
|
||||||
|
"findstart = 1 when we need to get the text length
|
||||||
|
" TODO check wheter this is really needed
|
||||||
|
if a:findstart == 1
|
||||||
|
let line = getline('.')
|
||||||
|
let idx = col('.')
|
||||||
|
while idx > 0
|
||||||
|
let idx -= 1
|
||||||
|
let c = line[idx]
|
||||||
|
if c =~ '\w'
|
||||||
|
continue
|
||||||
|
elseif ! c =~ '\.'
|
||||||
|
let idx = -1
|
||||||
|
break
|
||||||
|
else
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endwhile
|
||||||
|
|
||||||
|
return idx
|
||||||
|
"findstart = 0 when we need to return the list of completions
|
||||||
|
else
|
||||||
|
execute "python vimcomplete()"
|
||||||
|
return g:pythoncomplete_completions
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:DefPython()
|
||||||
|
python << PYTHONEOF
|
||||||
|
import functions
|
||||||
|
|
||||||
|
def vimcomplete():
|
||||||
|
(row, column) = vim.current.window.cursor
|
||||||
|
code = '\n'.join(vim.current.buffer)
|
||||||
|
all = functions.complete(code, row, column)
|
||||||
|
|
||||||
|
dictstr = '['
|
||||||
|
# have to do this for double quoting
|
||||||
|
for cmpl in all:
|
||||||
|
dictstr += '{'
|
||||||
|
for x in cmpl: dictstr += '"%s":"%s",' % (x,cmpl[x])
|
||||||
|
dictstr += '"icase":0},'
|
||||||
|
if dictstr[-1] == ',': dictstr = dictstr[:-1]
|
||||||
|
dictstr += ']'
|
||||||
|
vim.command("silent let g:pythoncomplete_completions = %s" % dictstr)
|
||||||
|
|
||||||
|
PYTHONEOF
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
call s:DefPython()
|
||||||
|
" vim: set et ts=4:
|
||||||
Reference in New Issue
Block a user