diff options
-rw-r--r-- | script/core/completion/completion.lua | 4 | ||||
-rw-r--r-- | script/core/definition.lua | 6 | ||||
-rw-r--r-- | script/core/diagnostics/redefined-local.lua | 3 | ||||
-rw-r--r-- | script/core/diagnostics/unused-local.lua | 3 | ||||
-rw-r--r-- | script/core/document-symbol.lua | 5 | ||||
-rw-r--r-- | script/core/highlight.lua | 3 | ||||
-rw-r--r-- | script/core/hint.lua | 3 | ||||
-rw-r--r-- | script/core/hover/args.lua | 2 | ||||
-rw-r--r-- | script/core/reference.lua | 6 | ||||
-rw-r--r-- | script/core/signature.lua | 2 | ||||
-rw-r--r-- | script/core/type-definition.lua | 3 | ||||
-rw-r--r-- | script/core/workspace-symbol.lua | 3 | ||||
-rw-r--r-- | script/parser/guide.lua | 4 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 3 | ||||
-rw-r--r-- | script/parser/newparser.lua | 21 | ||||
-rw-r--r-- | script/vm/compiler.lua | 4 | ||||
-rw-r--r-- | script/vm/def.lua | 17 | ||||
-rw-r--r-- | script/vm/local-id.lua | 1 | ||||
-rw-r--r-- | script/vm/ref.lua | 2 |
19 files changed, 43 insertions, 52 deletions
diff --git a/script/core/completion/completion.lua b/script/core/completion/completion.lua index 33d8fc16..428c8e96 100644 --- a/script/core/completion/completion.lua +++ b/script/core/completion/completion.lua @@ -1724,7 +1724,7 @@ local function tryluaDocByErr(state, position, err, docState, results) local label = {} local insertText = {} for i, arg in ipairs(func.args) do - if arg[1] and not arg.dummy then + if arg[1] and arg.type ~= 'self' then label[#label+1] = arg[1] if #label == 1 then insertText[#insertText+1] = ('%s ${%d:any}'):format(arg[1], #label) @@ -1788,7 +1788,7 @@ local function buildluaDocOfFunction(func) end for n, arg in ipairs(args) do local funcArg = func.args[n] - if funcArg[1] and not funcArg.dummy then + if funcArg[1] and funcArg.type ~= 'self' then index = index + 1 buf[#buf+1] = ('---@param %s ${%d:%s}'):format( funcArg[1], diff --git a/script/core/definition.lua b/script/core/definition.lua index ef183496..b89aa751 100644 --- a/script/core/definition.lua +++ b/script/core/definition.lua @@ -133,13 +133,13 @@ return function (uri, offset) local defs = vm.getDefs(source) for _, src in ipairs(defs) do - if src.dummy then - goto CONTINUE - end local root = guide.getRoot(src) if not root then goto CONTINUE end + if src.type == 'self' then + goto CONTINUE + end src = src.field or src.method or src if src.type == 'getindex' or src.type == 'setindex' diff --git a/script/core/diagnostics/redefined-local.lua b/script/core/diagnostics/redefined-local.lua index 503347d0..2157ae71 100644 --- a/script/core/diagnostics/redefined-local.lua +++ b/script/core/diagnostics/redefined-local.lua @@ -13,9 +13,6 @@ return function (uri, callback) or name == ast.ENVMode then return end - if source.tag == 'self' then - return - end local exist = guide.getLocal(source, name, source.start-1) if exist then callback { diff --git a/script/core/diagnostics/unused-local.lua b/script/core/diagnostics/unused-local.lua index 7e7bd9d7..d12ceb2b 100644 --- a/script/core/diagnostics/unused-local.lua +++ b/script/core/diagnostics/unused-local.lua @@ -88,9 +88,6 @@ return function (uri, callback) or name == ast.ENVMode then return end - if source.tag == 'self' then - return - end if isToBeClosed(source) then return end diff --git a/script/core/document-symbol.lua b/script/core/document-symbol.lua index 33970042..6629ccbc 100644 --- a/script/core/document-symbol.lua +++ b/script/core/document-symbol.lua @@ -33,7 +33,7 @@ local function buildFunctionParams(func) end local params = {} for _, arg in ipairs(func.args) do - if arg.dummy then + if arg.type == 'self' then goto CONTINUE end if arg.type == '...' then @@ -183,9 +183,6 @@ local function buildValue(source, text, symbols) end local function buildSet(source, text, used, symbols) - if source.dummy then - return - end local value = source.value if value and value.type == 'function' then used[value] = true diff --git a/script/core/highlight.lua b/script/core/highlight.lua index 61e759ea..edd8c95d 100644 --- a/script/core/highlight.lua +++ b/script/core/highlight.lua @@ -258,9 +258,6 @@ return function (uri, offset) if not target then return end - if target.dummy then - return - end if mark[target] then return end diff --git a/script/core/hint.lua b/script/core/hint.lua index 51842126..15eff0bf 100644 --- a/script/core/hint.lua +++ b/script/core/hint.lua @@ -22,9 +22,6 @@ local function typeHint(uri, results, start, finish) and source.type ~= 'setindex' then return end - if source.dummy then - return - end if source[1] == '_' then return end diff --git a/script/core/hover/args.lua b/script/core/hover/args.lua index e6c7ce65..a53136b0 100644 --- a/script/core/hover/args.lua +++ b/script/core/hover/args.lua @@ -26,7 +26,7 @@ local function asFunction(source) if source.args then for i = 1, #source.args do local arg = source.args[i] - if arg.dummy then + if arg.type == 'self' then goto CONTINUE end local name = arg.name or guide.getKeyName(arg) diff --git a/script/core/reference.lua b/script/core/reference.lua index c3ce2716..4c9c193d 100644 --- a/script/core/reference.lua +++ b/script/core/reference.lua @@ -69,9 +69,6 @@ return function (uri, position) local results = {} for _, src in ipairs(refs) do - if src.dummy then - goto CONTINUE - end local root = guide.getRoot(src) if not root then goto CONTINUE @@ -79,6 +76,9 @@ return function (uri, position) if not metaSource and vm.isMetaFile(root.uri) then goto CONTINUE end + if src.type == 'self' then + goto CONTINUE + end src = src.field or src.method or src if src.type == 'getindex' or src.type == 'setindex' diff --git a/script/core/signature.lua b/script/core/signature.lua index 1ca10399..505526b6 100644 --- a/script/core/signature.lua +++ b/script/core/signature.lua @@ -87,7 +87,7 @@ local function makeSignatures(text, call, pos) if call.args then local args = {} for _, arg in ipairs(call.args) do - if not arg.dummy then + if arg.type ~= 'self' then args[#args+1] = arg end end diff --git a/script/core/type-definition.lua b/script/core/type-definition.lua index b43f7dfe..e045f9b2 100644 --- a/script/core/type-definition.lua +++ b/script/core/type-definition.lua @@ -134,9 +134,6 @@ return function (uri, offset) local defs = vm.getDefs(source) for _, src in ipairs(defs) do - if src.dummy then - goto CONTINUE - end local root = guide.getRoot(src) if not root then goto CONTINUE diff --git a/script/core/workspace-symbol.lua b/script/core/workspace-symbol.lua index 5fb4a741..9dd768db 100644 --- a/script/core/workspace-symbol.lua +++ b/script/core/workspace-symbol.lua @@ -5,9 +5,6 @@ local define = require 'proto.define' local await = require 'await' local function buildSource(uri, source, key, results) - if source.dummy then - return - end if source.type == 'local' or source.type == 'setlocal' or source.type == 'setglobal' then diff --git a/script/parser/guide.lua b/script/parser/guide.lua index c4b0b1db..c0f33c28 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -21,7 +21,6 @@ local type = type ---@field specials parser.object[] ---@field labels parser.object[] ---@field node parser.object ----@field dummy boolean ---@field field parser.object ---@field method parser.object ---@field index parser.object @@ -833,6 +832,7 @@ end local isSetMap = { ['setglobal'] = true, ['local'] = true, + ['self'] = true, ['setlocal'] = true, ['setfield'] = true, ['setmethod'] = true, @@ -931,6 +931,7 @@ function m.getKeyName(obj) or tp == 'setglobal' then return obj[1] elseif tp == 'local' + or tp == 'self' or tp == 'getlocal' or tp == 'setlocal' then return obj[1] @@ -999,6 +1000,7 @@ function m.getKeyType(obj) or tp == 'setglobal' then return 'string' elseif tp == 'local' + or tp == 'self' or tp == 'getlocal' or tp == 'setlocal' then return 'local' diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index bbfd3ab4..22a2df1b 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -1367,6 +1367,7 @@ local function bindDocsBetween(sources, binded, bindSources, start, finish) end if src.start >= start then if src.type == 'local' + or src.type == 'self' or src.type == 'setglobal' or src.type == 'tablefield' or src.type == 'tableindex' @@ -1437,7 +1438,7 @@ end local bindDocAccept = { 'local' , 'setlocal' , 'setglobal', 'setfield' , 'setmethod' , 'setindex' , - 'tablefield', 'tableindex', + 'tablefield', 'tableindex', 'self' , 'function' , 'table' , '...' , } diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua index 5245b94d..ea4ad2c7 100644 --- a/script/parser/newparser.lua +++ b/script/parser/newparser.lua @@ -1749,15 +1749,15 @@ local function addDummySelf(node, call) parent = call, } end - local newNode = {} - for k, v in next, call.node.node do - newNode[k] = v - end - newNode.mirror = call.node.node - newNode.dummy = true - newNode.parent = call.args - call.node.node.mirror = newNode - tinsert(call.args, 1, newNode) + local self = createLocal { + start = node.colon.start, + finish = node.colon.finish, + method = node, + parent = call.args, + [1] = 'self', + } + self.type = 'self' + tinsert(call.args, 1, self) end local function parseSimple(node, funcName) @@ -2303,10 +2303,9 @@ local function parseFunction(isLocal, isAction) finish = funcRight, method = func.name, parent = params, - tag = 'self', - dummy = true, [1] = 'self', } + params[1].type = 'self' end end if hasLeftParen then diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 531a0cd2..1d79cc1b 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -60,6 +60,7 @@ local searchFieldSwitch = util.switch() end end) : case 'local' + : case 'self' : call(function (suri, node, key, pushResult) local fields if key then @@ -716,7 +717,7 @@ local function compileLocalBase(source) hasMarkDoc = bindDocs(source) end local hasMarkParam - if source.dummy and not hasMarkDoc then + if source.type == 'self' and not hasMarkDoc then hasMarkParam = true vm.setNode(source, vm.compileNode(source.method.node)) end @@ -834,6 +835,7 @@ local compilerSwitch = util.switch() end end) : case 'local' + : case 'self' : call(function (source) local baseNode = compileLocalBase(source) vm.setNode(source, baseNode, true) diff --git a/script/vm/def.lua b/script/vm/def.lua index 78055ddf..40eb7b90 100644 --- a/script/vm/def.lua +++ b/script/vm/def.lua @@ -30,12 +30,19 @@ simpleSwitch = util.switch() end end end - - if source.dummy then - for _, res in ipairs(vm.getDefs(source.method.node)) do - pushResult(res) + end) + : case 'sellf' + : call(function (source, pushResult) + if source.ref then + for _, ref in ipairs(source.ref) do + if ref.type == 'setlocal' then + pushResult(ref) + end end end + for _, res in ipairs(vm.getDefs(source.method.node)) do + pushResult(res) + end end) : case 'getlocal' : case 'setlocal' @@ -209,7 +216,7 @@ function vm.getDefs(source) local hasLocal local function pushResult(src) - if src.type == 'local' and not src.dummy then + if src.type == 'local' then if hasLocal then return end diff --git a/script/vm/local-id.lua b/script/vm/local-id.lua index b7a6e6d5..cda49d23 100644 --- a/script/vm/local-id.lua +++ b/script/vm/local-id.lua @@ -12,6 +12,7 @@ m.ID_SPLITE = '\x1F' local compileSwitch = util.switch() : case 'local' + : case 'self' : call(function (source) source._localID = ('%d'):format(source.start) if not source.ref then diff --git a/script/vm/ref.lua b/script/vm/ref.lua index b086f6e1..65e8fdab 100644 --- a/script/vm/ref.lua +++ b/script/vm/ref.lua @@ -298,7 +298,7 @@ function vm.getRefs(source, fileNotify) local hasLocal local function pushResult(src) - if src.type == 'local' and not src.dummy then + if src.type == 'local' then if hasLocal then return end |