diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-29 09:56:16 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-29 09:56:16 +0800 |
commit | 7ab564aad9fe823ff90614b106853f05be001fe4 (patch) | |
tree | e8ca8ef3d30e974834ef20061fa4fc7f29a97335 /server | |
parent | 1dee813e59166317d993a6010c66e267e69a82c2 (diff) | |
download | lua-language-server-7ab564aad9fe823ff90614b106853f05be001fe4.zip |
require的自动完成提示文件名
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/completion.lua | 5 | ||||
-rw-r--r-- | server/src/workspace.lua | 3 | ||||
-rw-r--r-- | server/test/crossfile/completion.lua | 10 |
3 files changed, 15 insertions, 3 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index 16b2ad4c..adbac085 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -341,12 +341,13 @@ local function searchInRequire(vm, select, source, callback) if source.type ~= 'string' then return end - local list = vm.lsp.workspace:matchPath(vm.uri, source[1]) + local list, map = vm.lsp.workspace:matchPath(vm.uri, source[1]) if not list then return end for _, str in ipairs(list) do callback(str, nil, CompletionItemKind.File, { + documentation = map[str], textEdit = { -- TODO 坑爹自动完成的字符串里面不能包含符号 -- 这里长字符串会出问题,不过暂时先这样吧 @@ -361,7 +362,7 @@ end local function searchCallArg(vm, source, word, callback, pos) local results = {} for _, src in ipairs(vm.sources) do - if src.type == 'call' + if src.type == 'call' and src.start <= pos and src.finish >= pos then diff --git a/server/src/workspace.lua b/server/src/workspace.lua index 74a674ed..fe1289f4 100644 --- a/server/src/workspace.lua +++ b/server/src/workspace.lua @@ -239,6 +239,7 @@ function mt:matchPath(baseUri, input) local list = {} for str in pairs(map) do list[#list+1] = str + map[str] = map[str]:sub(rootLen + 2) end if #list == 0 then return nil @@ -252,7 +253,7 @@ function mt:matchPath(baseUri, input) return sa > sb end end) - return list + return list, map end function mt:searchPath(baseUri, str) diff --git a/server/test/crossfile/completion.lua b/server/test/crossfile/completion.lua index eaa5ef00..b5c3bc1b 100644 --- a/server/test/crossfile/completion.lua +++ b/server/test/crossfile/completion.lua @@ -148,16 +148,19 @@ TEST { { label = 'abc', kind = CompletionItemKind.File, + documentation = 'abc.lua', textEdit = EXISTS, }, { label = 'abc.aaa', kind = CompletionItemKind.File, + documentation = 'abc/aaa.lua', textEdit = EXISTS, }, { label = 'abcde', kind = CompletionItemKind.File, + documentation = 'xxx/abcde.lua', textEdit = EXISTS, }, } @@ -177,6 +180,7 @@ TEST { { label = 'abc', kind = CompletionItemKind.File, + documentation = 'abc.lua', textEdit = EXISTS, }, } @@ -200,6 +204,7 @@ TEST { { label = 'abc.init', kind = CompletionItemKind.File, + documentation = 'abc/init.lua', textEdit = EXISTS, }, } @@ -223,6 +228,7 @@ TEST { { label = 'abc.init', kind = CompletionItemKind.File, + documentation = 'abc/init.lua', textEdit = EXISTS, }, } @@ -246,6 +252,7 @@ TEST { { label = 'abc.init', kind = CompletionItemKind.File, + documentation = 'abc/init.lua', textEdit = EXISTS, }, } @@ -269,6 +276,7 @@ TEST { { label = 'core.core', kind = CompletionItemKind.File, + documentation = 'core/core.lua', textEdit = EXISTS, }, } @@ -292,11 +300,13 @@ TEST { { label = 'x111', kind = CompletionItemKind.File, + documentation = 'abc/x111.lua', textEdit = EXISTS, }, { label = 'x000', kind = CompletionItemKind.File, + documentation = 'x000.lua', textEdit = EXISTS, }, } |