diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/completion.lua | 18 | ||||
-rw-r--r-- | server/src/utility.lua | 15 | ||||
-rw-r--r-- | server/test/completion/init.lua | 21 | ||||
-rw-r--r-- | server/test/crossfile/completion.lua | 8 |
4 files changed, 49 insertions, 13 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index 23bd224c..cf9a1a90 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -222,6 +222,16 @@ local function searchFields(vm, source, word, callback) if source:get 'object' and v:getType() ~= 'function' then goto CONTINUE end + if k == word then + local ok = v:eachInfo(function (_, src) + if src ~= source then + return true + end + end) + if not ok then + goto CONTINUE + end + end if matchKey(word, k) then map[k] = v end @@ -509,7 +519,7 @@ local function searchSpecial(vm, source, word, callback, pos) end end -local function makeList(source, word) +local function makeList(source, pos, word) local list = {} local mark = {} return function (name, src, kind, data) @@ -517,7 +527,9 @@ local function makeList(source, word) return end if word == name then - return + if src and src.start <= pos and src.finish >= pos then + return + end end if mark[name] then return @@ -547,7 +559,7 @@ return function (vm, pos, word, oldText) return nil end end - local callback, list = makeList(source, word) + local callback, list = makeList(source, pos, word) searchSpecial(vm, source, word, callback, pos) searchCallArg(vm, source, word, callback, pos) searchSource(vm, source, word, callback) diff --git a/server/src/utility.lua b/server/src/utility.lua index 3f0df110..a4072510 100644 --- a/server/src/utility.lua +++ b/server/src/utility.lua @@ -10,6 +10,8 @@ local next = next local rawset = rawset local move = table.move local setmetatable = setmetatable +local tableSort = table.sort +local mathType = math.type local TAB = setmetatable({}, { __index = function (self, n) self[n] = string_rep('\t', n) @@ -41,16 +43,19 @@ function table.dump(tbl) else KEY[key] = key end - elseif math_type(key) == 'integer' then - KEY[key] = ('[%d]'):format(key) + elseif mathType(key) == 'integer' then + KEY[key] = ('[%03d]'):format(key) else KEY[key] = ('<%s>'):format(key) end keys[#keys+1] = key end - table_sort(keys, function (a, b) - return KEY[a] < KEY[b] - end) + local mt = getmetatable(tbl) + if not mt or not mt.__pairs then + tableSort(keys, function (a, b) + return KEY[a] < KEY[b] + end) + end for _, key in ipairs(keys) do local value = tbl[key] local tp = type(value) diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index 5ae598c2..a512ee5e 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -138,7 +138,11 @@ zabcde@ { label = 'zabcdefg', kind = CompletionItemKind.Variable, - } + }, + { + label = 'zabcde', + kind = CompletionItemKind.Variable, + }, } TEST [[ @@ -389,7 +393,7 @@ print(fff) } TEST [[ -local function f(f@) +local function f(ff@) print(fff) end ]] @@ -631,7 +635,12 @@ TEST [[ local xxxx xxxx@ ]] -(nil) +{ + { + label = 'xxxx', + kind = CompletionItemKind.Variable, + }, +} TEST [[ local xxxx @@ -640,9 +649,13 @@ xxxx@ ]] { { + label = 'xxxx', + kind = CompletionItemKind.Variable, + }, + { label = 'XXXX', kind = CompletionItemKind.Variable, - } + }, } TEST [[ diff --git a/server/test/crossfile/completion.lua b/server/test/crossfile/completion.lua index fab2e81e..5cce68ef 100644 --- a/server/test/crossfile/completion.lua +++ b/server/test/crossfile/completion.lua @@ -202,6 +202,12 @@ TEST { }, completion = { { + label = 'abc', + kind = CompletionItemKind.Reference, + documentation = 'abc.lua', + textEdit = EXISTS, + }, + { label = 'abc.init', kind = CompletionItemKind.Reference, documentation = 'abc/init.lua', @@ -234,7 +240,7 @@ TEST { } } -TEST { +TEST { { path = 'abc.lua', content = '', |