├── .gitattributes ├── .gitignore ├── config.json ├── images └── Exet_logo_2.png ├── .vscode-test.mjs ├── .vscodeignore ├── src ├── executorMap.json ├── test │ └── extension.test.ts ├── extension.ts └── RunManager.ts ├── .vscode ├── extensions.json ├── tasks.json ├── settings.json └── launch.json ├── CHANGELOG.md ├── tsconfig.json ├── .eslintrc.json ├── vsc-extension-quickstart.md ├── README.md └── package.json /.gitattributes: -------------------------------------------------------------------------------- 1 | *.mp4 filter=lfs diff=lfs merge=lfs -text 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | out 2 | dist 3 | node_modules 4 | .vscode-test/ 5 | *.vsix 6 | bun.lockb 7 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "saveAllFilesBeforeRun":false, 3 | "runInTerminal":true 4 | } -------------------------------------------------------------------------------- /images/Exet_logo_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sahityaaryan/Exet/HEAD/images/Exet_logo_2.png -------------------------------------------------------------------------------- /.vscode-test.mjs: -------------------------------------------------------------------------------- 1 | import { defineConfig } from '@vscode/test-cli'; 2 | 3 | export default defineConfig({ 4 | files: 'out/test/**/*.test.js', 5 | }); 6 | -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | src/** 4 | .gitignore 5 | .yarnrc 6 | vsc-extension-quickstart.md 7 | **/tsconfig.json 8 | **/.eslintrc.json 9 | **/*.map 10 | **/*.ts 11 | **/.vscode-test.* 12 | -------------------------------------------------------------------------------- /src/executorMap.json: -------------------------------------------------------------------------------- 1 | { 2 | ".cpp": "cd $dir && (if not exist exetFiles mkdir exetFiles) & g++ $fileName -o exetFiles/$fileNameWithoutExt && $dir\\exetFiles\\$fileNameWithoutExt", 3 | ".java":"", 4 | ".js": "node" 5 | } 6 | 7 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "dbaeumer.vscode-eslint", 6 | "ms-vscode.extension-test-runner" 7 | ] 8 | } 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to the "exet" extension will be documented in this file. 4 | 5 | Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file. 6 | 7 | ## [Unreleased] 8 | 9 | - Initial release -------------------------------------------------------------------------------- /.vscode/tasks.json: -------------------------------------------------------------------------------- 1 | // See https://go.microsoft.com/fwlink/?LinkId=733558 2 | // for the documentation about the tasks.json format 3 | { 4 | "version": "2.0.0", 5 | "tasks": [ 6 | { 7 | "type": "npm", 8 | "script": "watch", 9 | "problemMatcher": "$tsc-watch", 10 | "isBackground": true, 11 | "presentation": { 12 | "reveal": "never" 13 | }, 14 | "group": { 15 | "kind": "build", 16 | "isDefault": true 17 | } 18 | } 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | "files.exclude": { 4 | "out": false // set this to true to hide the "out" folder with the compiled JS files 5 | }, 6 | "search.exclude": { 7 | "out": true // set this to false to include "out" folder in search results 8 | }, 9 | // Turn off tsc task auto detection since we have the necessary tasks as npm scripts 10 | "typescript.tsc.autoDetect": "off" 11 | } -------------------------------------------------------------------------------- /src/test/extension.test.ts: -------------------------------------------------------------------------------- 1 | import * as assert from 'assert'; 2 | 3 | // You can import and use all API from the 'vscode' module 4 | // as well as import your extension to test it 5 | import * as vscode from 'vscode'; 6 | // import * as myExtension from '../../extension'; 7 | 8 | suite('Extension Test Suite', () => { 9 | vscode.window.showInformationMessage('Start all tests.'); 10 | 11 | test('Sample test', () => { 12 | assert.strictEqual(-1, [1, 2, 3].indexOf(5)); 13 | assert.strictEqual(-1, [1, 2, 3].indexOf(0)); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "Node16", 4 | "target": "ES2022", 5 | "outDir": "out", 6 | "lib": [ 7 | "ES2022" 8 | ], 9 | "sourceMap": true, 10 | "rootDir": "src", 11 | "strict": false /* enable all strict type-checking options */ 12 | /* Additional Checks */ 13 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 14 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 15 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that compiles the extension and then opens it inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "Run Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "args": [ 13 | "--extensionDevelopmentPath=${workspaceFolder}" 14 | ], 15 | "outFiles": [ 16 | "${workspaceFolder}/out/**/*.js" 17 | ], 18 | "preLaunchTask": "${defaultBuildTask}" 19 | } 20 | ] 21 | } 22 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "parserOptions": { 5 | "ecmaVersion": 6, 6 | "sourceType": "module" 7 | }, 8 | "plugins": [ 9 | "@typescript-eslint" 10 | ], 11 | "rules": { 12 | "@typescript-eslint/naming-convention": [ 13 | "warn", 14 | { 15 | "selector": "import", 16 | "format": [ "camelCase", "PascalCase" ] 17 | } 18 | ], 19 | "@typescript-eslint/semi": "warn", 20 | "curly": "warn", 21 | "eqeqeq": "warn", 22 | "no-throw-literal": "warn", 23 | "semi": "off" 24 | }, 25 | "ignorePatterns": [ 26 | "out", 27 | "dist", 28 | "**/*.d.ts" 29 | ] 30 | } -------------------------------------------------------------------------------- /src/extension.ts: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | // The module 'vscode' contains the VS Code extensibility API 5 | // Import the module and reference it with the alias vscode in your code below 6 | import * as vscode from 'vscode'; 7 | import {RunManager} from "./RunManager"; 8 | 9 | // This method is called when your extension is activated 10 | // Your extension is activated the very first time the command is executed 11 | export function activate(context: vscode.ExtensionContext) { 12 | 13 | // Use the console to output diagnostic information (console.log) and errors (console.error) 14 | // This line of code will only be executed once when your extension is activated 15 | console.log('Congratulations, your extension "exet" is now active!'); 16 | 17 | 18 | //* The command has been defined in the package.json file 19 | //* Now provide the implementation of the command with registerCommand 20 | //* The commandId parameter must match the command field in package.json 21 | 22 | let disposable = vscode.commands.registerCommand("exet.helloWorld", () => { 23 | vscode.window.showInformationMessage("Hello Exet User"); 24 | }); 25 | 26 | 27 | // Corrected indentation for the 'run' command registration 28 | let run = vscode.commands.registerCommand("exet.run",async () => { 29 | 30 | try { 31 | const runCode = new RunManager(); 32 | // start the execution 33 | runCode.run(); 34 | } catch (e) { 35 | console.log("Error while execution: ",e); 36 | } 37 | 38 | }); 39 | 40 | context.subscriptions.push(disposable); 41 | context.subscriptions.push(run); 42 | } 43 | 44 | // This method is called when your extension is deactivated 45 | export function deactivate() { 46 | // console.log("deactivating 😎!!!"); 47 | } 48 | 49 | 50 | 51 | // Question 52 | 53 | // 1. what is the work of selection [done] 54 | 55 | // 2. how to setup the config for my extension [done] 56 | 57 | // 3. how to setup my executor map [done] 58 | 59 | //4. how to update my executor with the cwd in the executor map [done] 60 | 61 | 62 | //5. Updating the cli config for linux [done] 63 | 64 | // 6. How to create only one exetFile for the entire workspace [done] 65 | -------------------------------------------------------------------------------- /vsc-extension-quickstart.md: -------------------------------------------------------------------------------- 1 | # Welcome to your VS Code Extension 2 | 3 | ## What's in the folder 4 | 5 | * This folder contains all of the files necessary for your extension. 6 | * `package.json` - this is the manifest file in which you declare your extension and command. 7 | * The sample plugin registers a command and defines its title and command name. With this information VS Code can show the command in the command palette. It doesn’t yet need to load the plugin. 8 | * `src/extension.ts` - this is the main file where you will provide the implementation of your command. 9 | * The file exports one function, `activate`, which is called the very first time your extension is activated (in this case by executing the command). Inside the `activate` function we call `registerCommand`. 10 | * We pass the function containing the implementation of the command as the second parameter to `registerCommand`. 11 | 12 | ## Get up and running straight away 13 | 14 | * Press `F5` to open a new window with your extension loaded. 15 | * Run your command from the command palette by pressing (`Ctrl+Shift+P` or `Cmd+Shift+P` on Mac) and typing `Hello World`. 16 | * Set breakpoints in your code inside `src/extension.ts` to debug your extension. 17 | * Find output from your extension in the debug console. 18 | 19 | ## Make changes 20 | 21 | * You can relaunch the extension from the debug toolbar after changing code in `src/extension.ts`. 22 | * You can also reload (`Ctrl+R` or `Cmd+R` on Mac) the VS Code window with your extension to load your changes. 23 | 24 | ## Explore the API 25 | 26 | * You can open the full set of our API when you open the file `node_modules/@types/vscode/index.d.ts`. 27 | 28 | ## Run tests 29 | 30 | * Install the [Extension Test Runner](https://marketplace.visualstudio.com/items?itemName=ms-vscode.extension-test-runner) 31 | * Run the "watch" task via the **Tasks: Run Task** command. Make sure this is running, or tests might not be discovered. 32 | * Open the Testing view from the activity bar and click the Run Test" button, or use the hotkey `Ctrl/Cmd + ; A` 33 | * See the output of the test result in the Test Results view. 34 | * Make changes to `src/test/extension.test.ts` or create new test files inside the `test` folder. 35 | * The provided test runner will only consider files matching the name pattern `**.test.ts`. 36 | * You can create folders inside the `test` folder to structure your tests any way you want. 37 | 38 | ## Go further 39 | 40 | * [Follow UX guidelines](https://code.visualstudio.com/api/ux-guidelines/overview) to create extensions that seamlessly integrate with VS Code's native interface and patterns. 41 | * Reduce the extension size and improve the startup time by [bundling your extension](https://code.visualstudio.com/api/working-with-extensions/bundling-extension). 42 | * [Publish your extension](https://code.visualstudio.com/api/working-with-extensions/publishing-extension) on the VS Code extension marketplace. 43 | * Automate builds by setting up [Continuous Integration](https://code.visualstudio.com/api/working-with-extensions/continuous-integration). 44 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Exet 2 | 3 | Hello world from Exet! 4 | 5 | This extension provide smooth coding experience to the coders and programmers by managing the executable files like .exe (in cpp || c) 6 | or .class files (in java) or .js files (in Ts). 7 | 8 | This will create a separate folder for all the executable files of a particualr language and executable files of any file in any folder inside the workspace will be stored in this folder and will execute smoothly 9 | 10 | # How to run it? 11 | Just hit `ctrl+1` 12 | 13 | 14 | # Tutorials 15 | - [Complete setup (English)](https://www.youtube.com/watch?v=NzduTSxpZ6Y) 16 | - [Complete setup (Hindi)](https://www.youtube.com/watch?v=XpYY_aEnbJQ) 17 | - **Note**: There is no need of doing anything new for the `windows user as well` 😃 as **`described in the tutorial`**, just hit `ctrl+1`. 18 | 19 | ## Features 20 | 21 | 1. Handles the exe files for the C++ and C langauge in a single folder "exetFiles" so that your workspace will look clear and consistent 22 | 2. Handles the class files for the Java langauge in a single folder "exetClasses" so that your workspace will look clear and consistent 23 | 3. Handles the emittedJs files for the typescript in a single folder "exetEmittedJsFiles" to make your workspace clear and consistent 24 | 4. Run code per filename 25 | 5. Support REPL by running code in Integrated Terminal (default) 26 | 6. Supports langauges such as cpp, c , java, javascript, typescript 27 | 7. Can manage the executables of any script at any level of folder inside the workspace 28 | 29 | 30 | ## Requirements 31 | 32 | - To run typescript you must have typescript compiler in your system `tsc` 33 | 34 | ## Extension Settings 35 | 36 | This extension contributes the following settings: 37 | 38 | * `exet.enable`: Enable/disable this extension. 39 | * `exet.executorMap`: Executor map to map the extension name with the requrire execution command. 40 | * `exet.extensionNameMapByLanaguageId`: This is to map the extension name with the corresponding languageId. 41 | 42 | ## What I have not included 43 | 44 | - support for execute the command in the output terminal because the output channel can't take input and eventually the terminal can be used for both input and output. 45 | - Run from file explorer 46 | - SheBang support 47 | - Run by language 48 | 49 | ## Connect: 50 | 51 | * [Github](https://github.com/Sahityaaryan) 52 | * [LinkedIn](https://www.linkedin.com/in/sahityaaryan/) 53 | 54 | ## Note: 55 | 56 | * If you liked it then please consider putting reviews and ratings on it. It will help a lot to improve the extension. 57 | 58 | 59 | ## Following extension guidelines 60 | 61 | Ensure that you've read through the extensions guidelines and follow the best practices for creating your extension. 62 | 63 | * [Extension Guidelines](https://code.visualstudio.com/api/references/extension-guidelines) 64 | 65 | ## Working with Markdown 66 | 67 | You can author your README using Visual Studio Code. Here are some useful editor keyboard shortcuts: 68 | 69 | * Split the editor (`Cmd+\` on macOS or `Ctrl+\` on Windows and Linux). 70 | * Toggle preview (`Shift+Cmd+V` on macOS or `Shift+Ctrl+V` on Windows and Linux). 71 | * Press `Ctrl+Space` (Windows, Linux, macOS) to see a list of Markdown snippets. 72 | 73 | ## For more information 74 | 75 | * [Visual Studio Code's Markdown Support](http://code.visualstudio.com/docs/languages/markdown) 76 | * [Markdown Syntax Reference](https://help.github.com/articles/markdown-basics/) 77 | 78 | 79 | **Enjoy!** 80 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "exet", 3 | "displayName": "Exet", 4 | "publisher": "sahityaaryan", 5 | "description": "This extension will help the coders and programmers to manage the executable files at one place and hence make there workspace clear and consistent", 6 | "version": "1.4.2", 7 | "icon": "images/Exet_logo_2.png", 8 | "engines": { 9 | "vscode": "^1.85.0" 10 | }, 11 | "categories": [ 12 | "Programming Languages", 13 | "Other" 14 | ], 15 | "activationEvents": [], 16 | "main": "./out/extension.js", 17 | "repository": { 18 | "type": "git", 19 | "url": "https://github.com/Sahityaaryan/Exet" 20 | }, 21 | "contributes": { 22 | "commands": [ 23 | { 24 | "command": "exet.helloWorld", 25 | "title": "Hello World" 26 | }, 27 | { 28 | "command": "exet.run", 29 | "title": "Running" 30 | } 31 | ], 32 | "keybindings": [ 33 | { 34 | "command": "exet.run", 35 | "key": "ctrl+1" 36 | } 37 | ], 38 | "configuration": [ 39 | { 40 | "title": "Extension configuration", 41 | "properties": { 42 | "exet.executorMap": { 43 | "type": "object", 44 | "default": { 45 | "linux": { 46 | ".cpp": "cd @workSpace && ([[ ! -d exetFiles ]] & mkdir -p exetFiles) && cd @dir && g++ @fileName -o @workSpace/exetFiles/@fileNameWithoutExt && @workSpace/exetFiles/@fileNameWithoutExt", 47 | ".java": "cd @workSpace && ([[ ! -d exetClasses ]] & mkdir -p exetClasses) && cd @dir && javac -d @workSpace/exetClasses @fileName && java -classpath @workSpace/exetClasses @fileNameWithoutExt", 48 | ".c": "cd @workSpace && ([[ ! -d exetFiles ]] & mkdir -p exetFiles) && cd @dir && gcc @fileName -o @workSpace/exetFiles/@fileNameWithoutExt && @workSpace/exetFiles/@fileNameWithoutExt", 49 | ".js": " node @fileNameWithDir", 50 | ".ts": "cd @workSpace && ([[ ! -d exetEmittedJsFiles ]] & mkdir -p exetEmittedJsFiles) && cd @dir && tsc @fileName --outDir @workSpace/exetEmittedJsFiles && node @workSpace/exetEmittedJsFiles/@fileNameWithoutExt.js", 51 | ".py": "python3 @fileNameWithDir" 52 | }, 53 | "darwin": { 54 | ".cpp": "cd @workSpace && ([[ ! -d exetFiles ]] & mkdir -p exetFiles) && cd @dir && g++ @fileName -o @workSpace/exetFiles/@fileNameWithoutExt && @workSpace/exetFiles/@fileNameWithoutExt", 55 | ".java": "cd @workSpace && ([[ ! -d exetClasses ]] & mkdir -p exetClasses) && cd @dir && javac -d @workSpace/exetClasses @fileName && java -classpath @workSpace/exetClasses @fileNameWithoutExt", 56 | ".c": "cd @workSpace && ([[ ! -d exetFiles ]] & mkdir -p exetFiles) && cd @dir && gcc @fileName -o @workSpace/exetFiles/@fileNameWithoutExt && @workSpace/exetFiles/@fileNameWithoutExt", 57 | ".js": "node @fileNameWithDir", 58 | ".ts": "cd @workSpace && ([[ ! -d exetEmittedJsFiles ]] & mkdir -p exetEmittedJsFiles) && cd @dir && tsc @fileName --outDir @workSpace/exetEmittedJsFiles && node @workSpace/exetEmittedJsFiles/@fileNameWithoutExt.js", 59 | ".py": "python3 @fileNameWithDir" 60 | }, 61 | "win32": { 62 | ".cpp": "Set-Location '@workSpace'; if (-not (Test-Path exetFiles)) { New-Item -ItemType Directory -Name exetFiles | Out-Null }; Set-Location '@dir'; g++ '@fileName' -o \"@workSpace\\exetFiles\\@fileNameWithoutExt\"; if ($?) { Write-Host \"\"; & \"@workSpace\\exetFiles\\@fileNameWithoutExt\" }", 63 | ".java": "Set-Location '@workSpace'; if (-not (Test-Path exetClasses)) { New-Item -ItemType Directory -Name exetClasses | Out-Null }; Set-Location '@dir'; javac -d \"@workSpace\\exetClasses\" '@fileName'; if ($?) { Write-Host \"\"; java -classpath \"@workSpace\\exetClasses\" @fileNameWithoutExt }", 64 | ".c": "Set-Location '@workSpace'; if (-not (Test-Path exetFiles)) { New-Item -ItemType Directory -Name exetFiles | Out-Null }; Set-Location '@dir'; gcc '@fileName' -o \"@workSpace\\exetFiles\\@fileNameWithoutExt\"; if ($?) { Write-Host \"\"; & \"@workSpace\\exetFiles\\@fileNameWithoutExt\" }", 65 | ".js": "node '@fileNameWithDir'", 66 | ".ts": "Set-Location '@workSpace'; if (-not (Test-Path exetEmittedJsFiles)) { New-Item -ItemType Directory -Name exetEmittedJsFiles | Out-Null }; Set-Location '@dir'; tsc '@fileName' --outDir \"@workSpace\\exetEmittedJsFiles\"; if ($?) { Write-Host \"\"; node \"@workSpace\\exetEmittedJsFiles\\@fileNameWithoutExt.js\" }", 67 | ".py": "python '@fileNameWithDir'" 68 | } 69 | }, 70 | "description": "This is the executor map which run appropriate execution commands for the corresponding extension name" 71 | }, 72 | "exet.extensionNameMapByLanaguageId": { 73 | "type": "object", 74 | "default": { 75 | ".cpp": "cpp", 76 | ".js": "javascript", 77 | ".ts": "typescript", 78 | ".java": "java", 79 | ".c": "c" 80 | }, 81 | "description": "This is to map the extension name with the languageId" 82 | } 83 | } 84 | } 85 | ] 86 | }, 87 | "scripts": { 88 | "vscode:prepublish": "npm run compile", 89 | "compile": "tsc -p ./", 90 | "watch": "tsc -watch -p ./", 91 | "pretest": "npm run compile && npm run lint", 92 | "lint": "eslint src --ext ts", 93 | "test": "vscode-test" 94 | }, 95 | "devDependencies": { 96 | "@types/mocha": "^10.0.6", 97 | "@types/node": ">=18.0.0", 98 | "@types/vscode": "^1.85.0", 99 | "@typescript-eslint/eslint-plugin": "^6.13.1", 100 | "@typescript-eslint/parser": "^6.13.1", 101 | "@vscode/test-cli": "^0.0.4", 102 | "@vscode/test-electron": "^2.3.8", 103 | "eslint": "^8.54.0", 104 | "typescript": "^5.3.2" 105 | }, 106 | "dependencies": { 107 | "vsce": "^2.15.0" 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /src/RunManager.ts: -------------------------------------------------------------------------------- 1 | 2 | 'use strict'; 3 | import * as fs from 'fs'; 4 | import * as vscode from "vscode"; 5 | import * as os from "os"; 6 | import * as path from "path"; 7 | 8 | 9 | 10 | export class RunManager implements vscode.Disposable { 11 | private terminal: vscode.Terminal | null; 12 | private isRunning: boolean = false; 13 | private workspaceFolder: string | undefined; 14 | private cwd: string | undefined; 15 | private showOutputOnOutputChannel: boolean = false; 16 | private executorMap: object | undefined; 17 | private config: vscode.WorkspaceConfiguration | undefined; 18 | private extensionNameMapByLanaguageId: object | undefined; 19 | private document: vscode.TextDocument | undefined; 20 | // private setAlias:boolean = true; 21 | 22 | 23 | constructor() { 24 | this.terminal = null; 25 | this.config = undefined; 26 | } 27 | 28 | public async run() { 29 | //the async function for running the document 30 | // 1.It checks if this file is already running; if so, it displays a message and returns. 31 | 32 | if (this.isRunning) { 33 | vscode.window.showInformationMessage("This File is already running!!!"); 34 | return; 35 | } 36 | 37 | //# here by this i ma assuming that the code is running from the vs code edotor itself and not from the file explorer 38 | const editor = vscode.window.activeTextEditor; 39 | 40 | if (editor) { 41 | //getting the document loaded at the editor 42 | this.document = editor.document; 43 | 44 | } else { 45 | vscode.window.showErrorMessage("No Code Found for execution ☹️"); 46 | return; 47 | } 48 | 49 | // if it truly running from the editor and not any other case so now is the best time to iniatialize some more properties 50 | 51 | this.initialize(); 52 | 53 | // this is to check the extension of the file and run the appropriate command according to the extension 54 | const fileExtension = path.extname(this.document.fileName); 55 | 56 | //this function is to provide the executor for the required extension 57 | const executor = this.getExecutor(fileExtension); 58 | 59 | if (executor === null) { 60 | vscode.window.showErrorMessage("This language is not supported 😞 !!!"); 61 | return; 62 | } 63 | 64 | //no after all further we process our file 65 | this.getCodeFileAndExecute(true, fileExtension, executor); 66 | } 67 | 68 | //A private method because I not want it to be accessible to any of the instances and some initialization are rest for the future 69 | private initialize() { 70 | 71 | //!why a config ? what is it's significance? 72 | //* to get access of configurations of the extension which i have setted 73 | this.config = vscode.workspace.getConfiguration("exet", this.document.uri); 74 | 75 | //* here I don't allow the user to set the cwd on there own may be the feature appear in the future 76 | 77 | // we need to have the workspace folder path 78 | 79 | //for that we have to get the workspace folders 80 | 81 | //if we had some file to execute then we will search for the workspace folder 82 | this.workspaceFolder = this.document 83 | ? this.getWorkSpaceFolder() 84 | : undefined; 85 | 86 | 87 | // console.log("workspaceFolder: ",this.workspaceFolder); 88 | // vscode.window.showInformationMessage(this.workspaceFolder); 89 | if (!this.workspaceFolder && this.document && !this.document.isUntitled) { 90 | // if we have the file only in the workspace we will assign its path as the cwd 91 | this.cwd = path.dirname(this.document.fileName); 92 | 93 | } else { 94 | //if we have the workspacefolder then this would be relevant to be the cwd 95 | this.cwd = this.workspaceFolder; 96 | } 97 | } 98 | 99 | private getWorkSpaceFolder() { 100 | const foldersArray = vscode.workspace.workspaceFolders; 101 | 102 | //here if ther are many folders then we have to choose either the relevant one or the first one 103 | if (foldersArray) { 104 | const workspaceFolder: vscode.WorkspaceFolder | undefined = 105 | vscode.workspace.getWorkspaceFolder(this.document.uri); 106 | 107 | //if our code is within some folder then we would provide the folder path 108 | 109 | if (workspaceFolder) { 110 | return workspaceFolder.uri.fsPath; // returns string 111 | } 112 | 113 | return foldersArray[0].uri.fsPath; 114 | } 115 | //if we didn't event found the folders Array then we will return undefined may be because there is no other folder in the workspace may be a file only 116 | 117 | return undefined; 118 | } 119 | 120 | private getExecutor(fileExtension: string) { 121 | //letting the user know the file is srunning 122 | this.isRunning = true; 123 | 124 | //* the identification is solely depended over the fileExtension 125 | 126 | 127 | let executor = null; 128 | 129 | if (!fileExtension) { 130 | vscode.window.showInformationMessage("Can't execute an unknown file 😐"); 131 | return executor; 132 | } 133 | 134 | //here we will leverage the executor mapping from the file's extension 135 | 136 | //! this is the map of executor to the extension name 137 | 138 | const workspaceConfig = vscode.workspace.getConfiguration("exet"); 139 | this.executorMap = workspaceConfig.get("executorMap"); 140 | 141 | const executorMap = this.executorMap; 142 | 143 | // console.log("this is the executor map : ",executorMap); 144 | 145 | if (!executorMap || executorMap === undefined) { 146 | vscode.window.showErrorMessage("Something went wrong (Executor Map)"); 147 | return; 148 | } 149 | 150 | for (let platform of Object.keys(executorMap)) { 151 | 152 | if (platform === this.osPlatform()) { 153 | const osPlatform = executorMap[platform]; 154 | for (let ext of Object.keys(osPlatform)) { 155 | if (ext === fileExtension) { 156 | executor = osPlatform[ext]; 157 | break; 158 | } 159 | } 160 | 161 | } 162 | } 163 | 164 | if (executor === undefined || !executor) { 165 | vscode.window.showErrorMessage("Can't find the appropriate executor may be the language is not supported 🥲"); 166 | return; 167 | 168 | } 169 | return executor; 170 | 171 | //~ Function to add the unknow language support 172 | } 173 | 174 | private getCodeFileAndExecute( 175 | appendFile: boolean = true, 176 | fileExtension: string, 177 | executor: string 178 | ) { 179 | //Executing the command in the integrated terminal 180 | 181 | const activeTextEditor = vscode.window.activeTextEditor; 182 | 183 | //if all the extensions is configured to save all files before run then do so 184 | 185 | if (this.config.get("saveAllFilesBeforeRun")) { 186 | return vscode.workspace.saveAll().then(() => { 187 | this.executeCommand(executor, appendFile); 188 | }); 189 | } 190 | 191 | //I am explicitely assuming that the code file is runned from the editor 192 | 193 | return this.document.save().then(() => { 194 | this.executeCommand(executor, appendFile); 195 | }); 196 | } 197 | 198 | private executeCommand(executor: string, appendFile: boolean) { 199 | 200 | //again asking my configuration to run form terminal or from the output terminal 201 | 202 | this.executeCommandInTerminal(executor, appendFile); 203 | } 204 | 205 | //executing command from terminal 206 | 207 | private executeCommandInTerminal( 208 | executor: string, 209 | appendFile: boolean = true 210 | ) { 211 | if (!this.terminal) { 212 | 213 | const _doc: vscode.TextDocument = this.document; 214 | 215 | const fileProps = { 216 | fileName: path.basename(_doc?.fileName), 217 | fileNameWithoutExt: path 218 | .basename(_doc.fileName) 219 | .replace(/(\.)[a-zA-Z]+$/, ""), 220 | dir: path.dirname(_doc.fileName), 221 | workSpace: this.workspaceFolder, 222 | fileNameWithDir: _doc.fileName, 223 | }; 224 | 225 | 226 | 227 | executor = this.setExecutorVariables(fileProps, executor, this.osPlatform()); 228 | 229 | //I will set the terminal (to open the terminal default) 230 | const terminals = vscode.window.terminals; 231 | this.terminal = terminals 232 | ? terminals[0] 233 | : vscode.window.createTerminal("NewTerm"); // the first terminal will execute our output or new terminal will be created 234 | 235 | } 236 | 237 | //! the file below is important i have commented them for a while 238 | 239 | if (this.terminal === undefined 240 | || this.terminal === null) { 241 | // vscode.window.showInformationMessage("Please set the terminal!!"); 242 | this.terminal = vscode.window.createTerminal("Code"); 243 | } 244 | 245 | // console.log("os of the platform is: ",this.osPlatform()); 246 | // console.log("terminal: ",this.terminal) 247 | // if(this.terminal == undefined || this.terminal==null) 248 | // { 249 | // vscode.window.createTerminal("NewTerm"); 250 | // console.log("terminal: ",this.terminal); 251 | // } 252 | // this.terminal = null; 253 | 254 | 255 | (this.terminal || this.terminal !== undefined) ? this.terminal.show(true) : vscode.window.showErrorMessage("Something went wrong will generating output at terminal"); 256 | 257 | 258 | const ext = path.extname(path.basename(this.document.fileName)); 259 | 260 | 261 | 262 | 263 | //! Excatly here I have to build the feature for updating the PowerShell version 264 | 265 | //finally the command will be written on the terminal 266 | 267 | 268 | 269 | this.terminal.sendText(executor, appendFile); 270 | 271 | // if(!this.showOutputOnOutputChannel) 272 | // {this.terminal.sendText(executor, appendFile);} 273 | 274 | // else { 275 | // this.runFromTheOutputChannel(executor,ext); 276 | // } 277 | 278 | 279 | 280 | this.isRunning = false; 281 | 282 | 283 | //now cretaing the progress bar like thing 284 | 285 | 286 | // const statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left); 287 | 288 | // statusBarItem.text = 'Progress 0%'; 289 | 290 | // function updateProgress(progress: number) { 291 | // statusBarItem.text = `Progress: ${progress}%`; 292 | // statusBarItem.show(); 293 | // } 294 | 295 | 296 | 297 | } 298 | 299 | private setExecutorVariables(fileProps: { 300 | fileName: string; 301 | fileNameWithoutExt: string; 302 | dir: string; 303 | workSpace: string; 304 | fileNameWithDir: string; 305 | }, executor: string, platform: string) { 306 | //* here I am checking that whether this patterns match in the overall executor string 307 | 308 | const varCheckerAndReplace = [ 309 | { variable: /\@dir/g, replaceStatement: fileProps.dir }, 310 | { variable: /\@fileNameWithDir/g, replaceStatement: fileProps.fileNameWithDir }, 311 | { variable: /\@fileNameWithoutExt/g, replaceStatement: fileProps.fileNameWithoutExt }, 312 | { variable: /\@workSpace/g, replaceStatement: fileProps.workSpace }, 313 | { variable: /\@fileName/g, replaceStatement: fileProps.fileName }, 314 | ]; 315 | 316 | 317 | for (const keys of varCheckerAndReplace) { 318 | executor = executor.replace(keys.variable, keys.replaceStatement); 319 | } 320 | 321 | 322 | return executor; 323 | } 324 | 325 | private osPlatform() { 326 | return os.platform(); 327 | } 328 | 329 | 330 | 331 | // private runFromTheOutputChannel(executor:string,ext:string) 332 | // { 333 | 334 | // const workspaceConfig = vscode.workspace.getConfiguration("exet"); 335 | 336 | // this.extensionNameMapByLanaguageId = workspaceConfig.get("extensionNameMapByLanaguageId"); 337 | 338 | // if(this.extensionNameMapByLanaguageId == undefined || !this.extensionNameMapByLanaguageId) 339 | // { 340 | // console.log( 341 | // "not able to find the languageId object" 342 | // ); 343 | // return; 344 | // } 345 | 346 | // let languageId; 347 | 348 | // for(let keys of Object.keys(this.extensionNameMapByLanaguageId)) 349 | // { 350 | // if(keys===ext) 351 | // { 352 | // languageId = this.extensionNameMapByLanaguageId[ext]; 353 | // } 354 | // } 355 | 356 | 357 | 358 | 359 | 360 | // const output_ = vscode.window.createOutputChannel(`Output.${languageId}`,languageId); 361 | 362 | // output_.show(); 363 | 364 | // output_.append(executor); 365 | // } 366 | 367 | // this is of no use kindly ignore it 368 | public dispose(): void { 369 | console.log("RunManager disposed"); 370 | } 371 | 372 | } 373 | 374 | 375 | 376 | //! why micromatch over minimatch and the vscode.languages.match? 377 | 378 | // * micromatch (advance and can able to handle complex search) > minimatch 379 | 380 | --------------------------------------------------------------------------------