diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-10-17 20:20:18 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-10-17 20:20:18 +0800 |
commit | 4e647a342a525eda45418398f1409c8e5a57adff (patch) | |
tree | 5d0ccd3849e2f545b02c5c6f50c4be2d539cb36e /script | |
parent | 279c1ad7b88e464535971143660712fb0ea259ca (diff) | |
download | lua-language-server-4e647a342a525eda45418398f1409c8e5a57adff.zip |
new setting `Lua.diagnostics.workspaceEvent`
set the time to trigger workspace diagnostics.
resolve #1626
Diffstat (limited to 'script')
-rw-r--r-- | script/config/template.lua | 5 | ||||
-rw-r--r-- | script/provider/diagnostic.lua | 37 | ||||
-rw-r--r-- | script/provider/provider.lua | 16 |
3 files changed, 48 insertions, 10 deletions
diff --git a/script/config/template.lua b/script/config/template.lua index 2afb7fff..c71faa10 100644 --- a/script/config/template.lua +++ b/script/config/template.lua @@ -290,6 +290,11 @@ local template = { ) >> util.deepCopy(define.DiagnosticDefaultGroupFileStatus), ['Lua.diagnostics.disableScheme'] = Type.Array(Type.String) >> { 'git' }, + ['Lua.diagnostics.workspaceEvent'] = Type.String >> 'OnSave' << { + 'OnChange', + 'OnSave', + 'None', + }, ['Lua.diagnostics.workspaceDelay'] = Type.Integer >> 3000, ['Lua.diagnostics.workspaceRate'] = Type.Integer >> 100, ['Lua.diagnostics.libraryFiles'] = Type.String >> 'Opened' << { diff --git a/script/provider/diagnostic.lua b/script/provider/diagnostic.lua index 583173f0..0fac3e17 100644 --- a/script/provider/diagnostic.lua +++ b/script/provider/diagnostic.lua @@ -391,23 +391,22 @@ function m.pullDiagnostic(uri, isScopeDiag) return full end +---@param event string ---@param uri uri -function m.refresh(uri) +function m.refreshScopeDiag(event, uri) if not ws.isReady(uri) then return end - - await.close('diag:' .. uri) - ---@async - await.call(function () - await.setID('diag:' .. uri) - await.sleep(0.1) - xpcall(m.doDiagnostic, log.error, uri) - end) - local scp = scope.getScope(uri) local scopeID = 'diagnosticsScope:' .. scp:getName() await.close(scopeID) + + local eventConfig = config.get(uri, 'Lua.diagnostics.workspaceEvent') + + if eventConfig ~= event then + return + end + ---@async await.call(function () local delay = config.get(uri, 'Lua.diagnostics.workspaceDelay') / 1000 @@ -419,6 +418,21 @@ function m.refresh(uri) end) end +---@param uri uri +function m.refresh(uri) + if not ws.isReady(uri) then + return + end + + await.close('diag:' .. uri) + ---@async + await.call(function () + await.setID('diag:' .. uri) + await.sleep(0.1) + xpcall(m.doDiagnostic, log.error, uri) + end) +end + ---@async local function askForDisable(uri) if m.dontAskedForDisable then @@ -613,6 +627,7 @@ files.watch(function (ev, uri) ---@async m.refresh(uri) elseif ev == 'update' then m.refresh(uri) + m.refreshScopeDiag('OnChange', uri) elseif ev == 'open' then if ws.isReady(uri) then m.resendDiagnostic(uri) @@ -623,6 +638,8 @@ files.watch(function (ev, uri) ---@async or ws.isIgnored(uri) then m.clear(uri) end + elseif ev == 'save' then + m.refreshScopeDiag('OnSave', uri) end end) diff --git a/script/provider/provider.lua b/script/provider/provider.lua index 2225588a..7386ded0 100644 --- a/script/provider/provider.lua +++ b/script/provider/provider.lua @@ -312,6 +312,22 @@ m.register 'textDocument/didChange' { end } +m.register 'textDocument/didSave' { + capability = { + textDocumentSync = { + save = { + includeText = false, + }, + } + }, + ---@async + function (params) + local doc = params.textDocument + local uri = files.getRealUri(doc.uri) + files.onWatch('save', uri) + end +} + m.register 'textDocument/hover' { capability = { hoverProvider = true, |