diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/completion.lua | 36 | ||||
-rw-r--r-- | server/test/crossfile/completion.lua | 18 |
2 files changed, 44 insertions, 10 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index 3c6d9057..ecb7a90c 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -518,6 +518,29 @@ local function searchSource(vm, source, word, callback, pos) end end +local function buildTextEdit(start, finish, str) + return { + label = str, + textEdit = { + start = start + 1, + finish = finish - 1, + newText = ('%q'):format(str), + }, + additionalTextEdits = { + { + start = start, + finish = start, + newText = '', + }, + { + start = finish, + finish = finish, + newText = '', + }, + } + } +end + local function searchInRequire(vm, select, source, callback) if select ~= 1 then return @@ -533,16 +556,9 @@ local function searchInRequire(vm, select, source, callback) return end for _, str in ipairs(list) do - callback(str, nil, CompletionItemKind.Reference, { - documentation = map[str], - textEdit = { - -- TODO 坑爹自动完成的字符串里面不能包含符号 - -- 这里长字符串会出问题,不过暂时先这样吧 - start = source.start + 1, - finish = source.finish - 1, - newText = str, - } - }) + local data = buildTextEdit(source.start, source.finish, str) + data.documentation = map[str] + callback(str, nil, CompletionItemKind.Reference, data) end end diff --git a/server/test/crossfile/completion.lua b/server/test/crossfile/completion.lua index 8d1ff48d..2b38f42a 100644 --- a/server/test/crossfile/completion.lua +++ b/server/test/crossfile/completion.lua @@ -126,18 +126,21 @@ TEST { kind = CompletionItemKind.Reference, documentation = 'abc.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, { label = 'abc.aaa', kind = CompletionItemKind.Reference, documentation = 'abc/aaa.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, { label = 'abcde', kind = CompletionItemKind.Reference, documentation = 'xxx/abcde.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, } } @@ -158,6 +161,7 @@ TEST { kind = CompletionItemKind.Reference, documentation = 'abc.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, } } @@ -182,12 +186,14 @@ TEST { kind = CompletionItemKind.Reference, documentation = 'ABCD.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, { label = 'abc', kind = CompletionItemKind.Reference, documentation = 'abc.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, } } @@ -214,6 +220,7 @@ TEST { kind = CompletionItemKind.Reference, documentation = 'abc.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, } } @@ -240,12 +247,14 @@ TEST { kind = CompletionItemKind.Reference, documentation = 'abc.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, { label = 'abc.init', kind = CompletionItemKind.Reference, documentation = 'abc/init.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, } } @@ -270,18 +279,21 @@ TEST { kind = CompletionItemKind.Reference, documentation = 'abc/init.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, { label = 'abc.bbc', kind = CompletionItemKind.Reference, documentation = 'abc/bbc.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, { label = 'abc.init', kind = CompletionItemKind.Reference, documentation = 'abc/init.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, } } @@ -306,6 +318,7 @@ TEST { kind = CompletionItemKind.Reference, documentation = 'abc/init.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, } } @@ -330,6 +343,7 @@ TEST { kind = CompletionItemKind.Reference, documentation = 'abc/init.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, } } @@ -354,6 +368,7 @@ TEST { kind = CompletionItemKind.Reference, documentation = 'core/core.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, } } @@ -378,12 +393,14 @@ TEST { kind = CompletionItemKind.Reference, documentation = 'x000.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, { label = 'x111', kind = CompletionItemKind.Reference, documentation = 'abc/x111.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, } } @@ -532,6 +549,7 @@ TEST { kind = CompletionItemKind.Reference, documentation = 'xxx.lua', textEdit = EXISTS, + additionalTextEdits = EXISTS, }, } } |