summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-01-04 16:55:03 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-01-04 16:55:03 +0800
commita694873f15841e7138228b92f1fb28d8f4756900 (patch)
treed6800b63bfefb00850f328bc2fd2206e40712480
parent8d4cdc453a89077d7f5ed7ec96f1dacce4bc4f4d (diff)
downloadlua-language-server-a694873f15841e7138228b92f1fb28d8f4756900.zip
fix diagnostic
-rw-r--r--script/provider/diagnostic.lua37
-rw-r--r--script/provider/init.lua1
-rw-r--r--script/workspace/workspace.lua17
-rw-r--r--test/full/projects.lua2
-rw-r--r--test/full/self.lua2
5 files changed, 31 insertions, 28 deletions
diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua
index 0b607bd4..a9132e70 100644
--- a/script/provider/diagnostic.lua
+++ b/script/provider/diagnostic.lua
@@ -13,7 +13,6 @@ local converter = require 'proto.converter'
---@class diagnosticProvider
local m = {}
-m._start = false
m.cache = {}
m.sleepRest = 0.0
m.coroutineUri = setmetatable({}, { __mode = 'k' })
@@ -170,11 +169,7 @@ function m.syntaxErrors(uri, ast)
end
function m.diagnostics(uri, diags)
- if not m._start then
- return
- end
-
- if not ws.isReady() then
+ if not ws.isReady(uri) then
return
end
@@ -272,7 +267,7 @@ function m.doDiagnostic(uri)
end
function m.refresh(uri)
- if not m._start then
+ if not ws.isReady(uri) then
return
end
await.close('diag:' .. uri)
@@ -333,18 +328,12 @@ local function askForDisable()
end
end
-function m.diagnosticsAll(force)
- for _, scp in ipairs(ws.folders) do
- m.diagnosticsScope(scp.uri, force)
- end
-end
-
function m.diagnosticsScope(uri, force)
- if not force and not config.get(uri, 'Lua.diagnostics.enable') then
- m.clearAll()
+ if not ws.isReady(uri) then
return
end
- if not m._start then
+ if not force and not config.get(uri, 'Lua.diagnostics.enable') then
+ m.clearAll()
return
end
local delay = config.get(uri, 'Lua.diagnostics.workspaceDelay') / 1000
@@ -380,16 +369,6 @@ function m.diagnosticsScope(uri, force)
end, 'files.version', 'diagnosticsScope')
end
-function m.start()
- m._start = true
- m.diagnosticsAll()
-end
-
-function m.pause()
- m._start = false
- await.close 'diagnosticsScope'
-end
-
function m.checkStepResult(uri)
if await.hasID 'diagnosticsScope' then
return
@@ -427,6 +406,12 @@ function m.checkWorkspaceDiag(uri)
return false
end
+ws.watch(function (ev, uri)
+ if ev == 'reload' then
+ m.diagnosticsScope(uri)
+ end
+end)
+
files.watch(function (ev, uri) ---@async
if ev == 'remove' then
m.clear(uri)
diff --git a/script/provider/init.lua b/script/provider/init.lua
index a69fbab3..dfba351a 100644
--- a/script/provider/init.lua
+++ b/script/provider/init.lua
@@ -1 +1,2 @@
+require 'provider.diagnostic'
return require 'provider.provider'
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index 92aca131..2ae5f322 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -18,6 +18,21 @@ local m = {}
m.type = 'workspace'
---@type scope[]
m.folders = {}
+m.watchList = {}
+
+--- 注册事件
+---@param callback async fun(ev: string, uri: uri)
+function m.watch(callback)
+ m.watchList[#m.watchList+1] = callback
+end
+
+function m.onWatch(ev, uri)
+ for _, callback in ipairs(m.watchList) do
+ await.call(function ()
+ callback(ev, uri)
+ end)
+ end
+end
function m.initRoot(uri)
m.rootUri = uri
@@ -433,6 +448,8 @@ function m.awaitReload(scp)
waker()
end
end
+
+ m.onWatch('reload', scp.uri)
end
---@param uri uri
diff --git a/test/full/projects.lua b/test/full/projects.lua
index 4a8ef62a..9531d01b 100644
--- a/test/full/projects.lua
+++ b/test/full/projects.lua
@@ -42,7 +42,7 @@ local function doProjects(pathname)
print('开始诊断...')
ws.ready = true
- diag.start()
+ diag.diagnosticsScope(furi.encode(path:string()))
local clock = os.clock()
diff --git a/test/full/self.lua b/test/full/self.lua
index 0c148a91..d0e74a80 100644
--- a/test/full/self.lua
+++ b/test/full/self.lua
@@ -29,7 +29,7 @@ end
print('基准诊断目录:', path)
ws.ready = true
-diag.start()
+diag.diagnosticsScope(furi.encode(path:string()))
local clock = os.clock()