summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-06-16 17:12:03 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-06-16 17:12:03 +0800
commitb2f02681993eb0f38468767255d8a7ba71fadc72 (patch)
treefb04efa526b10e66e099eccb6cd0ef7d0aea9499
parentb02cc8207450ffdd9973f689b2e32a5facd68996 (diff)
downloadlua-language-server-b2f02681993eb0f38468767255d8a7ba71fadc72.zip
improve
-rw-r--r--script/core/noder.lua48
-rw-r--r--test/definition/luadoc.lua6
-rw-r--r--test/diagnostics/init.lua6
3 files changed, 38 insertions, 22 deletions
diff --git a/script/core/noder.lua b/script/core/noder.lua
index b1eff89a..8fa55ea3 100644
--- a/script/core/noder.lua
+++ b/script/core/noder.lua
@@ -415,26 +415,44 @@ function m.pushSource(noders, source)
node.sources[#node.sources+1] = source
end
+local function bindValue(noders, source, id)
+ local value = source.value
+ if not value then
+ return
+ end
+ local valueID = getID(value)
+ if not valueID then
+ return
+ end
+ if source.type == 'getlocal'
+ or source.type == 'setlocal' then
+ source = source.node
+ end
+ if source.bindDocs and value.type ~= 'table' then
+ for _, doc in ipairs(source.bindDocs) do
+ if doc.type == 'doc.class'
+ or doc.type == 'doc.type' then
+ return
+ end
+ end
+ end
+ -- x = y : x -> y
+ pushForward(noders, id, valueID, 'set')
+ -- 参数/call禁止反向查找赋值
+ local valueType = valueID:match '^.-:'
+ if valueType ~= 'p:'
+ and valueType ~= 's:'
+ and valueType ~= 'c:' then
+ pushBackward(noders, valueID, id, 'set')
+ end
+end
+
---@param noders noders
---@param source parser.guide.object
---@return parser.guide.object[]
function m.compileNode(noders, source)
local id = getID(source)
- local value = source.value
- if value then
- local valueID = getID(value)
- if valueID then
- -- x = y : x -> y
- pushForward(noders, id, valueID, 'set')
- -- 参数/call禁止反向查找赋值
- local valueType = valueID:match '^.-:'
- if valueType ~= 'p:'
- and valueType ~= 's:'
- and valueType ~= 'c:' then
- pushBackward(noders, valueID, id, 'set')
- end
- end
- end
+ bindValue(noders, source, id)
if source.special == 'setmetatable'
or source.special == 'require'
or source.special == 'dofile'
diff --git a/test/definition/luadoc.lua b/test/definition/luadoc.lua
index 5531e2e3..65ded319 100644
--- a/test/definition/luadoc.lua
+++ b/test/definition/luadoc.lua
@@ -68,12 +68,10 @@ TEST [[
local obj
obj:<?func?>()
+---@class A
local mt = {}
-mt.__index = mt
function mt:<!func!>()
end
----@class A
-local obj = setmetatable({}, mt)
]]
TEST [[
@@ -113,7 +111,7 @@ print(<?f?>)
TEST [[
local function f()
- return <!1!>
+ return 1
end
---@class Class
diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua
index 0f5880ae..b087f3b0 100644
--- a/test/diagnostics/init.lua
+++ b/test/diagnostics/init.lua
@@ -963,9 +963,9 @@ function mt2:method2() end
local v
---@type Bar
local v2
-v2 = v
-v2:method1()
-v2:method2() -- 这个感觉实际应该报错更合适
+v2 = v -- TODO 这里应该给警告
+v2:<!method1!>()
+v2:method2()
]]
TEST [[