summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/definition.lua4
-rw-r--r--script/vm/getDef.lua18
-rw-r--r--script/vm/global-manager.lua11
-rw-r--r--script/vm/local-id.lua6
-rw-r--r--script/vm/node/compiler.lua30
-rw-r--r--test/definition/bug.lua42
6 files changed, 76 insertions, 35 deletions
diff --git a/script/core/definition.lua b/script/core/definition.lua
index 9270367f..3323cb84 100644
--- a/script/core/definition.lua
+++ b/script/core/definition.lua
@@ -151,6 +151,10 @@ return function (uri, offset)
if not guide.isLiteral(src) then
goto CONTINUE
end
+ else
+ if guide.isLiteral(src) then
+ goto CONTINUE
+ end
end
if src.type == 'doc.class.name'
or src.type == 'doc.alias.name' then
diff --git a/script/vm/getDef.lua b/script/vm/getDef.lua
index c423ba1a..e661b861 100644
--- a/script/vm/getDef.lua
+++ b/script/vm/getDef.lua
@@ -178,13 +178,30 @@ function searchByParentNode(source, pushResult)
end
end
+local function searchByNode(source, pushResult)
+ local node = compiler.compileNode(source)
+ if not node then
+ return
+ end
+ for n in compiler.eachNode(node) do
+ pushResult(n)
+ end
+end
+
---@param source parser.object
---@return parser.object[]
function vm.getDefs(source)
local results = {}
local mark = {}
+ local hasLocal
local function pushResult(src)
+ if src.type == 'local' and not src.dummy then
+ if hasLocal then
+ return
+ end
+ hasLocal = true
+ end
if not mark[src] then
mark[src] = true
results[#results+1] = src
@@ -195,6 +212,7 @@ function vm.getDefs(source)
searchByGlobal(source, pushResult)
searchByID(source, pushResult)
searchByParentNode(source, pushResult)
+ searchByNode(source, pushResult)
return results
end
diff --git a/script/vm/global-manager.lua b/script/vm/global-manager.lua
index 5267aea1..4c2a535e 100644
--- a/script/vm/global-manager.lua
+++ b/script/vm/global-manager.lua
@@ -60,15 +60,19 @@ local compilerGlobalMap = util.switch()
---@param source parser.object
: call(function (source)
local name
+ local keyName = guide.getKeyName(source)
+ if not keyName then
+ return
+ end
if source.node._globalNode then
local parentName = source.node._globalNode:getName()
if parentName == '_G' then
- name = guide.getKeyName(source)
+ name = keyName
else
- name = parentName .. m.ID_SPLITE .. guide.getKeyName(source)
+ name = parentName .. m.ID_SPLITE .. keyName
end
elseif source.node.special == '_G' then
- name = guide.getKeyName(source)
+ name = keyName
end
if not name then
return
@@ -117,6 +121,7 @@ local compilerGlobalMap = util.switch()
local global = m.declareGlobal(name, uri)
if source.node.special == 'rawset' then
global:addSet(uri, source)
+ source.value = source.args[3]
else
global:addGet(uri, source)
end
diff --git a/script/vm/local-id.lua b/script/vm/local-id.lua
index ddcb9e97..230f48eb 100644
--- a/script/vm/local-id.lua
+++ b/script/vm/local-id.lua
@@ -59,7 +59,11 @@ local compileMap = util.switch()
if not parentID then
return
end
- source._localID = parentID .. m.ID_SPLITE .. guide.getKeyName(source)
+ local key = guide.getKeyName(source)
+ if not key then
+ return
+ end
+ source._localID = parentID .. m.ID_SPLITE .. key
source.index._localID = source._localID
if source.type == 'setindex' then
m.compileLocalID(source.next)
diff --git a/script/vm/node/compiler.lua b/script/vm/node/compiler.lua
index dbfc54d1..dd151e4f 100644
--- a/script/vm/node/compiler.lua
+++ b/script/vm/node/compiler.lua
@@ -109,16 +109,14 @@ local function getReturnOfSetMetaTable(source, args)
end
local function getReturn(func, index, source, args)
- local node = m.compileNode(func)
- if not node then
- return
+ if func.special == 'setmetatable' then
+ return getReturnOfSetMetaTable(source, args)
end
- for cnode in m.eachNode(node) do
- if cnode.type == 'function' then
- return getReturnOfFunction(cnode, index)
- elseif cnode.type == 'global' then
- if cnode.name == 'setmetatable' and index == 1 then
- return getReturnOfSetMetaTable(source, args)
+ local node = m.compileNode(func)
+ if node then
+ for cnode in m.eachNode(node) do
+ if cnode.type == 'function' then
+ return getReturnOfFunction(cnode, index)
end
end
end
@@ -215,6 +213,11 @@ local compilerMap = util.switch()
m.setNode(source, m.compileNode(source.value))
end
end)
+ : case 'field'
+ : case 'method'
+ : call(function (source)
+ m.setNode(source, m.compileNode(source.parent))
+ end)
: case 'function.return'
: call(function (source)
local func = source.parent
@@ -234,6 +237,10 @@ local compilerMap = util.switch()
m.setNode(source, getReturn(vararg.node, source.sindex, source, vararg.args))
end
end)
+ : case 'call'
+ : call(function (source)
+ m.setNode(source, getReturn(source.node, 1, source, source.args))
+ end)
: getMap()
---@param source parser.object
@@ -248,6 +255,11 @@ end
local function compileByGlobal(source)
if source._globalNode then
m.setNode(source, source._globalNode)
+ for _, set in ipairs(source._globalNode:getSets()) do
+ if set.value then
+ m.setNode(source, m.compileNode(set.value))
+ end
+ end
end
end
diff --git a/test/definition/bug.lua b/test/definition/bug.lua
index 77797f40..ef7295d1 100644
--- a/test/definition/bug.lua
+++ b/test/definition/bug.lua
@@ -134,7 +134,7 @@ t:<?add?>()
TEST [[
local t = {}
-t.<!f1!> = 1
+t.f1 = 1
t.<!f2!> = t.f1
print(t.<?f2?>)
@@ -142,9 +142,9 @@ print(t.<?f2?>)
TEST [[
local t = {}
-t.<!f1!> = 1
+t.f1 = 1
t.<!f2!> = t.f1
-t.<!f1!> = t.f2
+t.f1 = t.f2
print(t.<?f2?>)
]]
@@ -172,67 +172,65 @@ string.xx:<?format?>()
--v.<?bar1?>
--]]
-config.set(nil, 'Lua.IntelliSense.traceLocalSet', true)
TEST [[
local A, B
function A:get1()
- local <!a!> = B:get()
+ local a = B:get()
return a
end
function A:get2()
- local <!a!> = B:get()
+ local a = B:get()
return a
end
function A:get3()
- local <!a!> = B:get()
+ local a = B:get()
return a
end
function A:get4()
- local <!a!> = B:get()
+ local a = B:get()
return a
end
function A:get5()
- local <!a!> = B:get()
+ local a = B:get()
return a
end
function A:get6()
- local <!a!> = B:get()
+ local a = B:get()
return a
end
function A:get7()
- local <!a!> = B:get()
+ local a = B:get()
return a
end
function A:get8()
- local <!a!> = B:get()
+ local a = B:get()
return a
end
function B:get()
- local <!b!>
- <!b!> = A:get1()
- <!b!> = A:get2()
- <!b!> = A:get3()
- <!b!> = A:get4()
- <!b!> = A:get5()
- <!b!> = A:get6()
- <!b!> = A:get7()
- <!b!> = A:get8()
+ local b
+ b = A:get1()
+ b = A:get2()
+ b = A:get3()
+ b = A:get4()
+ b = A:get5()
+ b = A:get6()
+ b = A:get7()
+ b = A:get8()
return b
end
local <!b!> = B:get()
print(<?b?>)
]]
-config.set(nil, 'Lua.IntelliSense.traceLocalSet', false)
TEST [[
g[a.b.c] = 1