Skip to content

Commit

Permalink
Merge pull request #2621 from emmericp/check-all-diagnostics
Browse files Browse the repository at this point in the history
Run diagnostics on unopened files when explicitly requested by the user
  • Loading branch information
sumneko authored Apr 22, 2024
2 parents d2ea5ee + a6cb075 commit 630d109
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
10 changes: 6 additions & 4 deletions script/core/diagnostics/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ end
---@param name string
---@param isScopeDiag boolean
---@param response async fun(result: any)
---@param ignoreFileOpenState? boolean
---@return boolean
local function check(uri, name, isScopeDiag, response)
local function check(uri, name, isScopeDiag, response, ignoreFileOpenState)
local disables = config.get(uri, 'Lua.diagnostics.disable')
if util.arrayHas(disables, name) then
return false
Expand All @@ -107,7 +108,7 @@ local function check(uri, name, isScopeDiag, response)
return false
end

if status == 'Opened' and not files.isOpen(uri) then
if not ignoreFileOpenState and status == 'Opened' and not files.isOpen(uri) then
return false
end

Expand Down Expand Up @@ -167,7 +168,8 @@ end
---@param isScopeDiag boolean
---@param response async fun(result: any)
---@param checked? async fun(name: string)
return function (uri, isScopeDiag, response, checked)
---@param ignoreFileOpenState? boolean
return function (uri, isScopeDiag, response, checked, ignoreFileOpenState)
local ast = files.getState(uri)
if not ast then
return nil
Expand All @@ -176,7 +178,7 @@ return function (uri, isScopeDiag, response, checked)
for _, name in ipairs(buildDiagList()) do
await.delay()
local clock = os.clock()
local suc = check(uri, name, isScopeDiag, response)
local suc = check(uri, name, isScopeDiag, response, ignoreFileOpenState)
if suc then
local cost = os.clock() - clock
diagCosts[name] = (diagCosts[name] or 0) + cost
Expand Down
8 changes: 4 additions & 4 deletions script/provider/diagnostic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ local function isValid(uri)
end

---@async
function m.doDiagnostic(uri, isScopeDiag)
function m.doDiagnostic(uri, isScopeDiag, ignoreFileState)
if not isValid(uri) then
return
end
Expand Down Expand Up @@ -348,7 +348,7 @@ function m.doDiagnostic(uri, isScopeDiag)
lastDiag[#lastDiag] = nil
end
end
end)
end, ignoreFileState)

lastDiag = nil
pushResult()
Expand Down Expand Up @@ -575,7 +575,7 @@ function m.awaitDiagnosticsScope(suri, callback)
finished = true
end

function m.diagnosticsScope(uri, force)
function m.diagnosticsScope(uri, force, ignoreFileOpenState)
if not ws.isReady(uri) then
return
end
Expand All @@ -592,7 +592,7 @@ function m.diagnosticsScope(uri, force)
await.call(function () ---@async
await.sleep(0.0)
m.awaitDiagnosticsScope(uri, function (fileUri)
xpcall(m.doDiagnostic, log.error, fileUri, true)
xpcall(m.doDiagnostic, log.error, fileUri, true, ignoreFileOpenState)
end)
end, id)
end
Expand Down
2 changes: 1 addition & 1 deletion script/provider/provider.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ m.register '$/status/click' {
if result == titleDiagnostic then
local diagnostic = require 'provider.diagnostic'
for _, scp in ipairs(workspace.folders) do
diagnostic.diagnosticsScope(scp.uri, true)
diagnostic.diagnosticsScope(scp.uri, true, true)
end
elseif result == 'Restart Server' then
local diag = require 'provider.diagnostic'
Expand Down

0 comments on commit 630d109

Please sign in to comment.