Skip to content

Commit 4e647a3

Browse files
committed
new setting Lua.diagnostics.workspaceEvent
set the time to trigger workspace diagnostics. resolve #1626
1 parent 279c1ad commit 4e647a3

File tree

8 files changed

+86
-14
lines changed

8 files changed

+86
-14
lines changed

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## 3.6.0
44
* `NEW` settings:
55
* `Lua.misc.executablePath`: [#1557] specify the executable path in VSCode
6+
* `Lua.diagnostics.workspaceEvent`: [#1626] set the time to trigger workspace diagnostics.
67
* `NEW` CLI `--doc [path]` to make docs.
78
server will generate `doc.json` and `doc.md` in `LOGPATH`.
89
`doc.md` is generated by `doc.json` by example code `script/cli/doc2md.lua`.
@@ -54,6 +55,7 @@ server will generate `doc.json` and `doc.md` in `LOGPATH`.
5455
[#1599]: https://github.com/sumneko/lua-language-server/issues/1599
5556
[#1606]: https://github.com/sumneko/lua-language-server/issues/1606
5657
[#1608]: https://github.com/sumneko/lua-language-server/issues/1608
58+
[#1626]: https://github.com/sumneko/lua-language-server/issues/1626
5759
[#1637]: https://github.com/sumneko/lua-language-server/issues/1637
5860

5961
## 3.5.6

locale/en-us/setting.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,16 @@ Modify the diagnostic needed file status in a group.
7777
`Fallback` means that diagnostics in this group are controlled by `diagnostics.neededFileStatus` separately.
7878
Other settings will override individual settings without end of `!`.
7979
]]
80+
config.diagnostics.workspaceEvent =
81+
"Set the time to trigger workspace diagnostics."
82+
config.diagnostics.workspaceEvent.OnChange =
83+
"Trigger workspace diagnostics when the file is changed."
84+
config.diagnostics.workspaceEvent.OnSave =
85+
"Trigger workspace diagnostics when the file is saved."
86+
config.diagnostics.workspaceEvent.None =
87+
"Disable workspace diagnostics."
8088
config.diagnostics.workspaceDelay =
81-
"Latency (milliseconds) for workspace diagnostics. When you start the workspace, or edit any file, the entire workspace will be re-diagnosed in the background. Set to negative to disable workspace diagnostics."
89+
"Latency (milliseconds) for workspace diagnostics."
8290
config.diagnostics.workspaceRate =
8391
"Workspace diagnostics run rate (%). Decreasing this value reduces CPU usage, but also reduces the speed of workspace diagnostics. The diagnosis of the file you are currently editing is always done at full speed and is not affected by this setting."
8492
config.diagnostics.libraryFiles =

locale/pt-br/setting.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,16 @@ Modify the diagnostic needed file status in a group.
7777
`Fallback` means that diagnostics in this group are controlled by `diagnostics.neededFileStatus` separately.
7878
Other settings will override individual settings without end of `!`.
7979
]]
80+
config.diagnostics.workspaceEvent = -- TODO: need translate!
81+
"Set the time to trigger workspace diagnostics."
82+
config.diagnostics.workspaceEvent.OnChange = -- TODO: need translate!
83+
"Trigger workspace diagnostics when the file is changed."
84+
config.diagnostics.workspaceEvent.OnSave = -- TODO: need translate!
85+
"Trigger workspace diagnostics when the file is saved."
86+
config.diagnostics.workspaceEvent.None = -- TODO: need translate!
87+
"Disable workspace diagnostics."
8088
config.diagnostics.workspaceDelay = -- TODO: need translate!
81-
"Latency (milliseconds) for workspace diagnostics. When you start the workspace, or edit any file, the entire workspace will be re-diagnosed in the background. Set to negative to disable workspace diagnostics."
89+
"Latency (milliseconds) for workspace diagnostics."
8290
config.diagnostics.workspaceRate = -- TODO: need translate!
8391
"Workspace diagnostics run rate (%). Decreasing this value reduces CPU usage, but also reduces the speed of workspace diagnostics. The diagnosis of the file you are currently editing is always done at full speed and is not affected by this setting."
8492
config.diagnostics.libraryFiles = -- TODO: need translate!

locale/zh-cn/setting.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,16 @@ config.diagnostics.groupFileStatus =
7676
设置为 `Fallback` 意味着组中的诊断由 `diagnostics.neededFileStatus` 单独设置。
7777
其他设置将覆盖单独设置,但是不会覆盖以 `!` 结尾的设置。
7878
]]
79+
config.diagnostics.workspaceEvent =
80+
"设置触发工作区诊断的时机。"
81+
config.diagnostics.workspaceEvent.OnChange =
82+
"当文件发生变化时触发工作区诊断。"
83+
config.diagnostics.workspaceEvent.OnSave =
84+
"当文件保存时触发工作区诊断。"
85+
config.diagnostics.workspaceEvent.None =
86+
"关闭工作区诊断。"
7987
config.diagnostics.workspaceDelay =
80-
"进行工作区诊断的延迟(毫秒)。当你启动工作区,或编辑了任意文件后,将会在后台对整个工作区进行重新诊断。设置为负数可以禁用工作区诊断。"
88+
"进行工作区诊断的延迟(毫秒)。"
8189
config.diagnostics.workspaceRate =
8290
"工作区诊断的运行速率(百分比)。降低该值会减少CPU占用,但是也会降低工作区诊断的速度。你当前正在编辑的文件的诊断总是全速完成,不受该选项影响。"
8391
config.diagnostics.libraryFiles =

locale/zh-tw/setting.lua

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,16 @@ config.diagnostics.groupFileStatus =
7676
設定為 `Fallback` 意味著組中的診斷由 `diagnostics.neededFileStatus` 單獨設定。
7777
其他設定將覆蓋單獨設定,但是不會覆蓋以 `!` 結尾的設定。
7878
]]
79+
config.diagnostics.workspaceEvent = -- TODO: need translate!
80+
"Set the time to trigger workspace diagnostics."
81+
config.diagnostics.workspaceEvent.OnChange = -- TODO: need translate!
82+
"Trigger workspace diagnostics when the file is changed."
83+
config.diagnostics.workspaceEvent.OnSave = -- TODO: need translate!
84+
"Trigger workspace diagnostics when the file is saved."
85+
config.diagnostics.workspaceEvent.None = -- TODO: need translate!
86+
"Disable workspace diagnostics."
7987
config.diagnostics.workspaceDelay =
80-
"進行工作區診斷的延遲(毫秒)。當你啟動工作區,或編輯了任何檔案後,將會在背景對整個工作區進行重新診斷。設定為負數可以停用工作區診斷。"
88+
"進行工作區診斷的延遲(毫秒)。"
8189
config.diagnostics.workspaceRate =
8290
"工作區診斷的執行速率(百分比)。降低該值會減少CPU使用率,但是也會降低工作區診斷的速度。你目前正在編輯的檔案的診斷總是全速完成,不受該選項影響。"
8391
config.diagnostics.libraryFiles =

script/config/template.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ local template = {
290290
)
291291
>> util.deepCopy(define.DiagnosticDefaultGroupFileStatus),
292292
['Lua.diagnostics.disableScheme'] = Type.Array(Type.String) >> { 'git' },
293+
['Lua.diagnostics.workspaceEvent'] = Type.String >> 'OnSave' << {
294+
'OnChange',
295+
'OnSave',
296+
'None',
297+
},
293298
['Lua.diagnostics.workspaceDelay'] = Type.Integer >> 3000,
294299
['Lua.diagnostics.workspaceRate'] = Type.Integer >> 100,
295300
['Lua.diagnostics.libraryFiles'] = Type.String >> 'Opened' << {

script/provider/diagnostic.lua

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -391,23 +391,22 @@ function m.pullDiagnostic(uri, isScopeDiag)
391391
return full
392392
end
393393

394+
---@param event string
394395
---@param uri uri
395-
function m.refresh(uri)
396+
function m.refreshScopeDiag(event, uri)
396397
if not ws.isReady(uri) then
397398
return
398399
end
399-
400-
await.close('diag:' .. uri)
401-
---@async
402-
await.call(function ()
403-
await.setID('diag:' .. uri)
404-
await.sleep(0.1)
405-
xpcall(m.doDiagnostic, log.error, uri)
406-
end)
407-
408400
local scp = scope.getScope(uri)
409401
local scopeID = 'diagnosticsScope:' .. scp:getName()
410402
await.close(scopeID)
403+
404+
local eventConfig = config.get(uri, 'Lua.diagnostics.workspaceEvent')
405+
406+
if eventConfig ~= event then
407+
return
408+
end
409+
411410
---@async
412411
await.call(function ()
413412
local delay = config.get(uri, 'Lua.diagnostics.workspaceDelay') / 1000
@@ -419,6 +418,21 @@ function m.refresh(uri)
419418
end)
420419
end
421420

421+
---@param uri uri
422+
function m.refresh(uri)
423+
if not ws.isReady(uri) then
424+
return
425+
end
426+
427+
await.close('diag:' .. uri)
428+
---@async
429+
await.call(function ()
430+
await.setID('diag:' .. uri)
431+
await.sleep(0.1)
432+
xpcall(m.doDiagnostic, log.error, uri)
433+
end)
434+
end
435+
422436
---@async
423437
local function askForDisable(uri)
424438
if m.dontAskedForDisable then
@@ -613,6 +627,7 @@ files.watch(function (ev, uri) ---@async
613627
m.refresh(uri)
614628
elseif ev == 'update' then
615629
m.refresh(uri)
630+
m.refreshScopeDiag('OnChange', uri)
616631
elseif ev == 'open' then
617632
if ws.isReady(uri) then
618633
m.resendDiagnostic(uri)
@@ -623,6 +638,8 @@ files.watch(function (ev, uri) ---@async
623638
or ws.isIgnored(uri) then
624639
m.clear(uri)
625640
end
641+
elseif ev == 'save' then
642+
m.refreshScopeDiag('OnSave', uri)
626643
end
627644
end)
628645

script/provider/provider.lua

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,22 @@ m.register 'textDocument/didChange' {
312312
end
313313
}
314314

315+
m.register 'textDocument/didSave' {
316+
capability = {
317+
textDocumentSync = {
318+
save = {
319+
includeText = false,
320+
},
321+
}
322+
},
323+
---@async
324+
function (params)
325+
local doc = params.textDocument
326+
local uri = files.getRealUri(doc.uri)
327+
files.onWatch('save', uri)
328+
end
329+
}
330+
315331
m.register 'textDocument/hover' {
316332
capability = {
317333
hoverProvider = true,

0 commit comments

Comments
 (0)