Skip to content

Commit 21fae13

Browse files
Clean up dead code and other low-hanging tech debt
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>
1 parent 7884b75 commit 21fae13

4 files changed

Lines changed: 4 additions & 24 deletions

File tree

‎src/features/CodeActions.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class CodeActionsFeature implements vscode.Disposable {
2727

2828
private async showRuleDocumentation(ruleId: string): Promise<void> {
2929
const pssaDocBaseURL =
30-
"https://docs.microsoft.com/powershell/utility-modules/psscriptanalyzer/rules/";
30+
"https://learn.microsoft.com/powershell/utility-modules/psscriptanalyzer/rules/";
3131

3232
if (!ruleId) {
3333
this.log.writeWarning(

‎src/platform.ts‎

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -755,21 +755,6 @@ export class PowerShellExeFinder {
755755
}
756756
}
757757

758-
export function getWindowsSystemPowerShellPath(
759-
systemFolderName: string,
760-
): string | undefined {
761-
if (process.env.windir === undefined) {
762-
return undefined;
763-
} else
764-
return path.join(
765-
process.env.windir,
766-
systemFolderName,
767-
"WindowsPowerShell",
768-
"v1.0",
769-
"powershell.exe",
770-
);
771-
}
772-
773758
interface IPossiblePowerShellExe extends IPowerShellExeDetails {
774759
exists(): Promise<boolean>;
775760
readonly suppressWarning: boolean;

‎src/session.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,10 @@ export class SessionManager implements Middleware {
385385
const fs = vscode.workspace.fs;
386386
const pid = (await pwshProcess.getPid())!.toString();
387387
await fs.writeFile(pidFilePath, Buffer.from(pid));
388-
const deletePidOnExit = pwshProcess.onExited(() => {
388+
const deletePidOnExit = pwshProcess.onExited(async () => {
389389
deletePidOnExit.dispose();
390-
fs.delete(pidFilePath, { useTrash: false });
391-
console.log(`Deleted PID file: ${pidFilePath}`);
390+
await fs.delete(pidFilePath, { useTrash: false });
391+
this.logger.writeDebug(`Deleted PID file: ${pidFilePath}`);
392392
});
393393
this.registeredCommands.push(deletePidOnExit);
394394
this.extensionContext.subscriptions.push(deletePidOnExit);

‎src/utils.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ export async function readDirectory(
9696
return items.map(([name, _type]) => name);
9797
}
9898

99-
export function getTimestampString(): string {
100-
const time = new Date();
101-
return `[${time.getHours()}:${time.getMinutes()}:${time.getSeconds()}]`;
102-
}
103-
10499
export function sleep(ms: number): Promise<void> {
105100
return new Promise((resolve) => setTimeout(resolve, ms));
106101
}

0 commit comments

Comments
 (0)