diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-06-30 17:55:25 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-06-30 17:55:25 +0800 |
commit | b7caff0e2668dcad90d4e91c61736202000bc243 (patch) | |
tree | d15c2ea4119446fb212644a49f835a9361a383ba | |
parent | 0922958099d34a2512b238dd5bd66fd96335fe80 (diff) | |
download | lua-language-server-b7caff0e2668dcad90d4e91c61736202000bc243.zip |
resolve #573
-rw-r--r-- | changelog.md | 13 | ||||
-rw-r--r-- | script/core/noder.lua | 8 | ||||
-rw-r--r-- | test/diagnostics/init.lua | 4 |
3 files changed, 23 insertions, 2 deletions
diff --git a/changelog.md b/changelog.md index 857f685f..0d8e61ae 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,19 @@ # changelog ## 2.0.5 +* `CHG` `class field` consider implicit definition + ```lua + ---@class Class + local mt = {} + + function mt:init() + self.xxx = 1 + end + + function mt:func() + print(self.xxx) -- self.xxx is defined + end + ``` * `FIX` [#580](https://github.com/sumneko/lua-language-server/issues/580) ## 2.0.4 diff --git a/script/core/noder.lua b/script/core/noder.lua index 3cfbc84d..b8690ba4 100644 --- a/script/core/noder.lua +++ b/script/core/noder.lua @@ -241,6 +241,14 @@ local function getKey(source) end local function getNodeKey(source) + if source.type == 'getlocal' + or source.type == 'setlocal' then + source = source.node + end + local methodNode = getMethodNode(source) + if methodNode then + return getNodeKey(methodNode) + end local key, node = getKey(source) if guide.isGlobal(source) then return 'g:' .. key, nil diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua index be83ac96..b00a4e21 100644 --- a/test/diagnostics/init.lua +++ b/test/diagnostics/init.lua @@ -868,7 +868,7 @@ local mt2 = {} ---@type Foo local v print(v.field1 + 1) -print(v.<!field2!> + 1) +print(v.field2 + 1) print(v.<!field3!> + 1) print(v:method1()) print(v.method2()) @@ -877,7 +877,7 @@ print(v:<!method3!>()) ---@type Bar local v2 print(v2.field1 + 1) -print(v2.<!field2!> + 1) +print(v2.field2 + 1) print(v2.<!field3!> + 1) print(v2.field4 + 1) print(v2:method1()) |