Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
void this.languageClient.sendNotification(
DidCloseTextDocumentNotificationType,
{
textDocument: { uri },
},
);

void 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(
Expand Down
Loading