-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cancel button, update test suite, fix broken link
- Loading branch information
1 parent
fe5d18f
commit 43ee4a0
Showing
7 changed files
with
382 additions
and
270 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,66 @@ | ||
// src/config.ts | ||
import * as vscode from 'vscode'; | ||
import { waitForExtensionReady } from './utils'; | ||
|
||
export interface Configuration { | ||
model: string; | ||
apiKey?: string; | ||
} | ||
|
||
// Extension timing configuration | ||
export const Timeouts = { | ||
CLEANUP: 1000, // 1 second for cleanup operations | ||
DEFAULT_ACTIVATION: 100, // 100ms default safety delay | ||
get ACTIVATION(): number { | ||
return parseInt(process.env.VSCODE_CLAUDE_ACTIVATION_TIMEOUT || '', 10) || this.DEFAULT_ACTIVATION; | ||
}, | ||
STATUS_BAR_PRIORITY: 100 | ||
} as const; | ||
|
||
export function getConfiguration(): Configuration { | ||
const config = vscode.workspace.getConfiguration('claude-vscode'); | ||
return { | ||
model: config.get('model') || 'claude-3-opus-20240229', | ||
apiKey: config.get('apiKey') | ||
}; | ||
} | ||
|
||
export async function unregisterCommands(): Promise<void> { | ||
const allCommands = await vscode.commands.getCommands(); | ||
const ourCommands = [ | ||
'claude-vscode.support', | ||
'claude-vscode.askClaude', | ||
'claude-vscode.documentCode' | ||
]; | ||
|
||
// First try normal unregistration | ||
for (const cmd of ourCommands) { | ||
if (allCommands.includes(cmd)) { | ||
try { | ||
await vscode.commands.executeCommand('workbench.action.unregisterCommand', cmd); | ||
} catch (err) { | ||
console.warn(`Failed to unregister command ${cmd}:`, err); | ||
} | ||
} | ||
} | ||
|
||
// Wait for commands to unregister | ||
await waitForExtensionReady(Timeouts.ACTIVATION); | ||
|
||
// Force cleanup in case normal unregistration failed | ||
const remainingCommands = await vscode.commands.getCommands(); | ||
for (const cmd of ourCommands) { | ||
if (remainingCommands.includes(cmd)) { | ||
try { | ||
// Force dispose any existing command registration | ||
const existingDisposable = vscode.commands.registerCommand(cmd, () => {}); | ||
existingDisposable.dispose(); | ||
} catch (err) { | ||
console.warn(`Failed force cleanup of command ${cmd}:`, err); | ||
} | ||
} | ||
} | ||
|
||
// Final wait to ensure cleanup | ||
await waitForExtensionReady(Timeouts.ACTIVATION); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// src/utils.ts | ||
import * as vscode from 'vscode'; | ||
import { Timeouts } from './config'; | ||
|
||
/** | ||
* Waits for the extension to be ready after state changes | ||
* @param timeout Optional custom timeout (defaults to 3x activation timeout) | ||
*/ | ||
export async function waitForExtensionReady(timeout?: number): Promise<void> { | ||
const waitTime = timeout || Math.max(Timeouts.ACTIVATION * 3, 500); | ||
await new Promise(resolve => setTimeout(resolve, waitTime)); | ||
} | ||
|
||
/** | ||
* Ensures all editor windows are closed | ||
* @param retries Number of retry attempts | ||
* @param delay Delay between retries in ms | ||
*/ | ||
export async function ensureAllEditorsClosed(retries = 3, delay = 500): Promise<void> { | ||
for (let i = 0; i < retries; i++) { | ||
if (vscode.window.visibleTextEditors.length === 0) return; | ||
await vscode.commands.executeCommand('workbench.action.closeAllEditors'); | ||
await new Promise(resolve => setTimeout(resolve, delay)); | ||
} | ||
if (vscode.window.visibleTextEditors.length > 0) { | ||
throw new Error('Failed to close all editors'); | ||
} | ||
} | ||
|
||
/** | ||
* Unregisters our extension's commands from VS Code | ||
*/ | ||
export async function unregisterCommands(): Promise<void> { | ||
const allCommands = await vscode.commands.getCommands(); | ||
const ourCommands = [ | ||
'claude-vscode.support', | ||
'claude-vscode.askClaude', | ||
'claude-vscode.documentCode' | ||
]; | ||
|
||
for (const cmd of ourCommands) { | ||
if (allCommands.includes(cmd)) { | ||
try { | ||
await vscode.commands.executeCommand('workbench.action.unregisterCommand', cmd); | ||
} catch (err) { | ||
console.warn(`Failed to unregister command ${cmd}:`, err); | ||
} | ||
} | ||
} | ||
await waitForExtensionReady(Timeouts.ACTIVATION); | ||
} |
Oops, something went wrong.