Skip to content

Commit 630d109

Browse files
authored
Merge pull request #2621 from emmericp/check-all-diagnostics
Run diagnostics on unopened files when explicitly requested by the user
2 parents d2ea5ee + a6cb075 commit 630d109

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

script/core/diagnostics/init.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,9 @@ end
9494
---@param name string
9595
---@param isScopeDiag boolean
9696
---@param response async fun(result: any)
97+
---@param ignoreFileOpenState? boolean
9798
---@return boolean
98-
local function check(uri, name, isScopeDiag, response)
99+
local function check(uri, name, isScopeDiag, response, ignoreFileOpenState)
99100
local disables = config.get(uri, 'Lua.diagnostics.disable')
100101
if util.arrayHas(disables, name) then
101102
return false
@@ -107,7 +108,7 @@ local function check(uri, name, isScopeDiag, response)
107108
return false
108109
end
109110

110-
if status == 'Opened' and not files.isOpen(uri) then
111+
if not ignoreFileOpenState and status == 'Opened' and not files.isOpen(uri) then
111112
return false
112113
end
113114

@@ -167,7 +168,8 @@ end
167168
---@param isScopeDiag boolean
168169
---@param response async fun(result: any)
169170
---@param checked? async fun(name: string)
170-
return function (uri, isScopeDiag, response, checked)
171+
---@param ignoreFileOpenState? boolean
172+
return function (uri, isScopeDiag, response, checked, ignoreFileOpenState)
171173
local ast = files.getState(uri)
172174
if not ast then
173175
return nil
@@ -176,7 +178,7 @@ return function (uri, isScopeDiag, response, checked)
176178
for _, name in ipairs(buildDiagList()) do
177179
await.delay()
178180
local clock = os.clock()
179-
local suc = check(uri, name, isScopeDiag, response)
181+
local suc = check(uri, name, isScopeDiag, response, ignoreFileOpenState)
180182
if suc then
181183
local cost = os.clock() - clock
182184
diagCosts[name] = (diagCosts[name] or 0) + cost

script/provider/diagnostic.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ local function isValid(uri)
275275
end
276276

277277
---@async
278-
function m.doDiagnostic(uri, isScopeDiag)
278+
function m.doDiagnostic(uri, isScopeDiag, ignoreFileState)
279279
if not isValid(uri) then
280280
return
281281
end
@@ -348,7 +348,7 @@ function m.doDiagnostic(uri, isScopeDiag)
348348
lastDiag[#lastDiag] = nil
349349
end
350350
end
351-
end)
351+
end, ignoreFileState)
352352

353353
lastDiag = nil
354354
pushResult()
@@ -575,7 +575,7 @@ function m.awaitDiagnosticsScope(suri, callback)
575575
finished = true
576576
end
577577

578-
function m.diagnosticsScope(uri, force)
578+
function m.diagnosticsScope(uri, force, ignoreFileOpenState)
579579
if not ws.isReady(uri) then
580580
return
581581
end
@@ -592,7 +592,7 @@ function m.diagnosticsScope(uri, force)
592592
await.call(function () ---@async
593593
await.sleep(0.0)
594594
m.awaitDiagnosticsScope(uri, function (fileUri)
595-
xpcall(m.doDiagnostic, log.error, fileUri, true)
595+
xpcall(m.doDiagnostic, log.error, fileUri, true, ignoreFileOpenState)
596596
end)
597597
end, id)
598598
end

script/provider/provider.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ m.register '$/status/click' {
12091209
if result == titleDiagnostic then
12101210
local diagnostic = require 'provider.diagnostic'
12111211
for _, scp in ipairs(workspace.folders) do
1212-
diagnostic.diagnosticsScope(scp.uri, true)
1212+
diagnostic.diagnosticsScope(scp.uri, true, true)
12131213
end
12141214
elseif result == 'Restart Server' then
12151215
local diag = require 'provider.diagnostic'

0 commit comments

Comments
 (0)