diff options
-rw-r--r-- | server/locale/en-US/script.lni | 2 | ||||
-rw-r--r-- | server/locale/zh-CN/script.lni | 2 | ||||
-rw-r--r-- | server/src/method/textDocument/publishDiagnostics.lua | 21 | ||||
-rw-r--r-- | server/src/parser/ast.lua | 9 | ||||
-rw-r--r-- | server/src/parser/grammar.lua | 15 |
5 files changed, 29 insertions, 20 deletions
diff --git a/server/locale/en-US/script.lni b/server/locale/en-US/script.lni index 2ed02fd6..cdd3ffa9 100644 --- a/server/locale/en-US/script.lni +++ b/server/locale/en-US/script.lni @@ -14,6 +14,6 @@ MWS_NOT_COMPLETE = 'Workspace is not complete yet. You may try again later. MWS_COMPLETE = 'Workspace is complete now. You may try again...' PARSER_CRASH = 'Parser crashed! Last words:{}' -PARSER_IN_DEVELOPMENT = 'Syntax check is still in TODO...' +PARSER_UNKNOWN = 'Unknown syntax error...' SYMBOL_ANONYMOUS = '<Anonymous>' diff --git a/server/locale/zh-CN/script.lni b/server/locale/zh-CN/script.lni index fcdfcb12..c0922bac 100644 --- a/server/locale/zh-CN/script.lni +++ b/server/locale/zh-CN/script.lni @@ -14,6 +14,6 @@ MWS_NOT_COMPLETE = '工作目录还没有准备好,你可以稍后再试 MWS_COMPLETE = '工作目录准备好了,你可以再试一下了...' PARSER_CRASH = '语法解析崩溃了!遗言:{}' -PARSER_IN_DEVELOPMENT = '语法检查还在TODO列表里...' +PARSER_UNKNOWN = '未知语法错误...' SYMBOL_ANONYMOUS = '<匿名函数>' diff --git a/server/src/method/textDocument/publishDiagnostics.lua b/server/src/method/textDocument/publishDiagnostics.lua index e5c8b2ff..6e2f437a 100644 --- a/server/src/method/textDocument/publishDiagnostics.lua +++ b/server/src/method/textDocument/publishDiagnostics.lua @@ -79,23 +79,30 @@ end local function buildError(err, lines) local diagnostic = { source = 'Lua Language Server', - message = lang.script.PARSER_IN_DEVELOPMENT, + message = lang.script('PARSER_'..err.type, err.info) } if err.level == 'error' then diagnostic.severity = DiagnosticSeverity.Error else diagnostic.severity = DiagnosticSeverity.Warning end - local row, col = lines:rowcol(err.pos) - local _, max = lines:range(row) + local startrow, startcol = lines:rowcol(err.start) + local endrow, endcol + if err.finish then + endrow, endcol = lines:rowcol(err.finish) + else + endrow = startrow + local _, max = lines:range(endrow) + endcol = max + end local range = { start = { - line = row - 1, - character = col - 1, + line = startrow - 1, + character = startcol - 1, }, ['end'] = { - line = row - 1, - character = max, + line = endrow - 1, + character = endcol, }, } diagnostic.range = range diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index 8c4e1a1c..2096fd28 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -2,6 +2,11 @@ local tonumber = tonumber local string_char = string.char local utf8_char = utf8.char +local Errs +local function pushError(err) + Errs[#Errs+1] = err +end + local defs = { Nil = function (pos) return { @@ -415,12 +420,14 @@ local defs = { } return function (self, lua, mode) + Errs = {} local suc, res, err = pcall(self.grammar, lua, mode, defs) if not suc then return nil, res end if not res then - return nil, {err} + pushError(err) + return nil, Errs end return res end diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index ce7e4794..5ec5b826 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -1,6 +1,5 @@ local re = require 'parser.relabel' local m = require 'lpeglabel' -local calcline = require 'parser.calcline' local scriptBuf = '' @@ -74,14 +73,10 @@ local function grammar(tag) end end -local labels = { - -} - -local function errorpos(lua, pos, err) +local function errorpos(pos, err) return { - lua = lua, - pos = pos, + type = 'UNKNOWN', + start = pos, err = err, level = 'error', } @@ -431,9 +426,9 @@ Lua <- (Sp Action)* -> Lua Sp return function (lua, mode, parser_) parser = parser_ or {} local gram = compiled[mode] or compiled['Lua'] - local r, e, pos = gram:match(lua) + local r, _, pos = gram:match(lua) if not r then - local err = errorpos(lua, pos, e) + local err = errorpos(pos) return nil, err end |