From 444851fc1adb2fe3a0f952807cb4b644e18790c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 8 Nov 2019 11:44:04 +0800 Subject: =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=B8=80=E4=BA=9Bbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server-beta/src/service/diagnostic.lua | 45 +++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 4 deletions(-) (limited to 'server-beta/src/service') 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 -- cgit v1.2.3