Skip to content

Commit

Permalink
fix #1033
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Apr 11, 2022
1 parent 23ef4b1 commit 4c96b6a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 11 deletions.
3 changes: 3 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# changelog

## 3.0.1
* `FIX` [#1033](https://github.com/sumneko/lua-language-server/issues/1033)

## 3.0.0
`2022-4-10`
* `CHG` [break changes](https://github.com/sumneko/lua-language-server/issues/980)
Expand Down
34 changes: 23 additions & 11 deletions script/vm/compiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,47 +144,59 @@ local searchFieldSwitch = util.switch()
function m.getClassFields(suri, node, key, pushResult)
local mark = {}

local function searchClass(class)
local function searchClass(class, searchedFields)
local name = class.name
if mark[name] then
return
end
mark[name] = true
searchedFields = searchedFields or {}
for _, set in ipairs(class:getSets(suri)) do
if set.type == 'doc.class' then
-- check ---@field
local hasFounded
local hasFounded = {}
for _, field in ipairs(set.fields) do
local fieldKey = guide.getKeyName(field)
if key == nil
or guide.getKeyName(field) == key then
hasFounded = true
pushResult(field)
or fieldKey == key then
if not searchedFields[fieldKey] then
pushResult(field)
hasFounded[fieldKey] = true
end
end
end
-- check local field and global field
if set.bindSources then
for _, src in ipairs(set.bindSources) do
searchFieldSwitch(src.type, suri, src, key, function (field)
if guide.isSet(field) then
hasFounded = true
local fieldKey = guide.getKeyName(field)
if not searchedFields[fieldKey]
and guide.isSet(field) then
hasFounded[fieldKey] = true
pushResult(field)
end
end)
if src._globalNode then
searchFieldSwitch('global', suri, src._globalNode, key, function (field)
hasFounded = true
pushResult(field)
local fieldKey = field:getKeyName()
if not searchedFields[fieldKey] then
hasFounded[fieldKey] = true
pushResult(field)
end
end)
end
end
end
-- look into extends(if field not found)
if not hasFounded and set.extends then
if not hasFounded[key] and set.extends then
for fieldKey in pairs(hasFounded) do
searchedFields[fieldKey] = true
end
for _, extend in ipairs(set.extends) do
if extend.type == 'doc.extends.name' then
local extendType = globalMgr.getGlobal('type', extend[1])
if extendType then
searchClass(extendType)
searchClass(extendType, searchedFields)
end
end
end
Expand Down
7 changes: 7 additions & 0 deletions script/vm/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ mt.__index = mt
mt.type = 'global'
mt.name = ''

local ID_SPLITE = '\x1F'

---@param uri uri
---@param source parser.object
function mt:addSet(uri, source)
Expand Down Expand Up @@ -93,6 +95,11 @@ function mt:getName()
return self.name
end

---@return string
function mt:getKeyName()
return self.name:match('[^' .. ID_SPLITE .. ']+$')
end

---@return boolean
function mt:isAlive()
return next(self.links) ~= nil
Expand Down
17 changes: 17 additions & 0 deletions test/hover/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1849,3 +1849,20 @@ local x: {
[1]: integer = 10,
}
]]

TEST [[
---@class A
---@field x string
---@class B: A
---@field y string
---@type B
local <?t?>
]]
[[
local t: B {
x: string,
y: string,
}
]]

0 comments on commit 4c96b6a

Please sign in to comment.