diff options
-rw-r--r-- | server/src/method/textDocument/completion.lua | 2 | ||||
-rw-r--r-- | server/src/method/textDocument/publishDiagnostics.lua | 22 | ||||
-rw-r--r-- | server/src/parser/grammar.lua | 6 | ||||
-rw-r--r-- | server/src/service.lua | 14 |
4 files changed, 33 insertions, 11 deletions
diff --git a/server/src/method/textDocument/completion.lua b/server/src/method/textDocument/completion.lua index 3a8a2e6b..81ef1446 100644 --- a/server/src/method/textDocument/completion.lua +++ b/server/src/method/textDocument/completion.lua @@ -23,7 +23,6 @@ return function (lsp, params) end -- lua是从1开始的,因此都要+1 local position = lines:position(params.position.line + 1, params.position.character + 1) - log.debug(table.dump(params.position)) local items = matcher.completion(vm, position) if not items then return nil @@ -43,6 +42,5 @@ return function (lsp, params) isIncomplete = true, items = items, } - log.debug(table.dump(response)) return response end diff --git a/server/src/method/textDocument/publishDiagnostics.lua b/server/src/method/textDocument/publishDiagnostics.lua index 5f71d475..1186374d 100644 --- a/server/src/method/textDocument/publishDiagnostics.lua +++ b/server/src/method/textDocument/publishDiagnostics.lua @@ -75,10 +75,27 @@ local function createInfo(data, lines) return diagnostic end +local function buildError(err, lines) + local diagnostic = { + source = 'Lua Language Server', + message = 'Error', + } + if err.level == 'error' then + diagnostic.severity = DiagnosticSeverity.Error + else + diagnostic.severity = DiagnosticSeverity.Warning + end + local range = getRange(err.pos, err.pos, lines) + range['end'].character = 9999 + diagnostic.range = range + return diagnostic +end + return function (lsp, params) local vm = params.vm local lines = params.lines local uri = params.uri + local errs = lsp:getAstErrors(uri) local diagnostics = {} if vm then @@ -87,6 +104,11 @@ return function (lsp, params) diagnostics[#diagnostics+1] = createInfo(data, lines) end end + if errs then + for _, err in ipairs(errs) do + diagnostics[#diagnostics+1] = buildError(err, lines) + end + end return diagnostics end diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index a125bfe4..d21f07b9 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -79,14 +79,10 @@ local labels = { } local function errorpos(lua, pos, err) - local row, col = calcline.rowcol(lua, pos) - local str = calcline.line(lua, row) return { lua = lua, - line = row, - pos = col, + pos = pos, err = err, - code = str, level = 'error', } end diff --git a/server/src/service.lua b/server/src/service.lua index b8546665..ae6b6714 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -98,7 +98,7 @@ function mt:_doDiagnostic() end for uri in pairs(copy) do local obj = self._file[uri] - if obj and obj.vm then + if obj then local data = { uri = uri, vm = obj.vm, @@ -273,7 +273,7 @@ end function mt:compileAst(obj) local ast, err = parser:ast(obj.text) - obj.astErr = nil + obj.astErr = err if not ast then if type(err) == 'string' then local message = lang.script('PARSER_CRASH', err) @@ -282,8 +282,6 @@ function mt:compileAst(obj) type = 3, message = lang.script('PARSER_CRASH', err:match 'grammar%.lua%:%d+%:(.+)'), }) - else - obj.astErr = err end end return ast @@ -351,6 +349,14 @@ function mt:getVM(uri) return obj.vm end +function mt:getAstErrors(uri) + local obj = self._file[uri] + if not obj then + return nil + end + return obj.astErr +end + function mt:compileChain(child, parent) local parentObj = self._file[parent] local childObj = self._file[child] |