summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-27 18:10:33 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-27 18:10:33 +0800
commitffbff19e45c6f41fd6dba9f0baec0eda45b6f05b (patch)
treeed052b43461ab1ab386257a6548d343baa635147
parent9474261f54ae620a853856f9adce0083ce66dec7 (diff)
downloadlua-language-server-ffbff19e45c6f41fd6dba9f0baec0eda45b6f05b.zip
显示错误
-rw-r--r--server/src/method/textDocument/completion.lua2
-rw-r--r--server/src/method/textDocument/publishDiagnostics.lua22
-rw-r--r--server/src/parser/grammar.lua6
-rw-r--r--server/src/service.lua14
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]