Skip to content
This repository has been archived by the owner on Dec 23, 2021. It is now read-only.

Fix extension event listener #17

Merged
merged 1 commit into from
Jun 19, 2019
Merged
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
12 changes: 10 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export function activate(context: vscode.ExtensionContext) {

let currentPanel: vscode.WebviewPanel | undefined = undefined;
let childProcess: cp.ChildProcess;
let messageListener: vscode.Disposable;

// Add our library path to settings.json for autocomplete functionality
updatePythonExtraPaths();
Expand Down Expand Up @@ -77,7 +78,7 @@ export function activate(context: vscode.ExtensionContext) {
const scriptPath = onDiskPath.with({ scheme: "vscode-resource" });

// Create the Python process (after killing the one running if any)
if (childProcess != undefined) {
if (childProcess !== undefined) {
// TODO: We need to check the process was correctly killed
childProcess.kill();
}
Expand Down Expand Up @@ -116,8 +117,15 @@ export function activate(context: vscode.ExtensionContext) {
console.log(`Command execution exited with code: ${code}`);
});

if (messageListener !== undefined) {
messageListener.dispose();
const index = context.subscriptions.indexOf(messageListener);
if (index > -1) {
context.subscriptions.splice(index, 1);
}
}
// Handle messages from webview
currentPanel.webview.onDidReceiveMessage(
messageListener = currentPanel.webview.onDidReceiveMessage(
message => {
switch (message.command) {
case "button-press":
Expand Down