diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-31 11:11:59 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-31 11:11:59 +0800 |
commit | bf8399c9057927d6746b47915a7b79c62d1082bd (patch) | |
tree | 08b6258daddc8307e98308128e404d4b9b29bb33 | |
parent | 0245eb9245d7ff8509822f5b505d542b925b6c7e (diff) | |
download | lua-language-server-bf8399c9057927d6746b47915a7b79c62d1082bd.zip |
更新语法检查
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | server/src/method/textDocument/publishDiagnostics.lua | 7 | ||||
-rw-r--r-- | server/src/parser/ast.lua | 59 | ||||
-rw-r--r-- | server/src/parser/grammar.lua | 12 |
4 files changed, 67 insertions, 13 deletions
@@ -15,7 +15,7 @@ - [x] Intelligent - [x] Signature Help - [x] Document Symbols -- [ ] Support Dirty Script +- [x] Support Dirty Script - [ ] Syntax Check - [ ] Multi Workspace - [ ] Type Format diff --git a/server/src/method/textDocument/publishDiagnostics.lua b/server/src/method/textDocument/publishDiagnostics.lua index 6e2f437a..c0d86845 100644 --- a/server/src/method/textDocument/publishDiagnostics.lua +++ b/server/src/method/textDocument/publishDiagnostics.lua @@ -87,11 +87,8 @@ local function buildError(err, lines) diagnostic.severity = DiagnosticSeverity.Warning end local startrow, startcol = lines:rowcol(err.start) - local endrow, endcol - if err.finish then - endrow, endcol = lines:rowcol(err.finish) - else - endrow = startrow + local endrow, endcol = lines:rowcol(err.finish) + if err.type == 'UNKNOWN' then local _, max = lines:range(endrow) endcol = max end diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index de305ca3..6a26f46b 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -1,9 +1,13 @@ local tonumber = tonumber local string_char = string.char local utf8_char = utf8.char +local type = type local Errs local function pushError(err) + if err.finish < err.start then + err.finish = err.start + end local last = Errs[#Errs] if last then if last.start <= err.start and last.finish >= err.finish then @@ -290,6 +294,59 @@ local defs = { return first end end, + ExpList = function (start, ...) + local args = {...} + local max = #args + local finish = args[max] - 1 + local exps = { + type = 'list', + start = start, + finish = finish, + } + local wantExp = true + for i = 1, max-1 do + local arg = args[i] + local isExp = type(arg) == 'table' + if wantExp and not isExp then + pushError { + type = 'MISS_EXP', + start = start, + finish = arg - 1, + } + elseif not wantExp and isExp then + pushError { + type = 'MISS_SYMBOL', + start = start, + finish = arg.start-1, + info = { + symbol = ',', + } + } + end + if isExp then + exps[#exps+1] = arg + wantExp = false + start = arg.finish + 1 + else + wantExp = true + start = arg + end + end + if wantExp then + pushError { + type = 'MISS_EXP', + start = start, + finish = finish, + } + end + if #exps == 0 then + return nil + elseif #exps == 1 then + return exps[1] + else + return exps + end + end, Nothing = function () return nil end, @@ -577,7 +634,7 @@ local defs = { pushError { type = 'MUST_X16', start = pos, - finish = math.max(pos + #str - 1, pos), + finish = pos + #str - 1, } end, MissAssign = function (pos) diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index bee5d8e1..a840a7a0 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -75,6 +75,7 @@ local function errorpos(pos, err) return { type = 'UNKNOWN', start = pos, + finish = pos, err = err, } end @@ -193,7 +194,7 @@ TOCLOSE <- Sp '*toclose' DirtyAssign <- ASSIGN / {} -> MissAssign DirtyBR <- BR / {} -> MissBR DirtyTR <- TR / {} -> MissTR -DirtyPR <- TR / {} -> MissPR +DirtyPR <- PR / {} -> MissPR ]] grammar 'Nil' [[ @@ -288,14 +289,13 @@ Suffix <- DOT MustName / Sp ({} Table {}) -> Call / Sp ({} String {}) -> Call / Sp ({} BL DirtyExp (BR / Sp) {}) -> Index - / Sp ({} PL ExpList (PR / Sp) {}) -> Call + / Sp ({} PL ExpList DirtyPR {}) -> Call DirtyExp <- Exp / {} -> DirtyExp -ExpList <- (COMMA DirtyExp)+ - -> List - / (Exp (COMMA DirtyExp)*)? - -> List +ExpList <- Sp ({} (!%nl (COMMA {} / Exp))+ {}) + -> ExpList + / %nil NameList <- (COMMA MustName)+ -> List / (Name (COMMA MustName)*) |