From 45ba0743c75d0f2b68765db0240f150681808205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 3 Nov 2022 17:20:30 +0800 Subject: support `self` type #1505 --- script/vm/compiler.lua | 23 +++++++++++++++++++++++ script/vm/global.lua | 3 +++ 2 files changed, 26 insertions(+) (limited to 'script/vm') diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index dcd32e77..2e481edf 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -1564,6 +1564,29 @@ local compilerSwitch = util.switch() : call(function (source) vm.setNode(source, source) end) + : case 'doc.type.name' + : call(function (source) + if source[1] == 'self' then + local state = guide.getDocState(source) + if state.type == 'doc.return' + or state.type == 'doc.param' then + local func = state.bindSource + if func.type == 'function' then + local node = guide.getFunctionSelfNode(func) + if node then + vm.setNode(source, vm.compileNode(node)) + return + end + end + elseif state.type == 'doc.field' then + local class = state.class + if class then + vm.setNode(source, vm.compileNode(class)) + return + end + end + end + end) : case 'doc.generic.name' : call(function (source) vm.setNode(source, source) diff --git a/script/vm/global.lua b/script/vm/global.lua index e94f9239..027b096a 100644 --- a/script/vm/global.lua +++ b/script/vm/global.lua @@ -404,6 +404,9 @@ local compilerGlobalSwitch = util.switch() if name == '_' then return end + if name == 'self' then + return + end local type = vm.declareGlobal('type', name, uri) type:addGet(uri, source) source._globalNode = type -- cgit v1.2.3