summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-08-10 11:52:46 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-08-10 11:52:46 +0800
commit770f21794065e42919a515da2a50a2cf1e1eff60 (patch)
treee272349d3483053b487afa08bbca749f99ac7bfe
parent871035d0574b96175f44cdedd0f8256ae74a0534 (diff)
downloadlua-language-server-770f21794065e42919a515da2a50a2cf1e1eff60.zip
fix #244
-rw-r--r--changelog.md3
-rw-r--r--script/core/noder.lua48
-rw-r--r--test/crossfile/definition.lua21
3 files changed, 69 insertions, 3 deletions
diff --git a/changelog.md b/changelog.md
index b50dc044..72f8259b 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,8 @@
# changelog
+## 2.3.7
+* `FIX` [#244](https://github.com/sumneko/lua-language-server/issues/244)
+
## 2.3.6
`2021-8-9`
* `FIX` completion: can not find global fields
diff --git a/script/core/noder.lua b/script/core/noder.lua
index ac1d96d8..2e1313a2 100644
--- a/script/core/noder.lua
+++ b/script/core/noder.lua
@@ -93,7 +93,7 @@ local function getMethodNode(source)
end
end
-local getKey
+local getKey, getID
local getKeyMap = util.switch()
: case 'local'
: call(function (source)
@@ -366,6 +366,27 @@ function getKey(source)
return nil
end
+local function getLocalValueID(source)
+ if source.type ~= 'local' then
+ return nil
+ end
+ local value = source.value
+ if not value then
+ return nil
+ end
+ local id = getID(value)
+ if not id then
+ return nil
+ end
+ local ct = id:sub(1, 2)
+ if ct == 'g:'
+ or ct == 'p:'
+ or ct == 'l:' then
+ return id
+ end
+ return nil
+end
+
local function getNodeKey(source)
if source.type == 'getlocal'
or source.type == 'setlocal' then
@@ -375,6 +396,10 @@ local function getNodeKey(source)
if methodNode then
return getNodeKey(methodNode)
end
+ local localValueID = getLocalValueID(source)
+ if localValueID then
+ return localValueID
+ end
local key, node = getKey(source)
if key and guide.isGlobal(source) then
return 'g:' .. key, nil
@@ -385,7 +410,7 @@ end
---获取语法树单元的字符串ID
---@param source parser.guide.object
---@return string? id
-local function getID(source)
+function getID(source)
if not source then
return nil
end
@@ -1235,7 +1260,9 @@ function m.compileNode(noders, source)
if id and ssub(id, 1, 2) == 'g:' then
local uri = guide.getUri(source)
collector.subscribe(uri, id, noders)
- if guide.isSet(source) then
+ if guide.isSet(source)
+ -- local t = Global --> t: g:.Global
+ and source.type ~= 'local' then
local defID = 'def:' .. id
collector.subscribe(uri, defID, noders)
@@ -1470,6 +1497,11 @@ local partNodersMap = util.switch()
if nxt then
m.compilePartNodes(noders, nxt)
end
+
+ local parent = source.parent
+ if parent.value == source then
+ m.compilePartNodes(noders, parent)
+ end
end)
: case 'setfield'
: case 'getfield'
@@ -1483,6 +1515,11 @@ local partNodersMap = util.switch()
if nxt then
m.compilePartNodes(noders, nxt)
end
+
+ local parent = source.parent
+ if parent.value == source then
+ m.compilePartNodes(noders, parent)
+ end
end)
: case 'setglobal'
: case 'getglobal'
@@ -1491,6 +1528,11 @@ local partNodersMap = util.switch()
if nxt then
m.compilePartNodes(noders, nxt)
end
+
+ local parent = source.parent
+ if parent.value == source then
+ m.compilePartNodes(noders, parent)
+ end
end)
: case 'label'
: call(function (noders, source)
diff --git a/test/crossfile/definition.lua b/test/crossfile/definition.lua
index be6a5dc6..d492761e 100644
--- a/test/crossfile/definition.lua
+++ b/test/crossfile/definition.lua
@@ -784,3 +784,24 @@ TEST {
]],
},
}
+
+TEST {
+ {
+ path = 'a.lua',
+ content = [[
+local t = GlobalTable
+
+t.settings = {
+ <!test!> = 1
+}
+ ]]
+ },
+ {
+ path = 'b.lua',
+ content = [[
+local b = GlobalTable.settings
+
+print(b.<?test?>)
+ ]]
+ }
+}