Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

> **Note**: odd version numbers, for example, `0.13.0`, are not included in this changelog. They are used to test the new features and fixes before the final release.

## [1.0.0] - Unreleased
## [1.0.1] - Unreleased

### Changed:

- Snippets: All snippets that reference schemas updated to use `v1.0.0` schema

### Fixed:

- Runtime error: Fixed issue where the extension would throw an uncaught exception when running

## [0.27.0] - 2025-06-30

### Added:
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dev-proxy-toolkit",
"displayName": "Dev Proxy Toolkit",
"description": "Makes it easy to create and update Dev Proxy configuration files.",
"version": "1.0.0",
"version": "1.0.1",
"publisher": "garrytrinder",
"engines": {
"vscode": "^1.101.0"
Expand Down
55 changes: 31 additions & 24 deletions src/documents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,42 @@ import { updateFileDiagnostics, updateConfigFileDiagnostics } from './diagnostic
export const registerDocumentListeners = (context: vscode.ExtensionContext, collection: vscode.DiagnosticCollection) => {
context.subscriptions.push(
vscode.workspace.onDidOpenTextDocument(document => {
if (isProxyFile(document)) {
updateFileDiagnostics(context, document, collection);
vscode.commands.executeCommand('setContext', 'isDevProxyConfigFile', false);
}
if (!isConfigFile(document)) {
vscode.commands.executeCommand('setContext', 'isDevProxyConfigFile', false);
return;
} else {
vscode.commands.executeCommand('setContext', 'isDevProxyConfigFile', true);
updateConfigFileDiagnostics(context, document, collection);
try {
if (isProxyFile(document)) {
updateFileDiagnostics(context, document, collection);
vscode.commands.executeCommand('setContext', 'isDevProxyConfigFile', false);
}
if (!isConfigFile(document)) {
vscode.commands.executeCommand('setContext', 'isDevProxyConfigFile', false);
return;
} else {
vscode.commands.executeCommand('setContext', 'isDevProxyConfigFile', true);
updateConfigFileDiagnostics(context, document, collection);
}
} catch (error) {
console.error('Error handling document open:', error);
}
})
);

context.subscriptions.push(
vscode.workspace.onDidChangeTextDocument(event => {
if (!isConfigFile(event.document) && !isProxyFile(event.document)) {
collection.delete(event.document.uri);
vscode.commands.executeCommand('setContext', 'isDevProxyConfigFile', false);
return;
}
if (isConfigFile(event.document)) {
updateConfigFileDiagnostics(context, event.document, collection);
vscode.commands.executeCommand('setContext', 'isDevProxyConfigFile', true);
return;
}
if (isProxyFile(event.document)) {
updateFileDiagnostics(context, event.document, collection);
vscode.commands.executeCommand('setContext', 'isDevProxyConfigFile', false);
try {
if (!isConfigFile(event.document) && !isProxyFile(event.document)) {
collection.delete(event.document.uri);
return;
}
if (isConfigFile(event.document)) {
updateConfigFileDiagnostics(context, event.document, collection);
vscode.commands.executeCommand('setContext', 'isDevProxyConfigFile', true);
return;
}
if (isProxyFile(event.document)) {
updateFileDiagnostics(context, event.document, collection);
vscode.commands.executeCommand('setContext', 'isDevProxyConfigFile', false);
}
} catch (error) {
console.error('Error handling document change:', error);
}
})
);
Expand All @@ -58,4 +65,4 @@ export const registerDocumentListeners = (context: vscode.ExtensionContext, coll
});
})
);
};
};
33 changes: 31 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { VersionPreference } from './enums';
import { registerMcpServer } from './mcp';
import { registerTaskProvider } from './taskprovider';

// Global variable to track the interval
let statusBarInterval: NodeJS.Timeout | undefined;

export const activate = async (context: vscode.ExtensionContext): Promise<vscode.ExtensionContext> => {

const configuration = vscode.workspace.getConfiguration('dev-proxy-toolkit');
Expand All @@ -19,6 +22,8 @@ export const activate = async (context: vscode.ExtensionContext): Promise<vscode
await updateGlobalState(context, versionPreference);

const collection = vscode.languages.createDiagnosticCollection('dev-proxy-toolkit');
// Add collection to subscriptions for automatic disposal
context.subscriptions.push(collection);

registerDocumentListeners(context, collection);
registerCodeActions(context);
Expand All @@ -32,9 +37,33 @@ export const activate = async (context: vscode.ExtensionContext): Promise<vscode

updateStatusBar(context, statusBar);

setInterval(() => statusBarLoop(context, statusBar, versionPreference), 5000);
// Store the interval reference for proper cleanup
statusBarInterval = setInterval(() => {
// Add error handling to prevent uncaught exceptions
try {
statusBarLoop(context, statusBar, versionPreference);
} catch (error) {
console.error('Error in statusBarLoop:', error);
}
}, 5000);

// Add the interval to subscriptions for automatic cleanup
context.subscriptions.push({
dispose: () => {
if (statusBarInterval) {
clearInterval(statusBarInterval);
statusBarInterval = undefined;
}
}
});

return context;
};

export const deactivate = () => { };
export const deactivate = () => {
// Clean up the interval if it's still running
if (statusBarInterval) {
clearInterval(statusBarInterval);
statusBarInterval = undefined;
}
};
28 changes: 21 additions & 7 deletions src/statusbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,24 @@ export const handleStatusBarUpdate = (context: vscode.ExtensionContext, statusBa
};

export const statusBarLoop = async (context: vscode.ExtensionContext, statusBar: vscode.StatusBarItem, versionPreference: VersionPreference) => {
const devProxyExe = getDevProxyExe(versionPreference);
const isRunning = await isDevProxyRunning(devProxyExe);
const globalState = context.globalState.get<DevProxyInstall>('devProxyInstall');
await context.globalState.update('devProxyInstall', { ...globalState, isRunning });
vscode.commands.executeCommand('setContext', 'isDevProxyRunning', isRunning);
updateStatusBar(context, statusBar);
};
try {
// Check if the context is still valid
if (!context || !statusBar) {
return;
}

const devProxyExe = getDevProxyExe(versionPreference);
const isRunning = await isDevProxyRunning(devProxyExe);
const globalState = context.globalState.get<DevProxyInstall>('devProxyInstall');

// Only update if context is still valid
if (context.globalState) {
await context.globalState.update('devProxyInstall', { ...globalState, isRunning });
vscode.commands.executeCommand('setContext', 'isDevProxyRunning', isRunning);
updateStatusBar(context, statusBar);
}
} catch (error) {
// Log but don't throw to prevent extension crashes
console.error('Error in statusBarLoop:', error);
}
};
Loading