summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-12-14 15:47:43 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-12-14 15:47:43 +0800
commit9a24fa993879985468c291eb9f1003e8b8f5b4ce (patch)
tree2eea7714d82c2e9cf39790568f3c234fb34c006f
parent98bf48a28b34a8437904675d61eeb960a20b8833 (diff)
downloadlua-language-server-9a24fa993879985468c291eb9f1003e8b8f5b4ce.zip
`undefined-field` select field only
-rw-r--r--script/core/diagnostics/undefined-field.lua18
-rw-r--r--test/diagnostics/init.lua20
2 files changed, 23 insertions, 15 deletions
diff --git a/script/core/diagnostics/undefined-field.lua b/script/core/diagnostics/undefined-field.lua
index 67208e35..04ae95dd 100644
--- a/script/core/diagnostics/undefined-field.lua
+++ b/script/core/diagnostics/undefined-field.lua
@@ -94,11 +94,19 @@ return function (uri, callback)
if not fields[fieldName] then
local message = lang.script('DIAG_UNDEF_FIELD', fieldName)
- callback {
- start = src.start,
- finish = src.finish,
- message = message,
- }
+ if src.type == 'getfield' then
+ callback {
+ start = src.field.start,
+ finish = src.field.finish,
+ message = message,
+ }
+ elseif src.type == 'getmethod' then
+ callback {
+ start = src.method.start,
+ finish = src.method.finish,
+ message = message,
+ }
+ end
end
end
guide.eachSourceType(ast.ast, 'getfield', checkUndefinedField);
diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua
index 3f3c563c..cfd0f4cb 100644
--- a/test/diagnostics/init.lua
+++ b/test/diagnostics/init.lua
@@ -847,20 +847,20 @@ local mt2 = {}
local v
print(v.field1 + 1)
print(v.field2 + 1)
-print(<!v.field3!> + 1)
+print(v.<!field3!> + 1)
print(v:method1())
print(v.method2())
-print(<!v:method3!>())
+print(v:<!method3!>())
---@type Bar
local v2
print(v2.field1 + 1)
print(v2.field2 + 1)
-print(<!v2.field3!> + 1)
+print(v2.<!field3!> + 1)
print(v2.field4 + 1)
print(v2:method1())
print(v2.method2())
-print(<!v2:method3!>())
+print(v2:<!method3!>())
local v3 = {}
print(v3.abc)
@@ -880,7 +880,7 @@ function Foo:method1() end
---@type Foo
local v
v:method1()
-<!v:method2!>() -- doc.class.name
+v:<!method2!>() -- doc.class.name
]]
-- checkUndefinedField 通过type找到class,涉及到 class 继承版
@@ -895,7 +895,7 @@ function Bar:method3() end
---@type Bar
local v
v:method1()
-<!v:method2!>() -- doc.class.name
+v:<!method2!>() -- doc.class.name
v:method3()
]]
@@ -904,8 +904,8 @@ TEST [[
---@class Foo
local Foo
function Foo:method1() end
-<!Foo:method2!>() -- doc.class
-<!Foo:method2!>() -- doc.class
+Foo:<!method2!>() -- doc.class
+Foo:<!method2!>() -- doc.class
]]
-- checkUndefinedField 没有@class的不检测
@@ -921,9 +921,9 @@ TEST [[
---@class Foo
local mt
function mt:method1()
- <!mt.method2!>() -- doc.class
+ mt.<!method2!>() -- doc.class
self.method1()
- return <!self.method2!>() -- doc.class.name
+ return self.<!method2!>() -- doc.class.name
end
]]