diff options
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | locale/en-us/script.lua | 4 | ||||
-rw-r--r-- | locale/pt-br/script.lua | 4 | ||||
-rw-r--r-- | locale/zh-cn/script.lua | 8 | ||||
-rw-r--r-- | locale/zh-tw/script.lua | 4 | ||||
-rw-r--r-- | script/parser/compile.lua | 109 |
6 files changed, 63 insertions, 67 deletions
diff --git a/changelog.md b/changelog.md index 64c78f80..b0632a91 100644 --- a/changelog.md +++ b/changelog.md @@ -7,6 +7,7 @@ * `FIX` [#1476](https://github.com/sumneko/lua-language-server/issues/1476) * `FIX` [#1493](https://github.com/sumneko/lua-language-server/issues/1493) * `FIX` [#1499](https://github.com/sumneko/lua-language-server/issues/1499) +* `FIX` [#1526](https://github.com/sumneko/lua-language-server/issues/1526) ## 3.5.3 `2022-8-13` diff --git a/locale/en-us/script.lua b/locale/en-us/script.lua index 9135644b..ca17cdf0 100644 --- a/locale/en-us/script.lua +++ b/locale/en-us/script.lua @@ -271,6 +271,8 @@ PARSER_UNKNOWN_ATTRIBUTE = 'Local attribute should be `const` or `close`' PARSER_AMBIGUOUS_SYNTAX = -- TODO: need translate! 'In Lua 5.1, the left brackets called by the function must be in the same line as the function.' +PARSER_NEED_PAREN = -- TODO: need translate! +'Need to add a pair of parentheses.' PARSER_LUADOC_MISS_CLASS_NAME = '<class name> expected.' PARSER_LUADOC_MISS_EXTENDS_SYMBOL = @@ -416,6 +418,8 @@ ACTION_MARK_ASYNC = 'Mark current function as async.' ACTION_ADD_DICT = 'Add \'{}\' to workspace dict' +ACTION_FIX_ADD_PAREN = -- TODO: need translate! +'Add parentheses.' COMMAND_DISABLE_DIAG = 'Disable diagnostics' diff --git a/locale/pt-br/script.lua b/locale/pt-br/script.lua index d1ae41b8..e93ff85f 100644 --- a/locale/pt-br/script.lua +++ b/locale/pt-br/script.lua @@ -271,6 +271,8 @@ PARSER_UNKNOWN_ATTRIBUTE = 'Atributo local deve ser `const` ou `close`' PARSER_AMBIGUOUS_SYNTAX = -- TODO: need translate! 'In Lua 5.1, the left brackets called by the function must be in the same line as the function.' +PARSER_NEED_PAREN = -- TODO: need translate! +'需要添加一对括号。' PARSER_LUADOC_MISS_CLASS_NAME = 'Esperado <class name>.' PARSER_LUADOC_MISS_EXTENDS_SYMBOL = @@ -416,6 +418,8 @@ ACTION_MARK_ASYNC = 'Marque a função atual como assíncrona' ACTION_ADD_DICT = 'Adicione \'{}\' ao seu espaço de trabalho no ' +ACTION_FIX_ADD_PAREN = -- TODO: need translate! +'添加括号。' COMMAND_DISABLE_DIAG = 'Desativar diagnósticos.' diff --git a/locale/zh-cn/script.lua b/locale/zh-cn/script.lua index 775400ec..04d5e115 100644 --- a/locale/zh-cn/script.lua +++ b/locale/zh-cn/script.lua @@ -271,6 +271,8 @@ PARSER_UNKNOWN_ATTRIBUTE = '局部变量属性应该是 `const` 或 `close`' PARSER_AMBIGUOUS_SYNTAX = '在 Lua 5.1 中,函数调用的左括号必须与函数在同一行。' +PARSER_NEED_PAREN = +'需要添加一对括号。' PARSER_LUADOC_MISS_CLASS_NAME = '缺少类名称。' PARSER_LUADOC_MISS_EXTENDS_SYMBOL = @@ -414,8 +416,10 @@ ACTION_DISABLE_DIAG_FILE= '在此文件禁用诊断 ({})。' ACTION_MARK_ASYNC = '将当前函数标记为异步。' -ACTION_ADD_DICT = -- TODO: need translate! -'Add \'{}\' to workspace dict' +ACTION_ADD_DICT = +'将 \'{}\' 添加到工作区的词典中。' +ACTION_FIX_ADD_PAREN = +'添加括号。' COMMAND_DISABLE_DIAG = '禁用诊断' diff --git a/locale/zh-tw/script.lua b/locale/zh-tw/script.lua index e234f5ae..8f03d7ca 100644 --- a/locale/zh-tw/script.lua +++ b/locale/zh-tw/script.lua @@ -271,6 +271,8 @@ PARSER_UNKNOWN_ATTRIBUTE = '區域變數屬性應該是 `const` 或 `close` 。' PARSER_AMBIGUOUS_SYNTAX = -- TODO: need translate! '在 Lua 5.1 中,函数调用的左括号必须与函数在同一行。' +PARSER_NEED_PAREN = -- TODO: need translate! +'需要添加一对括号。' PARSER_LUADOC_MISS_CLASS_NAME = '缺少類別名稱。' PARSER_LUADOC_MISS_EXTENDS_SYMBOL = @@ -416,6 +418,8 @@ ACTION_MARK_ASYNC = '將目前函式標記為非同步。' ACTION_ADD_DICT = '添加 \'{}\' 到工作區字典' +ACTION_FIX_ADD_PAREN = -- TODO: need translate! +'添加括号。' COMMAND_DISABLE_DIAG = '停用診斷' diff --git a/script/parser/compile.lua b/script/parser/compile.lua index 33ac4d69..9724a74f 100644 --- a/script/parser/compile.lua +++ b/script/parser/compile.lua @@ -1444,68 +1444,6 @@ local function parseNameOrList(parent) return list or first end -local function dropTail() - local token = Tokens[Index + 1] - if token ~= '?' - and token ~= ':' then - return - end - local pl, pt, pp = 0, 0, 0 - while true do - local token = Tokens[Index + 1] - if not token then - break - end - if NLMap[token] then - break - end - if token == ',' then - if pl > 0 - or pt > 0 - or pp > 0 then - goto CONTINUE - else - break - end - end - if token == '<' then - pl = pl + 1 - goto CONTINUE - end - if token == '{' then - pt = pt + 1 - goto CONTINUE - end - if token == '(' then - pp = pp + 1 - goto CONTINUE - end - if token == '>' then - if pl <= 0 then - break - end - pl = pl - 1 - goto CONTINUE - end - if token == '}' then - if pt <= 0 then - break - end - pt = pt - 1 - goto CONTINUE - end - if token == ')' then - if pp <= 0 then - break - end - pp = pp - 1 - goto CONTINUE - end - ::CONTINUE:: - Index = Index + 2 - end -end - local function parseExpList(mini) local list local wantSep = false @@ -1552,7 +1490,6 @@ local function parseExpList(mini) if not exp then break end - dropTail() if wantSep then missSymbol(',', list[#list].finish, exp.start) end @@ -2379,6 +2316,27 @@ local function parseFunction(isLocal, isAction) return func end +local function pushErrorNeedParen(source) + pushError { + type = 'NEED_PAREN', + start = source.start, + finish = source.finish, + fix = { + title = 'FIX_ADD_PAREN', + { + start = source.start, + finish = source.start, + text = '(', + }, + { + start = source.finish, + finish = source.finish, + text = ')', + } + } + } +end + local function parseExpUnit() local token = Tokens[Index + 1] if token == '(' then @@ -2393,17 +2351,38 @@ local function parseExpUnit() if token == '{' then local table = parseTable() + if not table then + return nil + end + local exp = parseSimple(table, false) + if exp ~= table then + pushErrorNeedParen(table) + end return table end if CharMapStrSH[token] then local string = parseShortString() - return string + if not string then + return nil + end + local exp = parseSimple(string, false) + if exp ~= string then + pushErrorNeedParen(string) + end + return exp end if CharMapStrLH[token] then local string = parseLongString() - return string + if not string then + return nil + end + local exp = parseSimple(string, false) + if exp ~= string then + pushErrorNeedParen(string) + end + return exp end local number = parseNumber() |