diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-01-05 15:40:25 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-01-05 15:40:25 +0800 |
commit | 5641c17faaed10409a476558dde8e15f4f91f9cb (patch) | |
tree | 41e4981290a942b2ac6a273a47730f2386246040 | |
parent | d704ebf543af4e9ae2aa115f24193d4d5012ac73 (diff) | |
download | lua-language-server-5641c17faaed10409a476558dde8e15f4f91f9cb.zip |
guess `self`
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | script/parser/guide.lua | 25 | ||||
-rw-r--r-- | test/definition/special.lua | 10 |
3 files changed, 36 insertions, 0 deletions
diff --git a/changelog.md b/changelog.md index 4a290acf..03774edd 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ ## 1.11.0 * `NEW` `Lua.runtime.plugin` +* `NEW` intelli-scense: improved `m.f = function (self) end` from `self` to `m` * `CHG` performance optimization * `CHG` completion: improve performance of workspace words * `FIX` hover: tail comments may be cutted diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 354a5eed..6ba7e903 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -1506,6 +1506,29 @@ function m.checkSameSimpleInSpecialBranch(status, obj, start, pushQueue) end end +function m.checkSameSimpleInParamSelf(status, obj, start, pushQueue) + if obj.type ~= 'getlocal' or obj[1] ~= 'self' then + return + end + local node = obj.node + if node.tag == 'self' then + return + end + if node.parent.type ~= 'funcargs' then + return + end + local func = node.parent.parent + if func.type ~= 'function' or func.parent.type ~= 'setfield' then + return + end + local fieldNode = func.parent.node + local newStatus = m.status(status) + m.searchRefs(newStatus, fieldNode, 'ref') + for _, ref in ipairs(newStatus.results) do + pushQueue(ref, start, true) + end +end + local function appendValidGenericType(results, status, typeName, obj) if typeName.parent.type == 'doc.type.typeliteral' then if obj.type == 'string' and status.interface.docType then @@ -2415,6 +2438,8 @@ function m.checkSameSimple(status, simple, ref, start, force, mode, pushQueue) m.checkSameSimpleInValueOfCallMetaTable(status, ref, i, pushQueue) -- 检查自己是特殊变量的分支的情况 m.checkSameSimpleInSpecialBranch(status, ref, i, pushQueue) + -- self 的特殊处理 + m.checkSameSimpleInParamSelf(status, ref, i, pushQueue) if cmode == 'ref' then -- 检查形如 { a = f } 的情况 m.checkSameSimpleAsTableField(status, ref, i, pushQueue) diff --git a/test/definition/special.lua b/test/definition/special.lua index 4e3728e3..3f0d076a 100644 --- a/test/definition/special.lua +++ b/test/definition/special.lua @@ -124,3 +124,13 @@ end obj:<?x?>() ]] + +TEST [[ +local mt = {} + +mt.<!xx!> = 1 + +mt.yy = function (self) + print(self.<?xx?>) +end +]] |