diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-05-30 17:36:16 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-05-30 17:36:16 +0800 |
commit | ab7a1a12a106bdaf980ec8170295092b2cee8006 (patch) | |
tree | a21fa5328d1e73fe1018295ee3f71a111183ebae /script-beta/core | |
parent | eca92d19c165c697d50ec83fbce5591a60c2124a (diff) | |
download | lua-language-server-ab7a1a12a106bdaf980ec8170295092b2cee8006.zip |
更新自动完成
Diffstat (limited to 'script-beta/core')
-rw-r--r-- | script-beta/core/completion.lua | 113 |
1 files changed, 61 insertions, 52 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua index 90f5fbb2..f1bc5a25 100644 --- a/script-beta/core/completion.lua +++ b/script-beta/core/completion.lua @@ -218,62 +218,71 @@ local function checkLocal(ast, word, offset, results) end end -local function checkField(word, start, parent, oop, results) - local used = {} - vm.eachField(parent, function (src) - local key = vm.getKeyName(src) - if not key or key:sub(1, 1) ~= 's' then - return - end - if isSameSource(src, start) then - return - end - local name = key:sub(3) - if used[name] then +local function checkFieldThen(src, used, word, start, parent, oop, results) + local key = vm.getKeyName(src) + if not key or key:sub(1, 1) ~= 's' then + return + end + if isSameSource(src, start) then + return + end + local name = key:sub(3) + if used[name] then + return + end + if not matchKey(word, name) then + used[name] = true + return + end + local kind = ckind.Field + if vm.hasType(src, 'function') then + if oop then + kind = ckind.Method + else + kind = ckind.Function + end + used[name] = true + buildFunction(results, src, oop, { + label = name, + kind = kind, + id = stack(function () + return { + detail = buildDetail(src), + description = buildDesc(src), + } + end), + }) + else + if oop then return end - if not matchKey(word, name) then - used[name] = true - return + used[name] = true + local literal = vm.getLiteral(src) + if literal ~= nil then + kind = ckind.Enum end - local kind = ckind.Field - if vm.hasType(src, 'function') then - if oop then - kind = ckind.Method - else - kind = ckind.Function - end - used[name] = true - buildFunction(results, src, oop, { - label = name, - kind = kind, - id = stack(function () - return { - detail = buildDetail(src), - description = buildDesc(src), - } - end), - }) - else - if oop then - return - end - used[name] = true - local literal = vm.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) - } + results[#results+1] = { + label = name, + kind = kind, + id = stack(function () + return { + detail = buildDetail(src), + description = buildDesc(src), + } + end) + } + 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 + vm.eachField(parent, function (src) + checkFieldThen(src, used, word, start, parent, oop, results) end) return used end |