From 4cf5e0038283f7a9e1f19308a1263e954299d911 Mon Sep 17 00:00:00 2001 From: mdaneri Date: Tue, 17 Feb 2026 11:23:37 +0100 Subject: [PATCH 1/2] Refresh diagnostics for open PowerShell docs 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. --- src/session.ts | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/session.ts b/src/session.ts index a6bfde9b94..94fcedd718 100644 --- a/src/session.ts +++ b/src/session.ts @@ -99,6 +99,21 @@ export const PowerShellVersionRequestType = new RequestType0< void >("powerShell/getVersion"); +const DidOpenTextDocumentNotificationType = new NotificationType<{ + textDocument: { + uri: string; + languageId: string; + version: number; + text: string; + }; +}>("textDocument/didOpen"); + +const DidCloseTextDocumentNotificationType = new NotificationType<{ + textDocument: { + uri: string; + }; +}>("textDocument/didClose"); + export class SessionManager implements Middleware { public HostName: string; public DisplayName: string; @@ -295,6 +310,7 @@ export class SessionManager implements Middleware { `Started PowerShell v${this.versionDetails.version}.`, ); this.setSessionRunningStatus(); // Yay, we made it! + this.refreshOpenPowerShellDocumentDiagnostics(); await this.writePidIfInDevMode(this.languageServerProcess); @@ -1167,6 +1183,49 @@ Type 'help' to get help. } } + private refreshOpenPowerShellDocumentDiagnostics(): void { + if (!this.languageClient?.isRunning()) { + return; + } + + const openPowerShellDocuments = vscode.workspace.textDocuments.filter( + (document) => + document.languageId === "powershell" && + (document.uri.scheme === "file" || + document.uri.scheme === "untitled"), + ); + + if (openPowerShellDocuments.length === 0) { + return; + } + + this.logger.writeDebug( + `Refreshing analysis for ${openPowerShellDocuments.length} open PowerShell document(s).`, + ); + + for (const document of openPowerShellDocuments) { + const uri = document.uri.toString(); + this.languageClient.sendNotification( + DidCloseTextDocumentNotificationType, + { + textDocument: { uri }, + }, + ); + + this.languageClient.sendNotification( + DidOpenTextDocumentNotificationType, + { + textDocument: { + uri, + languageId: document.languageId, + version: document.version, + text: document.getText(), + }, + }, + ); + } + } + private createStatusBarItem(): vscode.LanguageStatusItem { const statusTitle = "Show PowerShell Session Menu"; const languageStatusItem = vscode.languages.createLanguageStatusItem( From a316c8359ae5a40961d5f2cdd2e6ad678a8979ce Mon Sep 17 00:00:00 2001 From: mdaneri Date: Tue, 17 Feb 2026 19:10:55 +0100 Subject: [PATCH 2/2] Use void to ignore sendNotification Promise 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. --- src/session.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/session.ts b/src/session.ts index 94fcedd718..57dca9fc93 100644 --- a/src/session.ts +++ b/src/session.ts @@ -1205,14 +1205,14 @@ Type 'help' to get help. for (const document of openPowerShellDocuments) { const uri = document.uri.toString(); - this.languageClient.sendNotification( + void this.languageClient.sendNotification( DidCloseTextDocumentNotificationType, { textDocument: { uri }, }, ); - this.languageClient.sendNotification( + void this.languageClient.sendNotification( DidOpenTextDocumentNotificationType, { textDocument: {