summaryrefslogtreecommitdiff
path: root/script-beta/core/completion.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-08-17 19:49:33 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-08-17 19:49:33 +0800
commitf91735b40a6829df71547151ee72f42f4a9ed2fc (patch)
tree19e1c476f965e9db148dbdf516878570192bf5f0 /script-beta/core/completion.lua
parente8e5e00ff910bbbd7729d473198eff92e7581e64 (diff)
downloadlua-language-server-f91735b40a6829df71547151ee72f42f4a9ed2fc.zip
优化自动完成的性能
Diffstat (limited to 'script-beta/core/completion.lua')
-rw-r--r--script-beta/core/completion.lua59
1 files changed, 28 insertions, 31 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua
index e4310673..dc05d0a1 100644
--- a/script-beta/core/completion.lua
+++ b/script-beta/core/completion.lua
@@ -167,7 +167,7 @@ end
local function buildFunction(results, source, oop, data)
local snipType = config.config.completion.callSnippet
if snipType == 'Disable' or snipType == 'Both' then
- results[#results+1] = data
+ results[data.label] = data
end
if snipType == 'Both' or snipType == 'Replace' then
local snipData = util.deepCopy(data)
@@ -181,7 +181,7 @@ local function buildFunction(results, source, oop, data)
description = buildDesc(source),
}
end)
- results[#results+1] = snipData
+ results[snipData.label] = snipData
end
end
@@ -229,7 +229,7 @@ local function checkLocal(ast, word, offset, results)
end
end
-local function checkFieldThen(src, used, word, start, parent, oop, results)
+local function checkFieldThen(src, results, word, start, parent, oop, results)
local key = vm.getKeyName(src)
if not key or key:sub(1, 1) ~= 's' then
return
@@ -238,15 +238,12 @@ local function checkFieldThen(src, used, word, start, parent, oop, results)
return
end
local name = key:sub(3)
- if used[name] then
- return
- end
- used[name] = true
if not matchKey(word, name) then
return
end
+ local value = guide.getObjectValue(src) or src
local kind = ckind.Field
- if vm.hasType(src, 'function') then
+ if value.type == 'function' then
if oop then
kind = ckind.Method
else
@@ -262,38 +259,38 @@ local function checkFieldThen(src, used, word, start, parent, oop, results)
}
end),
})
+ end
+ if oop then
+ return
+ end
+ local literal = guide.getLiteral(value)
+ if literal ~= nil then
+ kind = ckind.Enum
else
- if oop then
+ if results[name] then
return
end
- local literal = guide.getLiteral(src)
- if literal ~= nil then
- kind = ckind.Enum
- end
- results[#results+1] = {
- label = name,
- kind = kind,
- id = stack(function ()
- return {
- detail = buildDetail(src),
- description = buildDesc(src),
- }
- end)
- }
end
+ results[name] = {
+ label = name,
+ kind = kind,
+ id = stack(function ()
+ return {
+ detail = buildDetail(src),
+ description = buildDesc(src),
+ }
+ end)
+ }
end
local function checkField(word, start, parent, oop, results)
- local used = {}
- if parent.ref then
- for _, src in ipairs(parent.ref) do
- checkFieldThen(src, used, word, start, parent, oop, results)
- end
- end
+ local fields = {}
vm.eachField(parent, function (src)
- checkFieldThen(src, used, word, start, parent, oop, results)
+ checkFieldThen(src, fields, word, start, parent, oop, fields)
end)
- return used
+ for _, result in pairs(fields) do
+ results[#results+1] = result
+ end
end
local function checkTableField(ast, word, start, results)