Skip to content

Commit

Permalink
Fix unexpected file close attempts
Browse files Browse the repository at this point in the history
  • Loading branch information
Talamantez committed Nov 18, 2024
1 parent 94a91bb commit 91dcf7a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 36 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ concatenated_code.txt
.npmignore
.vscode/
.vscode-test/
src/
tsconfig.json
webpack.config.js
.gitignore
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).


## [1.1.4] - 2024-11-18
### Fixed
- Remove auto-closing of response windows
- Simplified window management
- Cleaned up editor disposal code

## [1.1.3] - 2024-11-18
### Fixed
- Response windows now properly handle readonly mode
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "claude-vscode-assistant",
"displayName": "Claude AI Assistant",
"version": "1.1.3",
"version": "1.1.4",
"description": "Claude AI assistant for Visual Studio Code",
"publisher": "conscious-robot",
"repository": {
Expand Down
37 changes: 3 additions & 34 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ClaudeResponse } from './api';

// Global state management
let registeredCommands: vscode.Disposable[] = [];
const activePanels = new Set<vscode.Disposable>();
let apiService: ClaudeApiService;

// Constants
Expand Down Expand Up @@ -56,23 +55,12 @@ export async function createResponsePanel(content: string): Promise<vscode.TextE
viewColumn: vscode.ViewColumn.Beside
});

// Safely handle readonly toggle
const commands = await vscode.commands.getCommands(true);
// Safely toggle readonly
const commands = await vscode.commands.getCommands();
if (commands.includes('workbench.action.toggleEditorReadonly')) {
await vscode.commands.executeCommand('workbench.action.toggleEditorReadonly');
}

if (editor) {
const disposable = new vscode.Disposable(() => {
try {
vscode.commands.executeCommand('workbench.action.closeActiveEditor');
} catch (error) {
console.error('Error closing panel:', error);
}
});
activePanels.add(disposable);
}

return editor;
} catch (error) {
console.error('Error creating response panel:', error);
Expand Down Expand Up @@ -136,15 +124,7 @@ export async function cleanupPanelsAndEditors(): Promise<void> {
await vscode.commands.executeCommand('workbench.action.closeAllEditors');
await new Promise(resolve => setTimeout(resolve, CLEANUP_TIMEOUT));

activePanels.forEach(panel => {
try {
panel.dispose();
} catch (error) {
console.error('Error disposing panel:', error);
}
});
activePanels.clear();

// Remove activePanels cleanup code, just keep tab cleanup
vscode.window.tabGroups.all.forEach(group => {
group.tabs.forEach(tab => {
try {
Expand Down Expand Up @@ -198,17 +178,6 @@ export async function activate(context: vscode.ExtensionContext, service?: Claud
registeredCommands.push(...commands);
context.subscriptions.push(...commands);

context.subscriptions.push(new vscode.Disposable(() => {
activePanels.forEach(panel => {
try {
panel.dispose();
} catch (error) {
console.error('Error disposing panel:', error);
}
});
activePanels.clear();
}));

console.log('Claude extension activated');
} catch (error) {
console.error('Error during activation:', error);
Expand Down
37 changes: 37 additions & 0 deletions src/services/claude-api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// src/services/claude-api.ts
import * as vscode from 'vscode';
import { askClaude as apiAskClaude, ClaudeResponse } from '../api';

export interface ClaudeApiService {
askClaude(text: string): Promise<ClaudeResponse>;
}

export class DefaultClaudeApiService implements ClaudeApiService {
private readonly _disposables: vscode.Disposable[] = [];

constructor() {
// Add any initialization if needed
}

async askClaude(text: string): Promise<ClaudeResponse> {
try {
return await apiAskClaude(text);
} catch (error) {
console.error('Error in DefaultClaudeApiService:', error);
throw error;
}
}

dispose(): void {
while (this._disposables.length) {
const disposable = this._disposables.pop();
if (disposable) {
try {
disposable.dispose();
} catch (error) {
console.error('Error disposing service:', error);
}
}
}
}
}

0 comments on commit 91dcf7a

Please sign in to comment.