Skip to content

Refresh diagnostics for open PowerShell docs#5402

Open
mdaneri wants to merge 3 commits intoPowerShell:mainfrom
mdaneri:fix/5381-refresh-open-doc-diagnostics
Open

Refresh diagnostics for open PowerShell docs#5402
mdaneri wants to merge 3 commits intoPowerShell:mainfrom
mdaneri:fix/5381-refresh-open-doc-diagnostics

Conversation

@mdaneri
Copy link
Copy Markdown

@mdaneri mdaneri commented Feb 17, 2026

PR Summary

  • refresh analysis for already-open PowerShell documents once the language client reaches Running
  • replay textDocument/didClose + textDocument/didOpen for open file and untitled PowerShell docs
  • avoid requiring a manual edit to clear false custom-attribute type diagnostics on initial open

Related Issue

Fixes #5381

Testing

  • verified extension builds with npm run compile
  • validated issue repro: initial false diagnostics clear without typing after session startup

PR Checklist

Note: Tick the boxes below that apply to this pull request by putting an x between the square brackets.
Please mark anything not applicable to this PR NA.

  • PR has a meaningful title
  • Summarized changes
  • PR has tests
  • This PR is ready to merge and is not work in progress
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready

Force re-analysis of open PowerShell documents after the language server starts. Adds DidOpenTextDocument and DidCloseTextDocument notification types and a refreshOpenPowerShellDocumentDiagnostics() helper that filters open documents (powershell, file/untitled), logs the action, and sends didClose followed by didOpen (including languageId, version and text) to the language client. The method is invoked after the session reports it has started; it no-ops if the client isn't running or there are no matching open documents.
Copilot AI review requested due to automatic review settings February 17, 2026 10:33
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses false diagnostics that appear when PowerShell documents are initially opened before the language server is fully initialized. The solution refreshes analysis for all open PowerShell documents once the language client reaches the Running state.

Changes:

  • Added custom notification types for textDocument/didOpen and textDocument/didClose
  • Implemented refreshOpenPowerShellDocumentDiagnostics() method to replay close/open events for already-open PowerShell documents
  • Called the refresh method after the language client is confirmed running during session startup

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

mdaneri and others added 2 commits February 17, 2026 19:10
Prefix this.languageClient.sendNotification calls with the void operator to explicitly discard the returned Promise and avoid floating-promise/unused-Promise warnings. Applied to notifications sent for DidCloseTextDocumentNotificationType and DidOpenTextDocumentNotificationType when iterating open PowerShell documents.
Copy link
Copy Markdown
Member

@andyleejordan andyleejordan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm reading this right, you're essentially sending mock close and open notifications for PowerShell docs after the LSP server starts. Which makes sense to work around the issue, but since that means we've identified the root case (these notifications are being sent too early) can we investigate if there are VS Code / LSP Client APIs to use to delay sending those notifications until we're ready? What I'm saying is, I suspect there's a more correct way to fix this.

@mdaneri
Copy link
Copy Markdown
Author

mdaneri commented Apr 3, 2026

I’m sure there’s a better approach. It just goes beyond what I know about how VS Code operates.

@andyleejordan
Copy link
Copy Markdown
Member

I'll take a look.

andyleejordan added a commit that referenced this pull request Apr 4, 2026
An attempt to fix #5381 where we believe the cause is that the didOpen()/didChange()
notifications are being sent before PowerShell has totally finished loading.

Since these run the PowerShell parser on the OmniSharp thread pool,
they essentially race the analysis of the files by PSScriptAnalyzer on the
PowerShell runspace pool. So when they beat it, the return errors.
But when they're beaten by it, the PSSA analysis has caused the assemblies
(and so custom attributes) to be loaded, no longer erroring.

I posited we could gate the notifications instead of duplicating them
like in #5402, and if the `Middleware` works as suspected by me (and Claude)
this should fix it. Morever, we now also use a proper `Promise` instead of
a while loop around a sleep to wait for the LSP server to be running.

While all of this could just be an AI hallucination...it seems right.
andyleejordan added a commit that referenced this pull request Apr 4, 2026
An attempt to fix #5381 where we believe the cause is that the didOpen()/didChange()
notifications are being sent before PowerShell has totally finished loading.

Since these run the PowerShell parser on the OmniSharp thread pool,
they essentially race the analysis of the files by PSScriptAnalyzer on the
PowerShell runspace pool. So when they beat it, the return errors.
But when they're beaten by it, the PSSA analysis has caused the assemblies
(and so custom attributes) to be loaded, no longer erroring.

I posited we could gate the notifications instead of duplicating them
like in #5402, and if the `Middleware` works as suspected by me (and Claude)
this should fix it. Morever, we now also use a proper `Promise` instead of
a while loop around a sleep to wait for the LSP server to be running.

While all of this could just be an AI hallucination...it seems right.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PowerShell Custom Attribute Types Unresolved on Initial File Open

3 participants