From ed4bedf3d79b3e73b83cc65da32bfb4ceb08672b Mon Sep 17 00:00:00 2001 From: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> Date: Fri, 12 Jun 2026 12:13:07 -0700 Subject: [PATCH 1/2] Clean up dead code and other low-hanging tech debt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A few low-risk cleanups found while combing through the extension: - Remove the unused `getTimestampString()` from `src/utils.ts`. It's been dead since 2017 (`1b424000`), when "Add timestamps and log levels to all extension-side log messages" moved timestamping into the `Logger` and deleted its three call sites. It also had a latent bug: no zero-padding, so it rendered times like `[9:5:3]`. - Remove the unused `getWindowsSystemPowerShellPath()` from `src/platform.ts`. It's been dead since #2238 (2019), which introduced `PowerShellExeFinder` and deleted the `System32PowerShellPath` / `SysnativePowerShellPath` / `SysWow64PowerShellPath` constants that called it. The same path is now built inline in `findWinPS()`, with proper bitness handling in `getSystem32Path()`. - Replace `console.log` with `this.logger.writeDebug` in `writePidIfInDevMode` (`src/session.ts`), per our `ILogger` convention. While here, `await` the `fs.delete` it sits next to so the "Deleted PID file" message is actually true — previously it was a floating promise and the log ran before the delete resolved. - Point the PSScriptAnalyzer rule docs link at `learn.microsoft.com` instead of `docs.microsoft.com` (`src/features/CodeActions.ts`); the old URL just 301s there anyway. I left the Command Explorer's dead code alone since #5508 already rewrites that file. Compile, lint, and format all pass; the touched code has no test coverage so risk is low. Drafted by Copilot (Claude Opus 4.8). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/features/CodeActions.ts | 2 +- src/platform.ts | 15 --------------- src/session.ts | 6 +++--- src/utils.ts | 5 ----- 4 files changed, 4 insertions(+), 24 deletions(-) diff --git a/src/features/CodeActions.ts b/src/features/CodeActions.ts index 825b7941a9..ff33097917 100644 --- a/src/features/CodeActions.ts +++ b/src/features/CodeActions.ts @@ -27,7 +27,7 @@ export class CodeActionsFeature implements vscode.Disposable { private async showRuleDocumentation(ruleId: string): Promise { const pssaDocBaseURL = - "https://docs.microsoft.com/powershell/utility-modules/psscriptanalyzer/rules/"; + "https://learn.microsoft.com/powershell/utility-modules/psscriptanalyzer/rules/"; if (!ruleId) { this.log.writeWarning( diff --git a/src/platform.ts b/src/platform.ts index c1037e05f9..ba78b7f0d7 100644 --- a/src/platform.ts +++ b/src/platform.ts @@ -755,21 +755,6 @@ export class PowerShellExeFinder { } } -export function getWindowsSystemPowerShellPath( - systemFolderName: string, -): string | undefined { - if (process.env.windir === undefined) { - return undefined; - } else - return path.join( - process.env.windir, - systemFolderName, - "WindowsPowerShell", - "v1.0", - "powershell.exe", - ); -} - interface IPossiblePowerShellExe extends IPowerShellExeDetails { exists(): Promise; readonly suppressWarning: boolean; diff --git a/src/session.ts b/src/session.ts index adcb815e4f..6612513a80 100644 --- a/src/session.ts +++ b/src/session.ts @@ -385,10 +385,10 @@ export class SessionManager implements Middleware { const fs = vscode.workspace.fs; const pid = (await pwshProcess.getPid())!.toString(); await fs.writeFile(pidFilePath, Buffer.from(pid)); - const deletePidOnExit = pwshProcess.onExited(() => { + const deletePidOnExit = pwshProcess.onExited(async () => { deletePidOnExit.dispose(); - fs.delete(pidFilePath, { useTrash: false }); - console.log(`Deleted PID file: ${pidFilePath}`); + await fs.delete(pidFilePath, { useTrash: false }); + this.logger.writeDebug(`Deleted PID file: ${pidFilePath}`); }); this.registeredCommands.push(deletePidOnExit); this.extensionContext.subscriptions.push(deletePidOnExit); diff --git a/src/utils.ts b/src/utils.ts index e29a5f3807..5e7ec6d738 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -96,11 +96,6 @@ export async function readDirectory( return items.map(([name, _type]) => name); } -export function getTimestampString(): string { - const time = new Date(); - return `[${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}]`; -} - export function sleep(ms: number): Promise { return new Promise((resolve) => setTimeout(resolve, ms)); } From fd4c4e78c809758ab38555a2af6ee0441dc406fd Mon Sep 17 00:00:00 2001 From: Andy Jordan <2226434+andyleejordan@users.noreply.github.com> Date: Fri, 12 Jun 2026 12:53:05 -0700 Subject: [PATCH 2/2] Handle errors when deleting dev-mode PID file on exit The `onExited` listener in `writePidIfInDevMode` is `async`, but VS Code `Event` listeners are fire-and-forget: the returned promise is never awaited. As Copilot noted on #5515, that means a rejection from `fs.delete(...)` would surface as an unhandled promise rejection, and the debug log would be skipped on failure. I kept the `async`/`await` form for readability and wrapped the body in `try`/`catch` so nothing escapes: a fully-caught async body resolves normally, and any failure is now logged via `this.logger.writeError` instead of going unhandled. The original `main` version floated the delete promise and logged success unconditionally, swallowing errors. Drafted by Copilot (Claude Opus 4.8). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/session.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/session.ts b/src/session.ts index 6612513a80..1c3585d1e4 100644 --- a/src/session.ts +++ b/src/session.ts @@ -387,8 +387,14 @@ export class SessionManager implements Middleware { await fs.writeFile(pidFilePath, Buffer.from(pid)); const deletePidOnExit = pwshProcess.onExited(async () => { deletePidOnExit.dispose(); - await fs.delete(pidFilePath, { useTrash: false }); - this.logger.writeDebug(`Deleted PID file: ${pidFilePath}`); + try { + await fs.delete(pidFilePath, { useTrash: false }); + this.logger.writeDebug(`Deleted PID file: ${pidFilePath}`); + } catch (err) { + this.logger.writeError( + `Error occurred while deleting PID file:\n${err}`, + ); + } }); this.registeredCommands.push(deletePidOnExit); this.extensionContext.subscriptions.push(deletePidOnExit);