summaryrefslogtreecommitdiff
path: root/server-beta/src/service
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-08 11:44:04 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-08 11:44:04 +0800
commit444851fc1adb2fe3a0f952807cb4b644e18790c1 (patch)
tree722586a59027734fbba91678e51d82061c3a923b /server-beta/src/service
parentd2b9dee8ce0ae345e4efd43c112bb3efd4071888 (diff)
downloadlua-language-server-444851fc1adb2fe3a0f952807cb4b644e18790c1.zip
修正一些bug
Diffstat (limited to 'server-beta/src/service')
-rw-r--r--server-beta/src/service/diagnostic.lua45
1 files changed, 41 insertions, 4 deletions
diff --git a/server-beta/src/service/diagnostic.lua b/server-beta/src/service/diagnostic.lua
index 6fd212a9..f6b0c1a0 100644
--- a/server-beta/src/service/diagnostic.lua
+++ b/server-beta/src/service/diagnostic.lua
@@ -4,6 +4,7 @@ local define = require 'proto.define'
local lang = require 'language'
local files = require 'files'
local config = require 'config'
+local core = require 'core.diagnostics'
local m = {}
@@ -29,11 +30,11 @@ local function buildSyntaxError(uri, err)
))
end
- local relative = err.info and err.info.relative
+ local related = err.info and err.info.related
local relatedInformation
- if relative then
+ if related then
relatedInformation = {}
- for _, rel in ipairs(relative) do
+ for _, rel in ipairs(related) do
relatedInformation[#relatedInformation+1] = {
message = lang.script('PARSER_'..rel.message),
location = define.location(uri, define.range(lines, text, rel.start, rel.finish)),
@@ -50,6 +51,34 @@ local function buildSyntaxError(uri, err)
}
end
+local function buildDiagnostic(uri, diag)
+ local lines = files.getLines(uri)
+ local text = files.getText(uri)
+
+ local relatedInformation
+ if diag.related then
+ relatedInformation = {}
+ for _, rel in ipairs(diag.related) do
+ local rtext = files.getText(rel.uri)
+ local rlines = files.getLines(rel.uri)
+ relatedInformation[#relatedInformation+1] = {
+ message = rel.message or rtext:sub(rel.start, rel.finish),
+ location = define.location(rel.uri, define.range(rlines, rtext, rel.start, rel.finish))
+ }
+ end
+ end
+
+ return {
+ range = define.range(lines, text, diag.start, diag.finish),
+ source = lang.script.DIAG_DIAGNOSTICS,
+ severity = diag.level,
+ message = diag.message,
+ code = diag.code,
+ tags = diag.tags,
+ relatedInformation = relatedInformation,
+ }
+end
+
function m.doDiagnostic(uri)
local ast = files.getAst(uri)
if not ast then
@@ -62,6 +91,12 @@ function m.doDiagnostic(uri)
diagnostics[#diagnostics+1] = buildSyntaxError(uri, err)
end
+ local diags = core(uri)
+ for _, diag in ipairs(diags) do
+ diagnostics[#diagnostics+1] = buildDiagnostic(uri, diag)
+ end
+
+
proto.notify('textDocument/publishDiagnostics', {
uri = uri,
diagnostics = diagnostics,
@@ -73,7 +108,9 @@ function m.refresh(uri)
m.version = m.version + 1
local myVersion = m.version
await.create(function ()
- m.doDiagnostic(files.getOriginUri(uri))
+ if uri then
+ m.doDiagnostic(files.getOriginUri(uri))
+ end
await.sleep(1.0)
if myVersion ~= m.version then
return