Skip to content

Commit 5641c17

Browse files
committed
guess self
1 parent d704ebf commit 5641c17

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 1.11.0
44
* `NEW` `Lua.runtime.plugin`
5+
* `NEW` intelli-scense: improved `m.f = function (self) end` from `self` to `m`
56
* `CHG` performance optimization
67
* `CHG` completion: improve performance of workspace words
78
* `FIX` hover: tail comments may be cutted

script/parser/guide.lua

+25
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,29 @@ function m.checkSameSimpleInSpecialBranch(status, obj, start, pushQueue)
15061506
end
15071507
end
15081508

1509+
function m.checkSameSimpleInParamSelf(status, obj, start, pushQueue)
1510+
if obj.type ~= 'getlocal' or obj[1] ~= 'self' then
1511+
return
1512+
end
1513+
local node = obj.node
1514+
if node.tag == 'self' then
1515+
return
1516+
end
1517+
if node.parent.type ~= 'funcargs' then
1518+
return
1519+
end
1520+
local func = node.parent.parent
1521+
if func.type ~= 'function' or func.parent.type ~= 'setfield' then
1522+
return
1523+
end
1524+
local fieldNode = func.parent.node
1525+
local newStatus = m.status(status)
1526+
m.searchRefs(newStatus, fieldNode, 'ref')
1527+
for _, ref in ipairs(newStatus.results) do
1528+
pushQueue(ref, start, true)
1529+
end
1530+
end
1531+
15091532
local function appendValidGenericType(results, status, typeName, obj)
15101533
if typeName.parent.type == 'doc.type.typeliteral' then
15111534
if obj.type == 'string' and status.interface.docType then
@@ -2415,6 +2438,8 @@ function m.checkSameSimple(status, simple, ref, start, force, mode, pushQueue)
24152438
m.checkSameSimpleInValueOfCallMetaTable(status, ref, i, pushQueue)
24162439
-- 检查自己是特殊变量的分支的情况
24172440
m.checkSameSimpleInSpecialBranch(status, ref, i, pushQueue)
2441+
-- self 的特殊处理
2442+
m.checkSameSimpleInParamSelf(status, ref, i, pushQueue)
24182443
if cmode == 'ref' then
24192444
-- 检查形如 { a = f } 的情况
24202445
m.checkSameSimpleAsTableField(status, ref, i, pushQueue)

test/definition/special.lua

+10
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,13 @@ end
124124
125125
obj:<?x?>()
126126
]]
127+
128+
TEST [[
129+
local mt = {}
130+
131+
mt.<!xx!> = 1
132+
133+
mt.yy = function (self)
134+
print(self.<?xx?>)
135+
end
136+
]]

0 commit comments

Comments
 (0)