From 050dcbe14a6e2d6ca267193119b016d1432d121b Mon Sep 17 00:00:00 2001 From: sumneko Date: Thu, 30 May 2019 10:27:14 +0800 Subject: =?UTF-8?q?=E5=8E=BB=E6=8E=89=E5=AF=B9toclose=E7=9A=84=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/core/completion.lua | 39 ++++++--------------------------------- server/src/parser/ast.lua | 40 +++++++++++++++++++++------------------- server/src/parser/grammar.lua | 8 ++++---- server/test/completion/init.lua | 16 ++++++++++------ 4 files changed, 41 insertions(+), 62 deletions(-) diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index 331eb6cc..a938d83c 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -373,19 +373,16 @@ end local function searchAsLocal(vm, source, word, callback) local loc = source:bindLocal() - if loc then - local close = loc:close() - -- 因为闭包的关系落在局部变量finish到close范围内的全局变量一定能访问到该局部变量 - searchCloseGlobal(vm, source.finish, close, word, callback) + if not loc then + return end + local close = loc:close() + -- 因为闭包的关系落在局部变量finish到close范围内的全局变量一定能访问到该局部变量 + searchCloseGlobal(vm, source.finish, close, word, callback) -- 特殊支持 local function if matchKey(word, 'function') then callback('function', nil, CompletionItemKind.Keyword) end - -- 特殊支持 local *toclose - if word == '' and config.config.runtime.version == 'Lua 5.4' then - callback('*toclose', nil, CompletionItemKind.Keyword) - end end local function searchAsArg(vm, source, word, callback) @@ -846,27 +843,6 @@ local function makeList(source, pos, word) end, list end -local function searchToclose(text, source, word, callback) - local pos = source.start - if text:sub(pos-1, pos-1) ~= '*' then - return false - end - if not matchKey(word, 'toclose') then - return false - end - for i = pos-1, 1, -1 do - if text:sub(i, i):match '[^%s%c]' then - if text:sub(i - #'local' + 1, i) == 'local' then - callback('toclose', nil, CompletionItemKind.Keyword) - return true - else - return false - end - end - end - return false -end - local function keywordSource(vm, word, pos) if not KEYMAP[word] then return nil @@ -933,7 +909,7 @@ local function getSource(vm, pos, text, filter) return source, pos, word end pos = findStartPos(pos, text) - source = findSource(vm, pos, filter) + source = findSource(vm, pos, filter) or findSource(vm, pos-1, filter) return source, pos, word end @@ -961,9 +937,6 @@ return function (vm, text, pos, oldText) end State = {} local callback, list = makeList(source, pos, word) - if searchToclose(text, source, word, callback) then - return list - end searchSpecial(vm, source, word, callback, pos, text) searchCallArg(vm, source, word, callback, pos) searchSource(vm, source, word, callback, pos) diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index ac97d512..fac276b8 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -836,29 +836,21 @@ local Defs = { keys, values, } end, - ToClose = function (start) - if State.Version == 'Lua 5.4' then - return { - type = 'toclose', - start = start, - finish = start + #'*toclose' - 1, + Local = function (tag, keys, values) + if tag and State.Version ~= 'Lua 5.4' then + pushError { + type = 'UNSUPPORT_SYMBOL', + start = tag.start, + finish = tag.finish, + version = 'Lua 5.4', + info = { + version = State.Version, + } } end - pushError { - type = 'UNSUPPORT_SYMBOL', - start = start, - finish = start + #'*toclose' - 1, - version = 'Lua 5.4', - info = { - version = State.Version, - } - } - return nil - end, - Local = function (toclose, keys, values) return { type = 'local', - keys, values, toclose + keys, values, tag } end, DoBody = function (...) @@ -1576,6 +1568,16 @@ local Defs = { } } return block + end, + MissGT = function (start) + pushError { + type = 'MISS_SYMBOL', + start = start, + finish = start, + info = { + symbol = '>' + } + } end } diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index 54b03e24..c0025a9c 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -215,8 +215,6 @@ ASSIGN <- Sp '=' Nothing <- {} -> Nothing -TOCLOSE <- Sp ({} '*toclose' Cut) -> ToClose - DirtyBR <- BR {} / {} -> MissBR DirtyTR <- TR {} / {} -> MissTR DirtyPR <- PR {} / {} -> DirtyPR @@ -484,8 +482,10 @@ RepeatBody <- REPEAT BreakEnd NeedUntil DirtyExp -ToClose <- TOCLOSE / %nil -Local <- (LOCAL ToClose NameList (ASSIGN ExpList)?) +LocalTag <- Sp '<' MustName LocalTagEnd + / %nil +LocalTagEnd <- '>' / {} -> MissGT +Local <- (LOCAL LocalTag NameList (ASSIGN ExpList)?) -> Local Set <- (SimpleList ASSIGN ExpList?) -> Set diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index b649e1a8..16928d6c 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -690,21 +690,25 @@ end require 'config' .config.runtime.version = 'Lua 5.4' --TEST [[ ---local *$ +--local $ --]] --{ -- { --- label = 'toclose', +-- label = '', -- kind = CompletionItemKind.Keyword, --- } +-- }, +-- { +-- label = '', +-- kind = CompletionItemKind.Keyword, +-- }, --} - +-- --TEST [[ ---local *tocl$ +--local