@@ -15,6 +15,7 @@ local scope = require 'workspace.scope'
15
15
local time = require ' bee.time'
16
16
local ltable = require ' linked-table'
17
17
local furi = require ' file-uri'
18
+ local json = require ' json'
18
19
19
20
--- @class diagnosticProvider
20
21
local m = {}
@@ -194,33 +195,43 @@ local function copyDiagsWithoutSyntax(diags)
194
195
end
195
196
196
197
--- @async
197
- function m .doDiagnostic (uri , isScopeDiag )
198
+ --- @param uri uri
199
+ --- @return boolean
200
+ local function isValid (uri )
198
201
if not config .get (uri , ' Lua.diagnostics.enable' ) then
199
- return
202
+ return false
200
203
end
201
204
if files .isLibrary (uri , true ) then
202
205
local status = config .get (uri , ' Lua.diagnostics.libraryFiles' )
203
206
if status == ' Disable' then
204
- return
207
+ return false
205
208
elseif status == ' Opened' then
206
209
if not files .isOpen (uri ) then
207
- return
210
+ return false
208
211
end
209
212
end
210
213
end
211
214
if ws .isIgnored (uri ) then
212
215
local status = config .get (uri , ' Lua.diagnostics.ignoredFiles' )
213
216
if status == ' Disable' then
214
- return
217
+ return false
215
218
elseif status == ' Opened' then
216
219
if not files .isOpen (uri ) then
217
- return
220
+ return false
218
221
end
219
222
end
220
223
end
221
224
local scheme = furi .split (uri )
222
225
local disableScheme = config .get (uri , ' Lua.diagnostics.disableScheme' )
223
226
if disableScheme [scheme ] then
227
+ return false
228
+ end
229
+ return true
230
+ end
231
+
232
+ --- @async
233
+ function m .doDiagnostic (uri , isScopeDiag )
234
+ if not isValid (uri ) then
224
235
return
225
236
end
226
237
@@ -293,6 +304,41 @@ function m.doDiagnostic(uri, isScopeDiag)
293
304
pushResult ()
294
305
end
295
306
307
+ --- @async
308
+ --- @return table | nil result
309
+ --- @return boolean ? unchanged
310
+ function m .pullDiagnostic (uri , isScopeDiag )
311
+ if not isValid (uri ) then
312
+ return nil
313
+ end
314
+
315
+ await .delay ()
316
+
317
+ local state = files .getState (uri )
318
+ if not state then
319
+ return nil
320
+ end
321
+
322
+ local prog <close> = progress .create (uri , lang .script .WINDOW_DIAGNOSING , 0.5 )
323
+ prog :setMessage (ws .getRelativePath (uri ))
324
+
325
+ local syntax = m .syntaxErrors (uri , state )
326
+ local diags = {}
327
+
328
+ xpcall (core , log .error , uri , isScopeDiag , function (result )
329
+ diags [# diags + 1 ] = buildDiagnostic (uri , result )
330
+ end )
331
+
332
+ local full = mergeDiags (syntax , diags )
333
+ if util .equal (m .cache [uri ], full ) then
334
+ return full , true
335
+ end
336
+
337
+ m .cache [uri ] = full
338
+
339
+ return full
340
+ end
341
+
296
342
function m .refresh (uri )
297
343
if not ws .isReady (uri ) then
298
344
return
@@ -426,13 +472,27 @@ function m.diagnosticsScope(uri, force)
426
472
end , id )
427
473
end
428
474
475
+ --- @param uri uri
476
+ --- @return ' server' | ' client'
477
+ function m .getOwner (uri )
478
+ -- TODO
479
+ return ' client'
480
+ end
481
+
429
482
ws .watch (function (ev , uri )
430
483
if ev == ' reload' then
431
- m .diagnosticsScope (uri )
484
+ if m .getOwner (uri ) == ' server' then
485
+ m .diagnosticsScope (uri )
486
+ else
487
+ proto .request (' workspace/diagnostic/refresh' , json .null )
488
+ end
432
489
end
433
490
end )
434
491
435
492
files .watch (function (ev , uri ) --- @async
493
+ if m .getOwner (uri ) == ' client' then
494
+ return
495
+ end
436
496
if ev == ' remove' then
437
497
m .clear (uri )
438
498
m .refresh (uri )
@@ -454,7 +514,11 @@ end)
454
514
config .watch (function (uri , key , value , oldValue )
455
515
if key :find ' Lua.diagnostics' then
456
516
if value ~= oldValue then
457
- m .diagnosticsScope (uri )
517
+ if m .getOwner (uri ) == ' server' then
518
+ m .diagnosticsScope (uri )
519
+ else
520
+ proto .request (' workspace/diagnostic/refresh' , json .null )
521
+ end
458
522
end
459
523
end
460
524
end )
0 commit comments