Skip to content

Commit

Permalink
fix #826
Browse files Browse the repository at this point in the history
  • Loading branch information
sumneko committed Dec 1, 2021
1 parent 98dc396 commit 90b5385
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 67 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 2.5.2
* `FIX` [#815](https://github.com/sumneko/lua-language-server/issues/815)
* `FIX` [#825](https://github.com/sumneko/lua-language-server/issues/825)
* `FIX` [#826](https://github.com/sumneko/lua-language-server/issues/826)
* `FIX` [#827](https://github.com/sumneko/lua-language-server/issues/827)
* `FIX` [#837](https://github.com/sumneko/lua-language-server/issues/837)
* `FIX` runtime errors
Expand Down
53 changes: 8 additions & 45 deletions script/core/noder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ local ANY_FIELD_CHAR = '*'
local INDEX_CHAR = '['
local RETURN_INDEX = SPLIT_CHAR .. '#'
local PARAM_INDEX = SPLIT_CHAR .. '&'
local PARAM_NAME = SPLIT_CHAR .. '$'
local EVENT_ENUM = SPLIT_CHAR .. '>'
local TABLE_KEY = SPLIT_CHAR .. '<'
local WEAK_TABLE_KEY = SPLIT_CHAR .. '<<'
Expand Down Expand Up @@ -1118,14 +1117,12 @@ compileNodeMap = util.switch()
end
if source.bindSources then
for _, src in ipairs(source.bindSources) do
if src.type == 'function'
or guide.isSet(src) then
local paramID = sformat('%s%s%s'
, getID(src)
, PARAM_NAME
, source.param[1]
)
pushForward(noders, paramID, id)
if src.type == 'function' and src.args then
for _, arg in ipairs(src.args) do
if arg[1] == source.param[1] then
pushForward(noders, getID(arg), id)
end
end
end
end
end
Expand Down Expand Up @@ -1166,12 +1163,6 @@ compileNodeMap = util.switch()
: call(function (noders, id, source)
if source.args then
for index, param in ipairs(source.args) do
local paramID = sformat('%s%s%s'
, id
, PARAM_NAME
, param.name[1]
)
pushForward(noders, paramID, getID(param.extends))
local indexID = sformat('%s%s%s'
, id
, PARAM_INDEX
Expand Down Expand Up @@ -1257,32 +1248,7 @@ compileNodeMap = util.switch()
, i
)
pushForward(noders, indexID, getID(arg))
if arg.type == 'local' then
pushForward(noders, getID(arg), sformat('%s%s%s'
, id
, PARAM_NAME
, arg[1]
))
if parentID then
pushForward(noders, getID(arg), sformat('%s%s%s'
, parentID
, PARAM_NAME
, arg[1]
))
end
else
pushForward(noders, getID(arg), sformat('%s%s%s'
, id
, PARAM_NAME
, '...'
))
if parentID then
pushForward(noders, getID(arg), sformat('%s%s%s'
, parentID
, PARAM_NAME
, '...'
))
end
if arg.type ~= 'local' then
for j = i + 1, i + 10 do
pushForward(noders, sformat('%s%s%s'
, id
Expand Down Expand Up @@ -1576,7 +1542,7 @@ function m.hasField(id)
end
local next2Char = ssub(id, #firstID + 2, #firstID + 2)
if next2Char == RETURN_INDEX
or next2Char == PARAM_NAME then
or next2Char == PARAM_INDEX then
return false
end
return true
Expand All @@ -1600,9 +1566,6 @@ function m.isCommonField(field)
if ssub(field, 1, #RETURN_INDEX) == RETURN_INDEX then
return false
end
if ssub(field, 1, #PARAM_NAME) == PARAM_NAME then
return false
end
return true
end

Expand Down
32 changes: 16 additions & 16 deletions test/crossfile/hover.lua
Original file line number Diff line number Diff line change
Expand Up @@ -988,22 +988,22 @@ p: T
-- comment 4
```]]}

TEST {{ path = 'a.lua', content = '', }, {
path = 'b.lua',
content = [[
---@param x number # aaa
local f
function f(<?x?>) end
]]
},
hover = [[
```lua
local x: number
```
---
aaa]]}
--TEST {{ path = 'a.lua', content = '', }, {
-- path = 'b.lua',
-- content = [[
-----@param x number # aaa
--local f
--
--function f(<?x?>) end
--]]
--},
--hover = [[
--```lua
--local x: number
--```
--
-----
-- aaa]]}

TEST {{ path = 'a.lua', content = '', }, {
path = 'b.lua',
Expand Down
20 changes: 14 additions & 6 deletions test/type_inference/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -912,12 +912,12 @@ for _, a in ipairs(v) do
end
]]

TEST 'number' [[
---@param x number
local f
f = function (<?x?>) end
]]
--TEST 'number' [[
-----@param x number
--local f
--
--f = function (<?x?>) end
--]]

TEST 'integer' [[
--- @class Emit
Expand Down Expand Up @@ -1057,3 +1057,11 @@ f {
TEST 'integer' [[
for <?i?> = a, b, c do end
]]

TEST 'number' [[
---@param x number
function F(<?x?>) end
---@param x boolean
function F(x) end
]]

0 comments on commit 90b5385

Please sign in to comment.