Skip to content

Commit cc89228

Browse files
committed
Move restart to separate function for clarity
1 parent e23a7e6 commit cc89228

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/extension.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,8 @@ const documentSelector: DocumentSelector = [
4343

4444
export async function activate(context: vscode.ExtensionContext): Promise<IPowerShellExtensionClient> {
4545
logger = new Logger();
46-
// Enables a reload-on-save for faster development
4746
if (context.extensionMode === vscode.ExtensionMode.Development) {
48-
const watcher = vscode.workspace.createFileSystemWatcher(
49-
new vscode.RelativePattern(context.extensionPath, "dist/*.js"),
50-
);
51-
52-
context.subscriptions.push(watcher);
53-
watcher.onDidChange(({ fsPath }) => {
54-
vscode.window.showInformationMessage(`${fsPath.split(context.extensionPath,2)[1]} changed. Reloading Extension Host...`);
55-
vscode.commands.executeCommand("workbench.action.restartExtensionHost");
56-
});
47+
restartOnExtensionFileChanges(context);
5748
}
5849

5950
// Register a command that waits for the Externsion Terminal to be active. Can be used by .NET Attach Tasks
@@ -229,6 +220,19 @@ export async function activate(context: vscode.ExtensionContext): Promise<IPower
229220
};
230221
}
231222

223+
/** Restarts the extension host when extension file changes are detected. Useful for development.. */
224+
function restartOnExtensionFileChanges(context: vscode.ExtensionContext): void {
225+
const watcher = vscode.workspace.createFileSystemWatcher(
226+
new vscode.RelativePattern(context.extensionPath, "dist/*.js")
227+
);
228+
229+
context.subscriptions.push(watcher);
230+
watcher.onDidChange(({ fsPath }) => {
231+
vscode.window.showInformationMessage(`${fsPath.split(context.extensionPath, 2)[1]} changed. Reloading Extension Host...`);
232+
vscode.commands.executeCommand("workbench.action.restartExtensionHost");
233+
});
234+
}
235+
232236
export async function deactivate(): Promise<void> {
233237
// Clean up all extension features
234238
for (const commandRegistration of commandRegistrations) {

0 commit comments

Comments
 (0)