From 737ab486d3800f66745d44f7d17e5bba4cb80df2 Mon Sep 17 00:00:00 2001 From: formulahendry Date: Sun, 20 Aug 2017 15:41:20 +0800 Subject: [PATCH] Fix #164: Make temporary file name not random by default; Support running code snippet in terminal --- .gitignore | 2 ++ CHANGELOG.md | 4 ++++ README.md | 2 ++ package.json | 7 ++++++- src/codeManager.ts | 6 ++++-- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8e5962e..2a55488 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ +.DS_Store +npm-debug.log out node_modules \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index ffb7cbc..b8cce9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +### 0.7.0 (2017-08-20) +* [#164](https://github.com/formulahendry/vscode-code-runner/issues/164): Make temporary file name not random by default +* Support running code snippet in terminal + ### 0.6.33 (2017-08-10) * [#149](https://github.com/formulahendry/vscode-code-runner/issues/149): Set custom terminal root path for Linux Shell on Windows diff --git a/README.md b/README.md index 35d4e43..09fa75a 100644 --- a/README.md +++ b/README.md @@ -145,6 +145,8 @@ To set whether to preserve focus on code editor after code run is triggered (def `code-runner.terminalRoot`: For Windows system, replaces the Windows style drive letter in the command with a Unix style root when using a custom shell as the terminal, like Bash or Cgywin. Example: Setting this to `/mnt/` will replace `C:\path` with `/mnt/c/path` (Default is **""**) +`code-runner.temporaryFileName`: Temporary file name used in running selected code snippet. When it is set as empty, the file name will be random. (Default is **"tempCodeRunnerFile"**) + ## About CWD Setting (current working directory) 1. By default, use the `code-runner.cwd` setting 2. If `code-runner.cwd` is not set and `code-runner.fileDirectoryAsCwd` is `true`, use the directory of the file to be executed diff --git a/package.json b/package.json index 6e9db85..c0fc9e2 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "code-runner", "displayName": "Code Runner", "description": "Run C, C++, Java, JS, PHP, Python, Perl, Ruby, Go, Lua, Groovy, PowerShell, CMD, BASH, F#, C#, VBScript, TypeScript, CoffeeScript, Scala, Swift, Julia, Crystal, OCaml, R, AppleScript, Elixir, VB.NET, Clojure, Haxe, Objective-C, Rust, Racket, AutoHotkey, AutoIt, Kotlin, Dart, Pascal, Haskell, Nim, D", - "version": "0.6.33", + "version": "0.7.0", "publisher": "formulahendry", "icon": "images/logo.png", "engines": { @@ -247,6 +247,11 @@ "type": "boolean", "default": true, "description": "Whether to show 'Run Code' icon in editor title menu." + }, + "code-runner.temporaryFileName": { + "type": "string", + "default": "tempCodeRunnerFile", + "description": "Temporary file name used in running selected code snippet. When it is set as empty, the file name will be random." } } }, diff --git a/src/codeManager.ts b/src/codeManager.ts index b471fdd..c2a2bf4 100644 --- a/src/codeManager.ts +++ b/src/codeManager.ts @@ -164,7 +164,9 @@ export class CodeManager { fileType = "." + this._languageId; } } - const tmpFileName = "temp" + this.rndName() + fileType; + const temporaryFileName = this._config.get("temporaryFileName"); + const tmpFileNameWithoutExt = temporaryFileName ? temporaryFileName : "temp" + this.rndName(); + const tmpFileName = tmpFileNameWithoutExt + fileType; this._codeFile = join(folder, tmpFileName); fs.writeFileSync(this._codeFile, content); } @@ -200,7 +202,7 @@ export class CodeManager { } private executeCommand(executor: string, appendFile: boolean = true) { - if (this._config.get("runInTerminal") && !this._isTmpFile) { + if (this._config.get("runInTerminal")) { this.executeCommandInTerminal(executor, appendFile); } else { this.executeCommandInOutputChannel(executor, appendFile);