diff options
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/completion.lua | 30 | ||||
-rw-r--r-- | server/test/completion/init.lua | 27 |
2 files changed, 54 insertions, 3 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index b2688c68..9e7b72ab 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -31,7 +31,7 @@ local CompletionItemKind = { local function matchKey(me, other) if me == other then - return false + return true end if me == '' then return true @@ -425,16 +425,18 @@ local function makeList(list, source) end mark[key] = true data = data or {} - list[#list+1] = data if var == key then data.label = var data.kind = defualt - else + elseif var.source ~= source then data.label = var.key data.kind = getKind(var, defualt) data.detail = data.detail or getDetail(var) data.documentation = data.documentation or getDocument(var, source) + else + return end + list[#list+1] = data end return callback end @@ -492,6 +494,27 @@ local function searchSpecial(vm, pos, callback) end end +local function clearList(list, source) + local key = source[1] + -- 如果只有一个结果且是自己,则不显示 + if #list == 1 then + if list[1].label == key then + list[1] = nil + end + return + end + -- 如果有多个结果,则将完全符合的放到最前面 + if #list > 1 then + for i, v in ipairs(list) do + if v.label == key then + table.remove(list, i) + table.insert(list, 1, v) + return + end + end + end +end + return function (vm, pos) local list = {} local callback = makeList(list) @@ -509,6 +532,7 @@ return function (vm, pos) if result then callback = makeList(list, source) searchInResult(result, source, vm, pos, callback) + clearList(list, source) end end if #list == 0 then diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index e26000b8..f4b459a0 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -94,6 +94,10 @@ zabcde@ ]] { { + label = 'zabcde', + kind = CompletionItemKind.Variable, + }, + { label = 'zabcdefg', kind = CompletionItemKind.Variable, } @@ -478,3 +482,26 @@ local t = { t @. ]] (nil) + +TEST [[ +local xxxx +xxxx@ +]] +(nil) + +TEST [[ +local xxxx +local XXXX +xxxx@ +]] + +{ + { + label = 'xxxx', + kind = CompletionItemKind.Variable, + }, + { + label = 'XXXX', + kind = CompletionItemKind.Variable, + } +} |