From e5967fca2bdcd7ee009cce99bf6ab5e5a9b533d5 Mon Sep 17 00:00:00 2001 From: Yegappan Lakshmanan Date: Wed, 26 Jan 2022 20:35:36 -0800 Subject: [PATCH] Update the loop that waits for matches for omni-completion --- autoload/lsp.vim | 7 +++++-- autoload/symbol.vim | 6 +++--- test/run_tests.sh | 4 +++- test/unit_tests.vim | 26 ++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/autoload/lsp.vim b/autoload/lsp.vim index 772da60..4580782 100644 --- a/autoload/lsp.vim +++ b/autoload/lsp.vim @@ -622,9 +622,12 @@ def lsp#omniFunc(findstart: number, base: string): any endwhile return start else + # Wait for the list of matches from the LSP server var count: number = 0 - while !complete_check() && lspserver.completePending - && count < 1000 + while lspserver.completePending && count < 1000 + if complete_check() + return v:none + endif sleep 2m count += 1 endwhile diff --git a/autoload/symbol.vim b/autoload/symbol.vim index 2bdb062..e46887d 100644 --- a/autoload/symbol.vim +++ b/autoload/symbol.vim @@ -261,7 +261,6 @@ export def GotoSymbol(lspserver: dict, location: dict, type: string) var wid = fname->bufwinid() if wid != -1 wid->win_gotoid() - normal! m` else var bnr: number = fname->bufnr() if bnr != -1 @@ -279,9 +278,10 @@ export def GotoSymbol(lspserver: dict, location: dict, type: string) exe 'edit ' .. fname endif endif - setpos("'`", getcurpos()) endif - # Set the previous cursor location mark + # Set the previous cursor location mark. Instead of using setpos(), m' is + # used so that the current location is added to the jump list. + normal m' setcursorcharpos(location.range.start.line + 1, location.range.start.character + 1) endif diff --git a/test/run_tests.sh b/test/run_tests.sh index 39d5cec..0403959 100755 --- a/test/run_tests.sh +++ b/test/run_tests.sh @@ -2,7 +2,9 @@ # Script to run the unit-tests for the LSP Vim plugin -VIMPRG=${VIMPRG:=/usr/bin/vim} +#VIMPRG=${VIMPRG:=/usr/bin/vim} +export VIMRUNTIME=/home/yega/Documents/vim/opfunc/vim/runtime +VIMPRG=/home/yega/Documents/vim/opfunc/vim/src/vim VIM_CMD="$VIMPRG -u NONE -U NONE -i NONE --noplugin -N --not-a-term" $VIM_CMD -S unit_tests.vim diff --git a/test/unit_tests.vim b/test/unit_tests.vim index 0b3057d..a7d6e1d 100644 --- a/test/unit_tests.vim +++ b/test/unit_tests.vim @@ -630,6 +630,32 @@ def Test_LspShowSignature() :%bw! enddef +# Test for LSP omni completion +def Test_omnicomplete() + lsp#setOptions({'autoComplete': v:false}) + silent! edit Xtest.c + var lines: list =<< trim END + void MyFunc1(void) + { + } + + void MyFunc2(void) + { + } + + void f1(void) + { + } + END + setline(1, lines) + :sleep 1 + cursor(10, 1) + feedkeys("oMy\\\();", "xt") + assert_equal("\tMyFunc2();", getline('.')) + :%bw! + lsp#setOptions({'autoComplete': v:true}) +enddef + def LspRunTests() :set nomore :set debug=beep -- 2.48.1