Fix filtering of nimsuggest results

This commit is contained in:
baabelfish 2016-02-09 11:51:57 +02:00
commit 0a4fa1eb78
4 changed files with 25 additions and 14 deletions

View file

@ -28,12 +28,10 @@ function! omni#nimsuggest(file, l, c)
let query = "sug " . a:file . ";" . tempfile . ":" . a:l . ":" . a:c
let jobcmdstr = g:nvim_nim_exec_nimsuggest . " --v2 --stdin " . a:file
let fullcmd = 'echo -e ' . shellescape(query, 1) . '|' . jobcmdstr
let completions_raw = split(system(fullcmd), "\n")[4:-2]
let completions_raw = util#FilterCompletions(split(system(fullcmd), "\n"))
for line in completions_raw
if len(split(line, " ")) > 7
call add(completions, omni#item(util#ParseV2(line)))
endif
call add(completions, omni#item(util#ParseV2(line)))
endfor
return completions

View file

@ -34,13 +34,7 @@ function! s:NimSuggest.on_stderr(job, chunk)
endfunction
function! s:NimSuggest.on_exit()
let temparr = []
for line in self.lines
if len(split(line, " ")) > 6
call add(temparr, line)
endif
endfor
let self.lines = temparr
let self.lines = util#FilterCompletions(self.lines)
if len(self.lines) > 0
call self.handler.run(self)
@ -63,8 +57,10 @@ function! suggest#NewKnown(command, sync, useV2, file, line, col, handler)
if !result.isAsync
let jobcmdstr = g:nvim_nim_exec_nimsuggest . " " . (a:useV2 ? '--v2' : '') . " " . '--stdin' . " " . result.file
let fullcmd = 'echo -e ' . shellescape(query, 1) . '|' . jobcmdstr
let result.lines = split(system(fullcmd), "\n")[4:-2]
call a:handler.run(result)
let result.lines = util#FilterCompletions(split(system(fullcmd), "\n"))
if len(result.lines) > 0
call a:handler.run(result)
endif
else
call util#StartQuery()
let result.job_server = jobstart([g:nvim_nim_exec_nimsuggest, '--port:5999', '--address:localhost', (a:useV2 ? '--v2' : ''), result.file], s:NimSuggestServer)

View file

@ -150,6 +150,23 @@ function! util#ParseV2(line)
endfunction
function! util#FilterCompletionLine(line)
let result = a:line =~ "^\\(def\\|sug\\|use\\|con\\)\\t"
return result
endfunction
function! util#FilterCompletions(lines)
let result = []
for line in a:lines
if util#FilterCompletionLine(line)
call add(result, line)
endif
endfor
return result
endfunction
let s:nesting_chars = ['(', '[', '{']
let s:unnesting_chars = [')', ']', '}']
let s:strip_regex = '\v^\s*(.{-})\s*$'

View file

@ -9,7 +9,7 @@ let b:current_syntax = "nim"
" Keywords
syntax keyword nimKeyword let const var static
syntax keyword nimKeyword let const var static async await
syntax keyword nimKeyword addr asm atomic bind cast defer discard
syntax keyword nimKeyword do expr stmt end generic mixin iterator
syntax keyword nimKeyword typedesc openarray out ptr ref return using