Skip to content

Commit effd5be

Browse files
authored
Improves duplicate command prevention (#349)
* Improves duplicate command prevention Refactors duplicate command prevention by implementing a timeout. This removes the reliance on `sentToTerminal` and introduces a 3-second timeout after a command is sent to the terminal. This prevents duplicate commands from being executed within a short timeframe, improving the reliability of command execution. * [Mega-Linter] Apply linters fixes --------- Co-authored-by: nvuillam <17500430+nvuillam@users.noreply.github.com>
1 parent 729e787 commit effd5be

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Improves duplicate command prevention
6+
57
## [6.27.0] 2025-02-10
68

79
- New Documentation Workbench LWC to gather in one place all documentation related commands, and allow to easily run them and configure related settings. Commands include:

src/command-runner.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ export class CommandRunner {
132132
this.showDuplicateCommandWarning();
133133
return null;
134134
}
135-
// For terminal: sentToTerminal is true
136-
if (existing.type === "terminal" && existing.sentToTerminal) {
135+
// For terminal: command was sent to terminal less than 3 seconds ago (heuristic to avoid false positives)
136+
if (existing.type === "terminal") {
137137
this.showDuplicateCommandWarning();
138138
return null;
139139
}
@@ -503,7 +503,10 @@ export class CommandRunner {
503503
// Mark as sent to terminal (for duplicate prevention)
504504
this.activeCommands.set(cmd, { type: "terminal", sentToTerminal: true });
505505
vscode.commands.executeCommand("workbench.action.terminal.scrollToBottom");
506-
// Optionally, you could remove from activeCommands after a delay or on user action
506+
// Remove from activeCommands after a delay
507+
setTimeout(() => {
508+
this.activeCommands.delete(cmd);
509+
}, 3000);
507510
}
508511

509512
/**

0 commit comments

Comments
 (0)