Skip to content

Commit 3f32e2f

Browse files
committed
use pull diagnostic for diag opened files
1 parent 6185d71 commit 3f32e2f

File tree

2 files changed

+38
-54
lines changed

2 files changed

+38
-54
lines changed

script/provider/diagnostic.lua

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -532,37 +532,19 @@ function m.pullDiagnosticScope(callback)
532532
end
533533
end
534534

535-
---@param uri uri
536-
---@return 'server' | 'client'
537-
function m.getOwner(uri)
538-
-- TODO
539-
do return 'server' end
540-
if PREVIEW then
541-
return 'client'
542-
else
543-
return 'server'
544-
end
545-
end
546-
547535
function m.refreshClient()
548536
log.debug('Refresh client diagnostics')
549537
proto.request('workspace/diagnostic/refresh', json.null)
550538
end
551539

552540
ws.watch(function (ev, uri)
553541
if ev == 'reload' then
554-
if m.getOwner(uri) == 'server' then
555-
m.diagnosticsScope(uri)
556-
else
557-
m.refreshClient()
558-
end
542+
m.diagnosticsScope(uri)
543+
m.refreshClient()
559544
end
560545
end)
561546

562547
files.watch(function (ev, uri) ---@async
563-
if m.getOwner(uri) == 'client' then
564-
return
565-
end
566548
if ev == 'remove' then
567549
m.clear(uri)
568550
m.refresh(uri)
@@ -584,23 +566,17 @@ end)
584566
config.watch(function (uri, key, value, oldValue)
585567
if key:find 'Lua.diagnostics' then
586568
if value ~= oldValue then
587-
if m.getOwner(uri) == 'server' then
588-
m.diagnosticsScope(uri)
589-
else
590-
m.refreshClient()
591-
end
569+
m.diagnosticsScope(uri)
570+
m.refreshClient()
592571
end
593572
end
594573
end)
595574

596575
fw.event(function (ev, path)
597576
if util.stringEndWith(path, '.editorconfig') then
598577
for _, scp in ipairs(ws.folders) do
599-
if m.getOwner(scp.uri) == 'server' then
600-
m.diagnosticsScope(scp.uri)
601-
else
602-
m.refreshClient()
603-
end
578+
m.diagnosticsScope(scp.uri)
579+
m.refreshClient()
604580
end
605581
end
606582
end)

script/provider/provider.lua

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,35 +1213,43 @@ m.register 'inlayHint/resolve' {
12131213
}
12141214

12151215
m.register 'textDocument/diagnostic' {
1216-
--preview = true,
1217-
--capability = {
1218-
-- diagnosticProvider = {
1219-
-- identifier = 'identifier',
1220-
-- interFileDependencies = true,
1221-
-- workspaceDiagnostics = false,
1222-
-- }
1223-
--},
1216+
preview = true,
1217+
capability = {
1218+
diagnosticProvider = {
1219+
identifier = 'identifier',
1220+
interFileDependencies = true,
1221+
workspaceDiagnostics = false,
1222+
}
1223+
},
12241224
---@async
12251225
function (params)
12261226
local uri = files.getRealUri(params.textDocument.uri)
12271227
workspace.awaitReady(uri)
12281228
local core = require 'provider.diagnostic'
1229-
if not params.previousResultId then
1230-
core.clearCache(uri)
1231-
end
1232-
local results, unchanged = core.pullDiagnostic(uri, false)
1233-
if unchanged then
1234-
return {
1235-
kind = 'unchanged',
1236-
resultId = uri,
1237-
}
1238-
else
1239-
return {
1240-
kind = 'full',
1241-
resultId = uri,
1242-
items = results or {},
1243-
}
1244-
end
1229+
-- TODO: do some trick
1230+
core.refresh(uri)
1231+
1232+
return {
1233+
kind = 'unchanged',
1234+
resultId = uri,
1235+
}
1236+
1237+
--if not params.previousResultId then
1238+
-- core.clearCache(uri)
1239+
--end
1240+
--local results, unchanged = core.pullDiagnostic(uri, false)
1241+
--if unchanged then
1242+
-- return {
1243+
-- kind = 'unchanged',
1244+
-- resultId = uri,
1245+
-- }
1246+
--else
1247+
-- return {
1248+
-- kind = 'full',
1249+
-- resultId = uri,
1250+
-- items = results or {},
1251+
-- }
1252+
--end
12451253
end
12461254
}
12471255

0 commit comments

Comments
 (0)