diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-03 19:55:07 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-03 19:55:07 +0800 |
commit | cfcf85156ea3f74e0697421b74cd3f9fdb0f91cf (patch) | |
tree | 4478a463a2fbc38b10f34c9ceb36040a266138d5 /server | |
parent | 5edda40151d5eed6605009346217d1da3bcb9ae6 (diff) | |
download | lua-language-server-cfcf85156ea3f74e0697421b74cd3f9fdb0f91cf.zip |
语法错误的版本
Diffstat (limited to 'server')
-rw-r--r-- | server/src/method/textDocument/codeAction.lua | 46 | ||||
-rw-r--r-- | server/src/method/textDocument/publishDiagnostics.lua | 3 | ||||
-rw-r--r-- | server/src/method/workspace/executeCommand.lua | 2 | ||||
-rw-r--r-- | server/src/service.lua | 4 |
4 files changed, 55 insertions, 0 deletions
diff --git a/server/src/method/textDocument/codeAction.lua b/server/src/method/textDocument/codeAction.lua index c61ad88f..53987d2d 100644 --- a/server/src/method/textDocument/codeAction.lua +++ b/server/src/method/textDocument/codeAction.lua @@ -112,7 +112,53 @@ local function solveAmbiguity1(lsp, uri, data, callback) } end +local function findSyntax(astErr, lines, data) + local start = lines:position(data.range.start.line + 1, data.range.start.character + 1) + local finish = lines:position(data.range['end'].line + 1, data.range['end'].character) + for _, err in ipairs(astErr) do + if err.start == start and err.finish == finish then + return err + end + end + return nil +end + +local function solveSyntax(lsp, uri, data, callback) + local obj = lsp:getFile(uri) + if not obj then + return + end + local astErr, lines = obj.astErr, obj.lines + if not astErr or not lines then + return + end + local err = findSyntax(astErr, lines, data) + if not err then + return nil + end + if err.version then + callback { + title = lang.script.CHANGE_RUNTIME_VERSION, + kind = 'quickfix', + command = { + title = lang.script.COMMAND_RUNTIME_VERSION, + command = 'config', + arguments = { + { + key = {'runtime', 'version'}, + action = 'set', + value = err.version, + } + } + }, + } + end +end + local function solveDiagnostic(lsp, uri, data, callback) + if data.source == lang.script.DIAG_SYNTAX_CHECK then + solveSyntax(lsp, uri, data, callback) + end if not data.code then return end diff --git a/server/src/method/textDocument/publishDiagnostics.lua b/server/src/method/textDocument/publishDiagnostics.lua index 9385c657..ed5ea99d 100644 --- a/server/src/method/textDocument/publishDiagnostics.lua +++ b/server/src/method/textDocument/publishDiagnostics.lua @@ -82,6 +82,9 @@ local function buildError(err, lines, uri) source = lang.script.DIAG_SYNTAX_CHECK, message = lang.script('PARSER_'..err.type, err.info) } + if err.version then + diagnostic.message = ('%s(%s)'):format(diagnostic.message, lang.script('DIAG_NEED_VERSION', err.version)) + end if err.level == 'error' then diagnostic.severity = DiagnosticSeverity.Error else diff --git a/server/src/method/workspace/executeCommand.lua b/server/src/method/workspace/executeCommand.lua index 17f8b2c2..f22590d5 100644 --- a/server/src/method/workspace/executeCommand.lua +++ b/server/src/method/workspace/executeCommand.lua @@ -75,6 +75,8 @@ function command.config(lsp, data) attr[#attr+1] = data.value setting[key] = attr + elseif data.action == 'set' then + setting[key] = data.value end io.save(vscodePath / 'settings.json', json.encode(setting) .. '\r\n') diff --git a/server/src/service.lua b/server/src/service.lua index fdeb926d..6db71442 100644 --- a/server/src/service.lua +++ b/server/src/service.lua @@ -497,6 +497,10 @@ function mt:doDiagnostics(uri) end end +function mt:getFile(uri) + return self._file[uri] +end + function mt:getVM(uri) local obj = self._file[uri] if not obj then |