Skip to content

Commit

Permalink
update: structure & fix: unsubmitted file
Browse files Browse the repository at this point in the history
  • Loading branch information
lightumcc committed Nov 12, 2023
1 parent 90bb35f commit 4b3d3b5
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 104 deletions.
111 changes: 54 additions & 57 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,74 @@ 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;
const commandHandler = () => {
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}"`);
Expand All @@ -43,17 +82,16 @@ 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();
updateRemote();
terminal.sendText(`${interpreterPathConfig} -u`);
terminal.show();
};

context.subscriptions.push(vscode.commands.registerCommand(command, commandHandler));
}
}
Expand All @@ -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
Expand Down
93 changes: 46 additions & 47 deletions src/extension.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +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 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;
const commandHandler = () => {
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}"`);
Expand All @@ -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();
Expand All @@ -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
Expand Down

0 comments on commit 4b3d3b5

Please sign in to comment.