start -= 1
endwhile
lspserver.omniCompleteKeyword = keyword
- return start
+ return line->byteidx(start)
else
# Wait for the list of matches from the LSP server
var count: number = 0
return
endif
- var cur_col: number = col('.')
+ var cur_col: number = charcol('.')
var line: string = getline('.')
if cur_col == 0 || line->empty()
# If the character before the cursor is not a keyword character or is not
# one of the LSP completion trigger characters, then do nothing.
if line[cur_col - 2] !~ '\k'
- var trigidx = lspserver.completionTriggerChars->index(line[cur_col - 2])
+ var trigChars = lspserver.completionTriggerChars
+ var trigidx = trigChars->index(line[cur_col - 2])
if trigidx == -1
return
endif
# completion triggered by one of the trigger characters
triggerKind = 2
- triggerChar = lspserver.completionTriggerChars[trigidx]
+ triggerChar = trigChars[trigidx]
endif
# first send all the changes in the current buffer to the LSP server
:bw!
enddef
+# Test for doing omni completion from the first column
+def g:Test_OmniComplete_Multibyte()
+ :silent! edit Xtest.c
+ sleep 200m
+ var lines: list<string> =<< trim END
+ #include <string.h>
+ void Fn(void)
+ {
+ int thisVar = 1;
+ int len = strlen("©©©©©") + thisVar;
+ }
+ END
+ setline(1, lines)
+ g:WaitForServerFileLoad(0)
+ redraw!
+
+ cursor(5, 36)
+ feedkeys("cwthis\<C-X>\<C-O>", 'xt')
+ assert_equal(' int len = strlen("©©©©©") + thisVar;', getline('.'))
+ :bw!
+enddef
+
+# Test for doing omni completion from the first column
+def g:Test_OmniComplete_Struct()
+ :silent! edit Xtest.c
+ sleep 200m
+ var lines: list<string> =<< trim END
+ struct test_ {
+ int foo;
+ int bar;
+ int baz;
+ };
+ void Fn(void)
+ {
+ struct test_ myTest;
+ struct test_ *pTest;
+ myTest.bar = 10;
+ pTest->bar = 20;
+ }
+ END
+ setline(1, lines)
+ g:WaitForServerFileLoad(0)
+ redraw!
+
+ cursor(10, 12)
+ feedkeys("cwb\<C-X>\<C-O>\<C-N>\<C-Y>", 'xt')
+ assert_equal(' myTest.baz = 10;', getline('.'))
+ cursor(11, 12)
+ feedkeys("cw\<C-X>\<C-O>\<C-N>\<C-N>\<C-Y>", 'xt')
+ assert_equal(' pTest->foo = 20;', getline('.'))
+ :bw!
+enddef
+
# TODO:
# 1. Add a test for autocompletion with a single match while ignoring case.
# After the full matched name is typed, the completion popup should still