diff options
author | sumneko <sumneko@hotmail.com> | 2019-05-30 10:27:14 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-05-30 10:27:14 +0800 |
commit | 050dcbe14a6e2d6ca267193119b016d1432d121b (patch) | |
tree | 507c51d511c32465e267bf1e7313e40a57582d03 | |
parent | 4005de553a6108cf4eddc45b4c5792154b6209c7 (diff) | |
download | lua-language-server-050dcbe14a6e2d6ca267193119b016d1432d121b.zip |
去掉对toclose的特殊支持
-rw-r--r-- | server/src/core/completion.lua | 39 | ||||
-rw-r--r-- | server/src/parser/ast.lua | 40 | ||||
-rw-r--r-- | server/src/parser/grammar.lua | 8 | ||||
-rw-r--r-- | 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 = '<toclose>', -- kind = CompletionItemKind.Keyword, --- } +-- }, +-- { +-- label = '<const>', +-- kind = CompletionItemKind.Keyword, +-- }, --} - +-- --TEST [[ ---local *tocl$ +--local <toc$ --]] --{ -- { --- label = 'toclose', +-- label = '<toclose>', -- kind = CompletionItemKind.Keyword, -- } --} |