Skip to content

Commit

Permalink
Minor fix for running custom command when there is no active editor w…
Browse files Browse the repository at this point in the history
…indow
  • Loading branch information
formulahendry committed Dec 3, 2016
1 parent b86df35 commit b5610e3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### 0.6.1
* Minor fix for running custom command when there is no active editor window

### 0.6.0
* Add support to run custom command

Expand Down
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": "code-runner",
"displayName": "Code Runner",
"description": "Run code snippet/file for C, C++, Java, JS, PHP, Python, Perl, Ruby, Go, Lua, Groovy, PowerShell, BAT/CMD, BASH/SH, F#, C#, VBScript, TypeScript, CoffeeScript, Scala, Swift, Julia, Crystal, OCaml, and custom command",
"version": "0.6.0",
"version": "0.6.1",
"publisher": "formulahendry",
"icon": "images/logo.png",
"engines": {
Expand Down
31 changes: 17 additions & 14 deletions src/codeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,21 +242,24 @@ export class CodeManager {
* @return the complete command to run the file, that includes the file name
*/
private getFinalCommandToRunCodeFile(executor: string, appendFile: boolean = true): string {
var placeholders: { regex: RegExp, replaceValue: string }[] = [
//A placeholder that has to be replaced by the code file name without its extension
{ "regex": /\$fileNameWithoutExt/g, "replaceValue": this.getCodeFileWithoutDirAndExt() },
//A placeholder that has to be replaced by the full code file name
{ "regex": /\$fullFileName/g, "replaceValue": this.quoteFileName(this._codeFile) },
//A placeholder that has to be replaced by the code file name without the directory
{ "regex": /\$fileName/g, "replaceValue": this.getCodeBaseFile() },
//A placeholder that has to be replaced by the directory of the code file
{ "regex": /\$dir/g, "replaceValue": this.quoteFileName(this.getCodeFileDir()) }
];

var cmd = executor
placeholders.forEach(placeholder => {
cmd = cmd.replace(placeholder.regex, placeholder.replaceValue)
});

if (this._codeFile) {
var placeholders: { regex: RegExp, replaceValue: string }[] = [
//A placeholder that has to be replaced by the code file name without its extension
{ "regex": /\$fileNameWithoutExt/g, "replaceValue": this.getCodeFileWithoutDirAndExt() },
//A placeholder that has to be replaced by the full code file name
{ "regex": /\$fullFileName/g, "replaceValue": this.quoteFileName(this._codeFile) },
//A placeholder that has to be replaced by the code file name without the directory
{ "regex": /\$fileName/g, "replaceValue": this.getCodeBaseFile() },
//A placeholder that has to be replaced by the directory of the code file
{ "regex": /\$dir/g, "replaceValue": this.quoteFileName(this.getCodeFileDir()) }
];

placeholders.forEach(placeholder => {
cmd = cmd.replace(placeholder.regex, placeholder.replaceValue)
});
}

return (cmd != executor ? cmd : executor + (appendFile ? ' ' + this.quoteFileName(this._codeFile) : ''));
}
Expand Down

0 comments on commit b5610e3

Please sign in to comment.