summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/parser/guide.lua25
-rw-r--r--test/definition/special.lua10
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
+]]