diff options
-rw-r--r-- | script/core/diagnostics/undefined-field.lua | 8 | ||||
-rw-r--r-- | script/parser/guide.lua | 60 | ||||
-rw-r--r-- | script/vm/eachField.lua | 25 | ||||
-rw-r--r-- | script/vm/vm.lua | 40 |
4 files changed, 78 insertions, 55 deletions
diff --git a/script/core/diagnostics/undefined-field.lua b/script/core/diagnostics/undefined-field.lua index 04ae95dd..a8fadfed 100644 --- a/script/core/diagnostics/undefined-field.lua +++ b/script/core/diagnostics/undefined-field.lua @@ -29,7 +29,7 @@ return function (uri, callback) local allDocClass = {} for i = 1, #infers do local infer = infers[i] - if infer.type ~= '_G' then + if infer.type ~= '_G' and infer.type ~= 'any' then local inferSource = infer.source if inferSource.type == 'doc.class' then addTo(allDocClass, inferSource) @@ -49,17 +49,13 @@ return function (uri, callback) return allDocClass end - ---@param allDocClass table int local function getAllFieldsFromAllDocClass(allDocClass) local fields = {} local empty = true for _, docClass in ipairs(allDocClass) do - local refs = vm.getFields(docClass) + local refs = vm.getFieldsOfDocClassAnyNotGet(docClass) for _, ref in ipairs(refs) do - if ref.type == 'getfield' or ref.type == 'getmethod' then - goto CONTINUE - end local name = vm.getKeyName(ref) if not name or vm.getKeyType(ref) ~= 'string' then goto CONTINUE diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 5fcfc0f3..40404f70 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -29,7 +29,9 @@ _ENV = nil local m = {} -m.ANY = {} +m.ANY = {"ANY"} + +m.ANYNOTGET = {"ANYNOTGET"} local blockTypes = { ['while'] = true, @@ -1246,6 +1248,52 @@ function m.isDocClass(source) return source.type == 'doc.class' end +function m.isSet(source) + local tp = source.type + if tp == 'setglobal' + or tp == 'local' + or tp == 'setlocal' + or tp == 'setfield' + or tp == 'setmethod' + or tp == 'setindex' + or tp == 'tablefield' + or tp == 'tableindex' then + return true + end + if tp == 'call' then + local special = m.getSpecial(source.node) + if special == 'rawset' then + return true + end + end + return false +end + +function m.isGet(source) + local tp = source.type + if tp == 'getglobal' + or tp == 'getlocal' + or tp == 'getfield' + or tp == 'getmethod' + or tp == 'getindex' then + return true + end + if tp == 'call' then + local special = m.getSpecial(source.node) + if special == 'rawget' then + return true + end + end + return false +end + +function m.getSpecial(source) + if not source then + return nil + end + return source.special +end + --- 根据函数的调用参数,获取:调用,参数索引 function m.getCallAndArgIndex(callarg) local callargs = callarg.parent @@ -2291,6 +2339,11 @@ function m.checkSameSimpleName(ref, sm) if sm == m.ANY then return true end + + if sm == m.ANYNOTGET and not m.isGet(ref) then + return true + end + if m.getSimpleName(ref) == sm then return true end @@ -4007,10 +4060,11 @@ function m.requestDefinition(obj, interface, deep) end --- 请求对象的域 -function m.requestFields(obj, interface, deep) +---@param filterKey nil|string|table nil表fields不做限制;string表fields必须同名;table取值为guild.ANYSET表fields必须满足isSet() +function m.requestFields(obj, interface, deep, filterKey) local status = m.status(nil, interface, deep) - m.searchFields(status, obj) + m.searchFields(status, obj, filterKey) return status.results, status.share.count end diff --git a/script/vm/eachField.lua b/script/vm/eachField.lua index 292ac39b..ce2be968 100644 --- a/script/vm/eachField.lua +++ b/script/vm/eachField.lua @@ -4,7 +4,7 @@ local guide = require 'parser.guide' local await = require 'await' local config = require 'config' -local function getFields(source, deep) +local function getFields(source, deep, filterKey) local unlock = vm.lock('eachField', source) if not unlock then return {} @@ -19,18 +19,19 @@ local function getFields(source, deep) deep = config.config.intelliSense.searchDepth + (deep or 0) await.delay() - local results = guide.requestFields(source, vm.interface, deep) + local results = guide.requestFields(source, vm.interface, deep, filterKey) unlock() return results end -local function getFieldsBySource(source, deep) +local function getFieldsBySource(source, deep, filterKey) deep = deep or -999 local cache = vm.getCache('eachField')[source] if not cache or cache.deep < deep then - cache = getFields(source, deep) + cache = getFields(source, deep, filterKey) cache.deep = deep + cache.filterKey = filterKey vm.getCache('eachField')[source] = cache end return cache @@ -46,12 +47,18 @@ function vm.getFields(source, deep) or getFieldsBySource(source, deep) vm.getCache('eachFieldOfGlobal')[name] = cache return cache - elseif guide.isDocClass(source) then - local cache = vm.getCache('eachFieldOfDocClass')[source] - or getFieldsBySource(source, deep) - vm.getCache('eachFieldOfDocClass')[source] = cache - return cache else return getFieldsBySource(source, deep) end end + +function vm.getFieldsOfDocClassAnyNotGet(source, deep) + if not guide.isDocClass(source) then + return {} + end + + local cache = vm.getCache('eachFieldOfDocClass')[source] + or getFieldsBySource(source, deep, guide.ANYNOTGET) + vm.getCache('eachFieldOfDocClass')[source] = cache + return cache +end diff --git a/script/vm/vm.lua b/script/vm/vm.lua index 9caab31f..b7eb1cde 100644 --- a/script/vm/vm.lua +++ b/script/vm/vm.lua @@ -39,42 +39,11 @@ function m.lock(tp, source) end function m.isSet(src) - local tp = src.type - if tp == 'setglobal' - or tp == 'local' - or tp == 'setlocal' - or tp == 'setfield' - or tp == 'setmethod' - or tp == 'setindex' - or tp == 'tablefield' - or tp == 'tableindex' then - return true - end - if tp == 'call' then - local special = m.getSpecial(src.node) - if special == 'rawset' then - return true - end - end - return false + return guide.isSet(src) end function m.isGet(src) - local tp = src.type - if tp == 'getglobal' - or tp == 'getlocal' - or tp == 'getfield' - or tp == 'getmethod' - or tp == 'getindex' then - return true - end - if tp == 'call' then - local special = m.getSpecial(src.node) - if special == 'rawget' then - return true - end - end - return false + return guide.isGet(src) end function m.getArgInfo(source) @@ -95,10 +64,7 @@ function m.getArgInfo(source) end function m.getSpecial(source) - if not source then - return nil - end - return source.special + return guide.getSpecial(source) end function m.getKeyName(source) |