Skip to content

Commit

Permalink
fix #244
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Aug 10, 2021
1 parent 871035d commit 770f217
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
48 changes: 45 additions & 3 deletions script/core/noder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ local function getMethodNode(source)
end
end

local getKey
local getKey, getID
local getKeyMap = util.switch()
: case 'local'
: call(function (source)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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)
Expand Down
21 changes: 21 additions & 0 deletions test/crossfile/definition.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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?>)
]]
}
}

0 comments on commit 770f217

Please sign in to comment.