From 300a9411341e90ba03830e82862a0d3ecb39b536 Mon Sep 17 00:00:00 2001 From: miyakogi Date: Sat, 24 Jan 2015 16:56:21 +0900 Subject: [PATCH 1/4] Improve completion --- autoload/nim.vim | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/autoload/nim.vim b/autoload/nim.vim index 59fefce..8c027c0 100644 --- a/autoload/nim.vim +++ b/autoload/nim.vim @@ -131,21 +131,29 @@ fun! NimComplete(findstart, base) if b:nim_caas_enabled == 0 return -1 endif + let curcol = col('.') if a:findstart if synIDattr(synIDtrans(synID(line("."),col("."),1)), "name") == 'Comment' return -1 endif - return col('.') + + let curline = getline(line('.')) + return curcol - match(reverse(split(curline, '\zs')), '[^0-9a-zA-Z_]') - 1 else let result = [] let sugOut = NimExec("--suggest") + let baselen = len(a:base) + for line in split(sugOut, '\n') let lineData = split(line, '\t') if len(lineData) > 0 && lineData[0] == "sug" - let kind = get(g:nim_symbol_types, lineData[1], '') - let c = { 'word': lineData[2], 'kind': kind, 'menu': lineData[3], 'dup': 1 } - call add(result, c) + let word = lineData[2] + if a:base ==# word[: baselen - 1] + let kind = get(g:nim_symbol_types, lineData[1], '') + let c = { 'word': word, 'kind': kind, 'menu': lineData[3], 'dup': 1 } + call add(result, c) + endif endif endfor return result From e78c05b2d26b1738a893d87b7c745f55682d9170 Mon Sep 17 00:00:00 2001 From: miyakogi Date: Sat, 24 Jan 2015 17:15:25 +0900 Subject: [PATCH 2/4] Use better regexp --- autoload/nim.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/nim.vim b/autoload/nim.vim index 8c027c0..7744805 100644 --- a/autoload/nim.vim +++ b/autoload/nim.vim @@ -139,7 +139,7 @@ fun! NimComplete(findstart, base) endif let curline = getline(line('.')) - return curcol - match(reverse(split(curline, '\zs')), '[^0-9a-zA-Z_]') - 1 + return curcol - match(reverse(split(curline, '\zs')), '\W') - 1 else let result = [] let sugOut = NimExec("--suggest") From 5223405928f9b556478cd96fc39ad516d6b16066 Mon Sep 17 00:00:00 2001 From: miyakogi Date: Sat, 24 Jan 2015 18:01:42 +0900 Subject: [PATCH 3/4] Return words also when cursor is placed just after dot. --- autoload/nim.vim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autoload/nim.vim b/autoload/nim.vim index 7744805..e6de5de 100644 --- a/autoload/nim.vim +++ b/autoload/nim.vim @@ -149,7 +149,7 @@ fun! NimComplete(findstart, base) let lineData = split(line, '\t') if len(lineData) > 0 && lineData[0] == "sug" let word = lineData[2] - if a:base ==# word[: baselen - 1] + if a:base ==# word[: baselen - 1] || baselen == 0 let kind = get(g:nim_symbol_types, lineData[1], '') let c = { 'word': word, 'kind': kind, 'menu': lineData[3], 'dup': 1 } call add(result, c) From 992e242883eb73f0e6254bf35f263836fe9e46d2 Mon Sep 17 00:00:00 2001 From: miyakogi Date: Sat, 31 Jan 2015 14:54:28 +0900 Subject: [PATCH 4/4] Fixed style (minor update) --- autoload/nim.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/autoload/nim.vim b/autoload/nim.vim index e6de5de..78d0a8c 100644 --- a/autoload/nim.vim +++ b/autoload/nim.vim @@ -149,9 +149,9 @@ fun! NimComplete(findstart, base) let lineData = split(line, '\t') if len(lineData) > 0 && lineData[0] == "sug" let word = lineData[2] - if a:base ==# word[: baselen - 1] || baselen == 0 + if a:base ==# word[: baselen - 1] || baselen == 0 let kind = get(g:nim_symbol_types, lineData[1], '') - let c = { 'word': word, 'kind': kind, 'menu': lineData[3], 'dup': 1 } + let c = {'word': word, 'kind': kind, 'menu': lineData[3], 'dup': 1} call add(result, c) endif endif