Skip to content

Commit

Permalink
fix: terminal stuck
Browse files Browse the repository at this point in the history
  • Loading branch information
lightumcc committed Dec 12, 2023
1 parent b69476c commit 6902e28
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
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": "cpc-interpreter-extension",
"displayName": "CAIE Pseudocode",
"description": "A VSCode language support extension of CAIE PseudoCode",
"version": "0.1.4",
"version": "0.1.5",
"publisher": "CreatechStudioShanghaiInc",
"icon": "image/icon.png",
"main": "src/extension.ts",
Expand Down
21 changes: 21 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const fs = require('fs');
let run_terminal_created = false;
let config_terminal_created = false;
let terminal;
let interpreterCloseListener;
const myCpcConfig = vscode.workspace.getConfiguration("myCpcConfig");

function saveCurrentFile() {
Expand Down Expand Up @@ -54,11 +55,30 @@ function devMode() {
terminal.show();
}

function registerInterpreterCloseEvent() {
vscode.window.onDidCloseTerminal((closedTerminal) => {
if (closedTerminal.name === 'CPC Interpreter') {
run_terminal_created = false;
}
if (closedTerminal.name === 'CPC Config') {
config_terminal_created = false;
}
});
}

function disposeInterpreterCloseEvent() {
if (interpreterCloseListener) {
interpreterCloseListener.dispose();
interpreterCloseListener = undefined;
}
}

function activate(context) {
const interpreterPathConfig = myCpcConfig.get("interpreterPath") || "cpc";

executeCurrentFile(context);
registerUpdate(context);
registerInterpreterCloseEvent();

function executeCurrentFile(context) {
const command = 'cpc.run';
Expand Down Expand Up @@ -100,6 +120,7 @@ function deactivate() {
if (terminal) {
terminal.dispose();
}
disposeInterpreterCloseEvent();
}

module.exports = {
Expand Down
19 changes: 19 additions & 0 deletions src/extension.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const fs = require('fs');
let run_terminal_created = false;
let config_terminal_created = false;
let terminal;
let interpreterCloseListener;
const myCpcConfig = vscode.workspace.getConfiguration("myCpcConfig");
function saveCurrentFile() {
const { activeTextEditor } = vscode.window;
Expand Down Expand Up @@ -46,10 +47,27 @@ function devMode() {
terminal.sendText(`${interpreterPathConfig} -c dev ${devModeConfig}`);
terminal.show();
}
function registerInterpreterCloseEvent() {
vscode.window.onDidCloseTerminal((closedTerminal) => {
if (closedTerminal.name === 'CPC Interpreter') {
run_terminal_created = false;
}
if (closedTerminal.name === 'CPC Config') {
config_terminal_created = false;
}
});
}
function disposeInterpreterCloseEvent() {
if (interpreterCloseListener) {
interpreterCloseListener.dispose();
interpreterCloseListener = undefined;
}
}
function activate(context) {
const interpreterPathConfig = myCpcConfig.get("interpreterPath") || "cpc";
executeCurrentFile(context);
registerUpdate(context);
registerInterpreterCloseEvent();
function executeCurrentFile(context) {
const command = 'cpc.run';
const editor = vscode.window.activeTextEditor;
Expand Down Expand Up @@ -88,6 +106,7 @@ function deactivate() {
if (terminal) {
terminal.dispose();
}
disposeInterpreterCloseEvent();
}
module.exports = {
activate,
Expand Down

0 comments on commit 6902e28

Please sign in to comment.