From 2ce73841e83f44212c20bfd997bc1874cda9e3c0 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 13:26:27 +0800 Subject: =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server-beta/src/service/diagnostic.lua | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) (limited to 'server-beta/src/service') diff --git a/server-beta/src/service/diagnostic.lua b/server-beta/src/service/diagnostic.lua index f6b0c1a0..b7d6be02 100644 --- a/server-beta/src/service/diagnostic.lua +++ b/server-beta/src/service/diagnostic.lua @@ -9,6 +9,7 @@ local core = require 'core.diagnostics' local m = {} m.version = 0 +m._start = false local function concat(t, sep) if type(t) ~= 'table' then @@ -35,8 +36,14 @@ local function buildSyntaxError(uri, err) if related then relatedInformation = {} for _, rel in ipairs(related) do + local rmessage + if rel.message then + rmessage = lang.script('PARSER_'..rel.message) + else + rmessage = text:sub(rel.start, rel.finish) + end relatedInformation[#relatedInformation+1] = { - message = lang.script('PARSER_'..rel.message), + message = rmessage, location = define.location(uri, define.range(lines, text, rel.start, rel.finish)), } end @@ -67,7 +74,7 @@ local function buildDiagnostic(uri, diag) } end end - + return { range = define.range(lines, text, diag.start, diag.finish), source = lang.script.DIAG_DIAGNOSTICS, @@ -91,12 +98,13 @@ 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) + if m._start then + local diags = core(uri) + for _, diag in ipairs(diags) do + diagnostics[#diagnostics+1] = buildDiagnostic(uri, diag) + end end - proto.notify('textDocument/publishDiagnostics', { uri = uri, diagnostics = diagnostics, @@ -107,10 +115,13 @@ end function m.refresh(uri) m.version = m.version + 1 local myVersion = m.version + if uri then + m.doDiagnostic(files.getOriginUri(uri)) + end + if not m._start then + return + end await.create(function () - if uri then - m.doDiagnostic(files.getOriginUri(uri)) - end await.sleep(1.0) if myVersion ~= m.version then return @@ -127,4 +138,9 @@ function m.refresh(uri) end) end +function m.start() + m._start = true + m.refresh() +end + return m -- cgit v1.2.3