diff --git a/src/extension.ts b/src/extension.ts index 115bd35..1840196 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -2,25 +2,64 @@ const vscode = require('vscode'); const path = require('path'); const fs = require('fs'); -let terminal_created = false; +let run_terminal_created = false; +let config_terminal_created = false; let terminal; const myCpcConfig = vscode.workspace.getConfiguration("myCpcConfig"); -function activate(context) { - console.log("Extension activated"); +function saveCurrentFile() { + const { activeTextEditor } = vscode.window; + if (activeTextEditor) { + activeTextEditor.document.save(); + } +} +function updateBranch() { const interpreterPathConfig = myCpcConfig.get("interpreterPath") || "cpc"; - - executeCurrentFile(context); - registerUpdate(context); + const updateBranchConfig = myCpcConfig.get("updateBranch") || "stable"; + const isWindows = process.platform.startsWith('win'); - function saveCurrentFile() { - const { activeTextEditor } = vscode.window; - if (activeTextEditor) { - activeTextEditor.document.save(); - } + if (!config_terminal_created) { + terminal = vscode.window.createTerminal('CPC Config'); + config_terminal_created = true; } + const cdCommand = isWindows ? `(Get-Command ${interpreterPathConfig} -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source | Split-Path -Parent | Split-Path -Parent) | Set-Location` : `cd $(which ${interpreterPathConfig})/../..`; + + terminal.sendText(`${interpreterPathConfig} -c branch ${updateBranchConfig}`); + terminal.sendText(`${cdCommand}`); + terminal.sendText(`git checkout -f ${updateBranchConfig}`) + terminal.show(); +} + +function updateRemote() { + const interpreterPathConfig = myCpcConfig.get("interpreterPath") || "cpc"; + const updateRemoteConfig = myCpcConfig.get("updateRemote") || "github"; + if (!config_terminal_created) { + terminal = vscode.window.createTerminal('CPC Config'); + config_terminal_created = true; + } + terminal.sendText(`${interpreterPathConfig} -c remote ${updateRemoteConfig}`); + terminal.show(); +} + +function devMode() { + const interpreterPathConfig = myCpcConfig.get("interpreterPath") || "cpc"; + const devModeConfig = myCpcConfig.get("devMode"); + if (!config_terminal_created) { + terminal = vscode.window.createTerminal('CPC Config'); + config_terminal_created = true; + } + terminal.sendText(`${interpreterPathConfig} -c dev ${devModeConfig}`); + terminal.show(); +} + +function activate(context) { + const interpreterPathConfig = myCpcConfig.get("interpreterPath") || "cpc"; + + executeCurrentFile(context); + registerUpdate(context); + function executeCurrentFile(context) { const command = 'cpc.run'; const editor = vscode.window.activeTextEditor; @@ -28,9 +67,9 @@ function activate(context) { if (editor) { const filePath = vscode.window.activeTextEditor.document.uri.fsPath; const decodedFilePath = decodeURI(filePath); - if (!terminal_created) { + if (!run_terminal_created) { terminal = vscode.window.createTerminal('CPC Interpreter'); - terminal_created = true; + run_terminal_created = true; } saveCurrentFile(); terminal.sendText(`${interpreterPathConfig} "${decodedFilePath}"`); @@ -43,9 +82,9 @@ function activate(context) { function registerUpdate(context) { const command = 'cpc.update'; const commandHandler = () => { - if (!terminal_created) { + if (!config_terminal_created) { terminal = vscode.window.createTerminal('CPC Config'); - terminal_created = true; + config_terminal_created = true; } devMode(); updateBranch(); @@ -53,7 +92,6 @@ function activate(context) { terminal.sendText(`${interpreterPathConfig} -u`); terminal.show(); }; - context.subscriptions.push(vscode.commands.registerCommand(command, commandHandler)); } } @@ -64,47 +102,6 @@ function deactivate() { } } -function updateBranch() { - const interpreterPathConfig = myCpcConfig.get("interpreterPath") || "cpc"; - const updateBranchConfig = myCpcConfig.get("updateBranch") || "stable"; - const scriptDir = interpreterPathConfig; - const isWindows = process.platform.startsWith('win'); - - if (!terminal_created) { - terminal = vscode.window.createTerminal('CPC Config'); - terminal_created = true; - } - - const cdCommand = isWindows ? `(Get-Command ${interpreterPathConfig} -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source | Split-Path -Parent | Split-Path -Parent) | Set-Location` : `cd $(which ${interpreterPathConfig})/../..`; - - terminal.sendText(`${interpreterPathConfig} -c branch ${updateBranchConfig}`); - terminal.sendText(`${cdCommand}`); - terminal.sendText(`git checkout ${updateBranchConfig}`) - terminal.show(); -} - -function updateRemote() { - const interpreterPathConfig = myCpcConfig.get("interpreterPath") || "cpc"; - const updateRemoteConfig = myCpcConfig.get("updateRemote") || "github"; - if (!terminal_created) { - terminal = vscode.window.createTerminal('CPC Config'); - terminal_created = true; - } - terminal.sendText(`${interpreterPathConfig} -c remote ${updateRemoteConfig}`); - terminal.show(); -} - -function devMode() { - const interpreterPathConfig = myCpcConfig.get("interpreterPath") || "cpc"; - const devModeConfig = myCpcConfig.get("devMode"); - if (!terminal_created) { - terminal = vscode.window.createTerminal('CPC Config'); - terminal_created = true; - } - terminal.sendText(`${interpreterPathConfig} -c dev ${devModeConfig}`); - terminal.show(); -} - module.exports = { activate, deactivate diff --git a/src/extension.ts.js b/src/extension.ts.js index d0b9c2a..0fc949e 100644 --- a/src/extension.ts.js +++ b/src/extension.ts.js @@ -2,20 +2,54 @@ const vscode = require('vscode'); const path = require('path'); const fs = require('fs'); -let terminal_created = false; +let run_terminal_created = false; +let config_terminal_created = false; let terminal; const myCpcConfig = vscode.workspace.getConfiguration("myCpcConfig"); +function saveCurrentFile() { + const { activeTextEditor } = vscode.window; + if (activeTextEditor) { + activeTextEditor.document.save(); + } +} +function updateBranch() { + const interpreterPathConfig = myCpcConfig.get("interpreterPath") || "cpc"; + const updateBranchConfig = myCpcConfig.get("updateBranch") || "stable"; + const isWindows = process.platform.startsWith('win'); + if (!config_terminal_created) { + terminal = vscode.window.createTerminal('CPC Config'); + config_terminal_created = true; + } + const cdCommand = isWindows ? `(Get-Command ${interpreterPathConfig} -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source | Split-Path -Parent | Split-Path -Parent) | Set-Location` : `cd $(which ${interpreterPathConfig})/../..`; + terminal.sendText(`${interpreterPathConfig} -c branch ${updateBranchConfig}`); + terminal.sendText(`${cdCommand}`); + terminal.sendText(`git checkout -f ${updateBranchConfig}`); + terminal.show(); +} +function updateRemote() { + const interpreterPathConfig = myCpcConfig.get("interpreterPath") || "cpc"; + const updateRemoteConfig = myCpcConfig.get("updateRemote") || "github"; + if (!config_terminal_created) { + terminal = vscode.window.createTerminal('CPC Config'); + config_terminal_created = true; + } + terminal.sendText(`${interpreterPathConfig} -c remote ${updateRemoteConfig}`); + terminal.show(); +} +function devMode() { + const interpreterPathConfig = myCpcConfig.get("interpreterPath") || "cpc"; + const devModeConfig = myCpcConfig.get("devMode"); + if (!config_terminal_created) { + terminal = vscode.window.createTerminal('CPC Config'); + config_terminal_created = true; + } + terminal.sendText(`${interpreterPathConfig} -c dev ${devModeConfig}`); + terminal.show(); +} function activate(context) { - console.log("Extension activated"); const interpreterPathConfig = myCpcConfig.get("interpreterPath") || "cpc"; executeCurrentFile(context); registerUpdate(context); - function saveCurrentFile() { - const { activeTextEditor } = vscode.window; - if (activeTextEditor) { - activeTextEditor.document.save(); - } - } function executeCurrentFile(context) { const command = 'cpc.run'; const editor = vscode.window.activeTextEditor; @@ -23,9 +57,9 @@ function activate(context) { if (editor) { const filePath = vscode.window.activeTextEditor.document.uri.fsPath; const decodedFilePath = decodeURI(filePath); - if (!terminal_created) { + if (!run_terminal_created) { terminal = vscode.window.createTerminal('CPC Interpreter'); - terminal_created = true; + run_terminal_created = true; } saveCurrentFile(); terminal.sendText(`${interpreterPathConfig} "${decodedFilePath}"`); @@ -37,9 +71,9 @@ function activate(context) { function registerUpdate(context) { const command = 'cpc.update'; const commandHandler = () => { - if (!terminal_created) { + if (!config_terminal_created) { terminal = vscode.window.createTerminal('CPC Config'); - terminal_created = true; + config_terminal_created = true; } devMode(); updateBranch(); @@ -55,41 +89,6 @@ function deactivate() { terminal.dispose(); } } -function updateBranch() { - const interpreterPathConfig = myCpcConfig.get("interpreterPath") || "cpc"; - const updateBranchConfig = myCpcConfig.get("updateBranch") || "stable"; - const scriptDir = interpreterPathConfig; - const isWindows = process.platform.startsWith('win'); - if (!terminal_created) { - terminal = vscode.window.createTerminal('CPC Config'); - terminal_created = true; - } - const cdCommand = isWindows ? `(Get-Command ${interpreterPathConfig} -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Source | Split-Path -Parent | Split-Path -Parent) | Set-Location` : `cd $(which ${interpreterPathConfig})/../..`; - terminal.sendText(`${interpreterPathConfig} -c branch ${updateBranchConfig}`); - terminal.sendText(`${cdCommand}`); - terminal.sendText(`git checkout ${updateBranchConfig}`); - terminal.show(); -} -function updateRemote() { - const interpreterPathConfig = myCpcConfig.get("interpreterPath") || "cpc"; - const updateRemoteConfig = myCpcConfig.get("updateRemote") || "github"; - if (!terminal_created) { - terminal = vscode.window.createTerminal('CPC Config'); - terminal_created = true; - } - terminal.sendText(`${interpreterPathConfig} -c remote ${updateRemoteConfig}`); - terminal.show(); -} -function devMode() { - const interpreterPathConfig = myCpcConfig.get("interpreterPath") || "cpc"; - const devModeConfig = myCpcConfig.get("devMode"); - if (!terminal_created) { - terminal = vscode.window.createTerminal('CPC Config'); - terminal_created = true; - } - terminal.sendText(`${interpreterPathConfig} -c dev ${devModeConfig}`); - terminal.show(); -} module.exports = { activate, deactivate