Skip to content

Commit

Permalink
Improve omni completion: support for keywords, less clutter
Browse files Browse the repository at this point in the history
The description on the right hand side of the completion pop-up window
is now only shown when it has some useful information to convey. This
makes it easier to visually parse the pop-up window.
  • Loading branch information
xolox committed Jun 14, 2011
1 parent 9e42b06 commit bfd5701
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
3 changes: 2 additions & 1 deletion autoload/xolox/lua.vim
Expand Up @@ -285,7 +285,7 @@ endfunction
function! s:addsignatures(entries) function! s:addsignatures(entries)
for entry in a:entries for entry in a:entries
let signature = xolox#lua#getsignature(entry.word) let signature = xolox#lua#getsignature(entry.word)
if !empty(signature) if !empty(signature) && signature != entry.word
let entry.menu = signature let entry.menu = signature
endif endif
endfor endfor
Expand Down Expand Up @@ -386,6 +386,7 @@ function! xolox#lua#getomnivariables(modules) " {{{1
let starttime = xolox#misc#timer#start() let starttime = xolox#misc#timer#start()
let output = xolox#lua#dofile(s:omnicomplete_script, a:modules) let output = xolox#lua#dofile(s:omnicomplete_script, a:modules)
let variables = eval('[' . substitute(output, '\_s\+', ',', 'g') . ']') let variables = eval('[' . substitute(output, '\_s\+', ',', 'g') . ']')
call sort(variables, 1)
let msg = "%s: Collected %i variables for omni completion in %s" let msg = "%s: Collected %i variables for omni completion in %s"
call xolox#misc#timer#stop(msg, s:script, len(variables), starttime) call xolox#misc#timer#stop(msg, s:script, len(variables), starttime)
return variables return variables
Expand Down
2 changes: 1 addition & 1 deletion ftplugin/lua.vim
Expand Up @@ -3,7 +3,7 @@
" Author: Peter Odding <peter@peterodding.com> " Author: Peter Odding <peter@peterodding.com>
" Last Change: June 14, 2011 " Last Change: June 14, 2011
" URL: http://peterodding.com/code/vim/lua-ftplugin " URL: http://peterodding.com/code/vim/lua-ftplugin
" Version: 0.6.5 " Version: 0.6.6


" Support for automatic update using the GLVS plug-in. " Support for automatic update using the GLVS plug-in.
" GetLatestVimScripts: 3625 1 :AutoInstall: lua.zip " GetLatestVimScripts: 3625 1 :AutoInstall: lua.zip
Expand Down
23 changes: 16 additions & 7 deletions misc/lua-ftplugin/omnicomplete.lua
Expand Up @@ -25,29 +25,33 @@ local function isident(s)
return type(s) == 'string' and s:find('^[A-Za-z_][A-Za-z_0-9]*$') and not keywords[s] return type(s) == 'string' and s:find('^[A-Za-z_][A-Za-z_0-9]*$') and not keywords[s]
end end


local function addmatch(output, word, kind, desc) local function addmatch(word, kind, desc)
print(string.format("{'word':'%s','kind':'%s','menu':'%s'}", word, kind, desc)) if not desc then
print(string.format("{'word':'%s','kind':'%s'}", word, kind))
else
print(string.format("{'word':'%s','kind':'%s','menu':'%s'}", word, kind, desc))
end
end end


local function dump(table, path, cache, output) local function dump(table, path, cache)
local printed = false local printed = false
for key, value in pairs(table) do for key, value in pairs(table) do
if isident(key) then if isident(key) then
local path = path and (path .. '.' .. key) or key local path = path and (path .. '.' .. key) or key
local vtype = type(value) local vtype = type(value)
if vtype == 'function' then if vtype == 'function' then
printed = true printed = true
addmatch(output, path, 'f', path .. '()') addmatch(path, 'f', path .. '()')
elseif vtype ~= 'table' then elseif vtype ~= 'table' then
printed = true printed = true
addmatch(output, path, 'v', path) addmatch(path, 'v', nil)
else else
if vtype == 'table' and not cache[value] then if vtype == 'table' and not cache[value] then
cache[value] = true cache[value] = true
if dump(value, path, cache, output) then if dump(value, path, cache) then
printed = true printed = true
else else
addmatch(output, path, 'm', path .. '[]') addmatch(path, 'm', path .. '[]')
end end
end end
end end
Expand All @@ -56,6 +60,11 @@ local function dump(table, path, cache, output)
return printed return printed
end end


-- Add keywords to completion candidates.
for kw, _ in pairs(keywords) do
addmatch(kw, 'k', nil)
end

-- Load installed modules. -- Load installed modules.
-- XXX What if module loading has side effects? It shouldn't, but still... -- XXX What if module loading has side effects? It shouldn't, but still...
for _, modulename in ipairs(arg) do for _, modulename in ipairs(arg) do
Expand Down

0 comments on commit bfd5701

Please sign in to comment.