summaryrefslogtreecommitdiff
path: root/script-beta
diff options
context:
space:
mode:
Diffstat (limited to 'script-beta')
-rw-r--r--script-beta/core/completion.lua2
-rw-r--r--script-beta/core/diagnostics/redundant-parameter.lua4
-rw-r--r--script-beta/core/hover/table.lua6
-rw-r--r--script-beta/core/reference.lua9
-rw-r--r--script-beta/core/semantic-tokens.lua4
-rw-r--r--script-beta/core/signature.lua2
-rw-r--r--script-beta/parser/guide.lua39
-rw-r--r--script-beta/vm/eachDef.lua14
-rw-r--r--script-beta/vm/eachField.lua12
-rw-r--r--script-beta/vm/eachRef.lua14
-rw-r--r--script-beta/vm/getInfer.lua12
11 files changed, 64 insertions, 54 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua
index 5a18ccaf..6939d240 100644
--- a/script-beta/core/completion.lua
+++ b/script-beta/core/completion.lua
@@ -196,7 +196,7 @@ local function getSnip(source)
if context <= 0 then
return nil
end
- local defs = vm.getRefs(source, 'simple')
+ local defs = vm.getRefs(source)
for _, def in ipairs(defs) do
if def ~= source and def.type == 'function' then
local uri = guide.getUri(def)
diff --git a/script-beta/core/diagnostics/redundant-parameter.lua b/script-beta/core/diagnostics/redundant-parameter.lua
index a03a408f..074e7f7c 100644
--- a/script-beta/core/diagnostics/redundant-parameter.lua
+++ b/script-beta/core/diagnostics/redundant-parameter.lua
@@ -6,7 +6,7 @@ local define = require 'proto.define'
local await = require 'await'
local function countLibraryArgs(source)
- local lib = vm.getLibrary(source, 'simple')
+ local lib = vm.getLibrary(source)
if not lib then
return nil
end
@@ -63,7 +63,7 @@ return function (uri, callback)
local func = source.node
local funcArgs
- local defs = vm.getDefs(func, 'simple')
+ local defs = vm.getDefs(func)
for _, def in ipairs(defs) do
if def.type == 'function' then
local args = countFuncArgs(def)
diff --git a/script-beta/core/hover/table.lua b/script-beta/core/hover/table.lua
index 812a69be..314d0b42 100644
--- a/script-beta/core/hover/table.lua
+++ b/script-beta/core/hover/table.lua
@@ -49,9 +49,9 @@ local function getField(src)
end
end
end
- local tp = vm.getInferType(src, 'simple')
- local class = vm.getClass(src, 'simple')
- local literal = vm.getInferLiteral(src, 'simple')
+ local tp = vm.getInferType(src)
+ local class = vm.getClass(src)
+ local literal = vm.getInferLiteral(src)
if type(literal) == 'string' and #literal >= 50 then
literal = literal:sub(1, 47) .. '...'
end
diff --git a/script-beta/core/reference.lua b/script-beta/core/reference.lua
index 13d698a2..0e3268f5 100644
--- a/script-beta/core/reference.lua
+++ b/script-beta/core/reference.lua
@@ -71,10 +71,10 @@ return function (uri, offset)
local results = {}
vm.setSearchLevel(10)
- vm.eachRef(source, function (src)
+ for _, src in ipairs(vm.getRefs(source, 'deep')) do
local root = guide.getRoot(src)
if not root then
- return
+ goto CONTINUE
end
if src.type == 'setfield'
or src.type == 'getfield'
@@ -88,13 +88,14 @@ return function (uri, offset)
or src.type == 'setmethod' then
src = src.method
elseif src.type == 'table' and src.parent.type ~= 'return' then
- return
+ goto CONTINUE
end
results[#results+1] = {
target = src,
uri = files.getOriginUri(root.uri),
}
- end)
+ ::CONTINUE::
+ end
if #results == 0 then
return nil
diff --git a/script-beta/core/semantic-tokens.lua b/script-beta/core/semantic-tokens.lua
index 222f54b6..fa037610 100644
--- a/script-beta/core/semantic-tokens.lua
+++ b/script-beta/core/semantic-tokens.lua
@@ -15,7 +15,7 @@ Care['setglobal'] = function (source, results)
}
end
Care['getglobal'] = function (source, results)
- local lib = vm.getLibrary(source, 'simple')
+ local lib = vm.getLibrary(source)
if lib then
if source[1] == '_G' then
return
@@ -67,7 +67,7 @@ Care['getlocal'] = function (source, results)
end
-- 3. 不是函数的局部变量
local hasFunc
- for _, def in ipairs(vm.getDefs(loc, 'simple')) do
+ for _, def in ipairs(vm.getDefs(loc)) do
if def.type == 'function'
or (def.type == 'library' and def.value.type == 'function') then
hasFunc = true
diff --git a/script-beta/core/signature.lua b/script-beta/core/signature.lua
index be39f6c9..ba21ae50 100644
--- a/script-beta/core/signature.lua
+++ b/script-beta/core/signature.lua
@@ -79,7 +79,7 @@ local function makeSignatures(call, pos)
index = 1
end
local signs = {}
- local defs = vm.getDefs(node, 'simple')
+ local defs = vm.getDefs(node)
for _, src in ipairs(defs) do
if src.type == 'function' then
signs[#signs+1] = makeOneSignature(src, oop, index)
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua
index be08b949..1d375d89 100644
--- a/script-beta/parser/guide.lua
+++ b/script-beta/parser/guide.lua
@@ -1183,9 +1183,12 @@ function m.status(parentStatus, interface)
depth = parentStatus and (parentStatus.depth + 1) or 1,
interface = parentStatus and parentStatus.interface or {},
locks = parentStatus and parentStatus.locks or {},
- simple = parentStatus and (parentStatus.simple or parentStatus.depth > 1),
+ deep = parentStatus and parentStatus.deep,
results = {},
}
+ if status.depth >= 3 then
+ status.deep = false
+ end
status.lock = status.locks[status.depth] or {}
status.locks[status.depth] = status.lock
if interface then
@@ -1297,7 +1300,7 @@ function m.checkSameSimpleInValueOfTable(status, value, start, queue)
end
end
-function m.searchFields(status, obj, key, interface)
+function m.searchFields(status, obj, key, interface, deep)
if obj.type == 'table' then
local keyName = key and ('s|' .. key)
local results = {}
@@ -1316,6 +1319,7 @@ function m.searchFields(status, obj, key, interface)
return results
else
local newStatus = m.status(status, interface)
+ --newStatus.deep = deep
local simple = m.getSimple(obj)
if not simple then
return {}
@@ -1981,7 +1985,7 @@ function m.checkSameSimple(status, simple, data, mode, results, queue)
m.checkSameSimpleInValueOfCallMetaTable(status, ref, i, queue)
-- 检查自己是特殊变量的分支的情况
m.checkSameSimpleInSpecialBranch(status, ref, i, queue)
- if cmode == 'ref' and not status.simple then
+ if cmode == 'ref' and status.deep then
-- 检查形如 { a = f } 的情况
m.checkSameSimpleAsTableField(status, ref, i, queue)
-- 检查形如 return m 的情况
@@ -3086,6 +3090,13 @@ function m.inferCheckBinary(status, source)
end
function m.inferByDef(status, obj)
+ if not status.cache.inferedDef then
+ status.cache.inferedDef = {}
+ end
+ if status.cache.inferedDef[obj] then
+ return
+ end
+ status.cache.inferedDef[obj] = true
local mark = {}
local newStatus = m.status(status, status.interface)
m.searchRefs(newStatus, obj, 'def')
@@ -3488,7 +3499,7 @@ function m.searchInfer(status, obj)
end
local cache, makeCache
- if not status.simple then
+ if status.deep then
cache, makeCache = m.getRefCache(status, obj, 'infer')
end
if cache then
@@ -3517,9 +3528,7 @@ function m.searchInfer(status, obj)
return
end
- if not status.simple then
- m.inferByDef(status, obj)
- end
+ m.inferByDef(status, obj)
m.inferBySet(status, obj)
m.inferByCall(status, obj)
m.inferByGetTable(status, obj)
@@ -3537,9 +3546,9 @@ end
--- 与 `return function` 形式。
--- 不穿透 `setmetatable` ,考虑由
--- 业务层进行反向 def 搜索。
-function m.requestReference(obj, interface, simple)
+function m.requestReference(obj, interface, deep)
local status = m.status(nil, interface)
- status.simple = simple
+ status.deep = deep
-- 根据 field 搜索引用
m.searchRefs(status, obj, 'ref')
@@ -3555,9 +3564,9 @@ end
--- 请求对象的定义,包括 `a.b.c` 形式
--- 与 `return function` 形式。
--- 穿透 `setmetatable` 。
-function m.requestDefinition(obj, interface, simple)
+function m.requestDefinition(obj, interface, deep)
local status = m.status(nil, interface)
- status.simple = simple
+ status.deep = deep
-- 根据 field 搜索定义
m.searchRefs(status, obj, 'def')
@@ -3565,14 +3574,14 @@ function m.requestDefinition(obj, interface, simple)
end
--- 请求对象的域
-function m.requestFields(obj, interface)
- return m.searchFields(nil, obj, nil, interface)
+function m.requestFields(obj, interface, deep)
+ return m.searchFields(nil, obj, nil, interface, deep)
end
--- 请求对象的类型推测
-function m.requestInfer(obj, interface, simple)
+function m.requestInfer(obj, interface, deep)
local status = m.status(nil, interface)
- status.simple = simple
+ status.deep = deep
m.searchInfer(status, obj)
return status.results, status.cache.count
diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua
index ec3930ed..8b3c6a9b 100644
--- a/script-beta/vm/eachDef.lua
+++ b/script-beta/vm/eachDef.lua
@@ -4,9 +4,7 @@ local files = require 'files'
local util = require 'utility'
local await = require 'await'
-local m = {}
-
-function m.eachDef(source, simple)
+local function eachDef(source, simple)
local results = {}
local lock = vm.lock('eachDef', source)
if not lock then
@@ -27,19 +25,19 @@ function m.eachDef(source, simple)
return results
end
-function vm.getDefs(source, simple)
+function vm.getDefs(source, deep)
if guide.isGlobal(source) then
local name = guide.getKeyName(source)
local cache = vm.getCache('eachDefOfGlobal')[name]
or vm.getCache('eachDef')[source]
- or m.eachDef(source)
+ or eachDef(source, deep)
vm.getCache('eachDefOfGlobal')[name] = cache
return cache
- elseif simple then
- return m.eachDef(source, simple)
+ elseif deep then
+ return eachDef(source, deep)
else
local cache = vm.getCache('eachDef')[source]
- or m.eachDef(source)
+ or eachDef(source, deep)
vm.getCache('eachDef')[source] = cache
return cache
end
diff --git a/script-beta/vm/eachField.lua b/script-beta/vm/eachField.lua
index 632cf211..9075bf36 100644
--- a/script-beta/vm/eachField.lua
+++ b/script-beta/vm/eachField.lua
@@ -20,7 +20,7 @@ local function eachFieldOfLibrary(results)
end
end
-local function eachField(source)
+local function eachField(source, deep)
local unlock = vm.lock('eachField', source)
if not unlock then
return
@@ -34,7 +34,7 @@ local function eachField(source)
end
await.delay()
- local results = guide.requestFields(source, vm.interface)
+ local results = guide.requestFields(source, vm.interface, deep)
if source.special == '_G' then
eachFieldOfLibrary(results)
end
@@ -46,17 +46,19 @@ local function eachField(source)
return results
end
-function vm.getFields(source)
+function vm.getFields(source, deep)
if guide.isGlobal(source) then
local name = guide.getKeyName(source)
local cache = vm.getCache('eachFieldOfGlobal')[name]
or vm.getCache('eachField')[source]
- or eachField(source)
+ or eachField(source, deep)
vm.getCache('eachFieldOfGlobal')[name] = cache
return cache
+ elseif deep then
+ return eachField(source, deep)
else
local cache = vm.getCache('eachField')[source]
- or eachField(source)
+ or eachField(source, deep)
vm.getCache('eachField')[source] = cache
return cache
end
diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua
index 429cbb73..8391d89d 100644
--- a/script-beta/vm/eachRef.lua
+++ b/script-beta/vm/eachRef.lua
@@ -3,7 +3,7 @@ local guide = require 'parser.guide'
local util = require 'utility'
local await = require 'await'
-local function getRefs(source, simple)
+local function getRefs(source, deep)
local results = {}
local lock = vm.lock('eachRef', source)
if not lock then
@@ -13,7 +13,7 @@ local function getRefs(source, simple)
await.delay()
local clock = os.clock()
- local myResults, count = guide.requestReference(source, vm.interface, simple)
+ local myResults, count = guide.requestReference(source, vm.interface, deep)
if DEVELOP and os.clock() - clock > 0.1 then
log.warn('requestReference', count, os.clock() - clock, guide.getUri(source), util.dump(source, { deep = 1 }))
end
@@ -24,19 +24,19 @@ local function getRefs(source, simple)
return results
end
-function vm.getRefs(source, simple)
+function vm.getRefs(source, deep)
if guide.isGlobal(source) then
local name = guide.getKeyName(source)
local cache = vm.getCache('eachRefOfGlobal')[name]
or vm.getCache('eachRef')[source]
- or getRefs(source)
+ or getRefs(source, deep)
vm.getCache('eachRefOfGlobal')[name] = cache
return cache
- elseif simple then
- return getRefs(source, simple)
+ elseif deep then
+ return getRefs(source, deep)
else
local cache = vm.getCache('eachRef')[source]
- or getRefs(source)
+ or getRefs(source, deep)
vm.getCache('eachRef')[source] = cache
return cache
end
diff --git a/script-beta/vm/getInfer.lua b/script-beta/vm/getInfer.lua
index 18f7f0ef..db3b240c 100644
--- a/script-beta/vm/getInfer.lua
+++ b/script-beta/vm/getInfer.lua
@@ -29,13 +29,13 @@ function vm.hasInferType(source, type)
return false
end
-function vm.getInferType(source, simple)
- local infers = vm.getInfers(source, simple)
+function vm.getInferType(source, deep)
+ local infers = vm.getInfers(source, deep)
return guide.viewInferType(infers)
end
-function vm.getInferLiteral(source, simple)
- local infers = vm.getInfers(source, simple)
+function vm.getInferLiteral(source, deep)
+ local infers = vm.getInfers(source, deep)
local literals = {}
local mark = {}
for _, infer in ipairs(infers) do
@@ -54,12 +54,12 @@ end
--- 获取对象的值
--- 会尝试穿透函数调用
-function vm.getInfers(source, simple)
+function vm.getInfers(source, deep)
if not source then
return
end
local clock = os.clock()
- local infers = guide.requestInfer(source, vm.interface, simple)
+ local infers = guide.requestInfer(source, vm.interface, deep)
if os.clock() - clock > 0.1 then
log.warn(('Request infer takes [%.3f]sec! %s %s'):format(os.clock() - clock, guide.getUri(source), util.dump(source, { deep = 1 })))
end