Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ To set whether to preserve focus on code editor after code run is triggered (def

`code-runner.ignoreSelection`: Whether to ignore selection to always run entire file. (Default is **false**)

`code-runner.showRunIconInEditorTitleMenu`: Whether to show 'Run Code' icon in editor title menu. (Default is **true**)
`code-runner.onlyShowRunIconIfExecutorExists`: Whether to only show 'Run Code' icon in editor title menu if the current file can be ran. If false, the icon will show for every file. (Default is **true**)

`code-runner.showRunIconInEditorTitleMenu`: Whether to show 'Run Code' icon in editor title menu. If false, overrides `code-runner.onlyShowRunIconIfExecutorExists` setting. (Default is **true**)

`code-runner.showRunCommandInEditorContextMenu`: Whether to show 'Run Code' command in editor context menu. (Default is **true**)

Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
],
"editor/title/run": [
{
"when": "config.code-runner.showRunIconInEditorTitleMenu",
"when": "code-runner.showRunButton",
"command": "code-runner.run",
"group": "navigation"
}
Expand Down Expand Up @@ -324,10 +324,16 @@
"description": "Whether to ignore selection to always run entire file.",
"scope": "resource"
},
"code-runner.onlyShowRunIconIfExecutorExists": {
"type": "boolean",
"default": true,
"description": "Whether to only show 'Run Code' icon in editor title menu if the current file can be ran. If false, the icon will show for every file.",
"scope": "resource"
},
"code-runner.showRunIconInEditorTitleMenu": {
"type": "boolean",
"default": true,
"description": "Whether to show 'Run Code' icon in editor title menu.",
"description": "Whether to show 'Run Code' icon in editor title menu. If false, overrides `code-runner.onlyShowRunIconIfExecutorExists` setting.",
"scope": "resource"
},
"code-runner.showStopIconInEditorTitleMenu": {
Expand Down
16 changes: 16 additions & 0 deletions src/codeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ export class CodeManager implements vscode.Disposable {
this.stopRunning();
}

public fileHasExecutor(): boolean {
const editor = vscode.window.activeTextEditor;
if (editor) {
this._document = editor.document;
}

if (!this._document) {
return false;
}

this.initialize();
const fileExtension = extname(this._document.fileName);
const executor = this.getExecutor(this._document.languageId, fileExtension);
return executor != null;
}

private checkIsRunFromExplorer(fileUri: vscode.Uri): boolean {
const editor = vscode.window.activeTextEditor;
if (!fileUri || !fileUri.fsPath) {
Expand Down
19 changes: 19 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(runByLanguage);
context.subscriptions.push(stop);
context.subscriptions.push(codeManager);

const updateContext = () => {
const config = vscode.workspace.getConfiguration("code-runner");
if (!config.get<boolean>("showRunIconInEditorTitleMenu", true)) {
vscode.commands.executeCommand("setContext", "code-runner.showRunButton", false);
return;
}

if (!config.get<boolean>("onlyShowRunIconIfExecutorExists", true)) {
vscode.commands.executeCommand("setContext", "code-runner.showRunButton", true);
return;
}

vscode.commands.executeCommand("setContext", "code-runner.showRunButton", codeManager.fileHasExecutor());
};
vscode.workspace.onDidChangeConfiguration(updateContext);
vscode.window.onDidChangeActiveTextEditor(updateContext);

updateContext();
}

export function deactivate() {
Expand Down