Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude Code-Runner from running with certain file extensions #1171

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
17 changes: 13 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
"menus": {
"editor/context": [
{
"when": "!inOutput && config.code-runner.showRunCommandInEditorContextMenu",
"when": "!inOutput && config.code-runner.showRunCommandInEditorContextMenu && resourceExtname not in code-runner.excludedFileExtension",
"command": "code-runner.run",
"group": "navigation"
},
Expand All @@ -97,21 +97,21 @@
],
"editor/title/run": [
{
"when": "config.code-runner.showRunIconInEditorTitleMenu",
"when": "config.code-runner.showRunIconInEditorTitleMenu && resourceExtname not in code-runner.excludedFileExtension",
"command": "code-runner.run",
"group": "navigation"
}
],
"editor/title": [
{
"when": "config.code-runner.showStopIconInEditorTitleMenu && code-runner.codeRunning",
"when": "config.code-runner.showStopIconInEditorTitleMenu && code-runner.codeRunning && resourceExtname not in code-runner.excludedFileExtension",
"command": "code-runner.stop",
"group": "navigation"
}
],
"explorer/context": [
{
"when": "!explorerResourceIsFolder && config.code-runner.showRunCommandInExplorerContextMenu",
"when": "!explorerResourceIsFolder && config.code-runner.showRunCommandInExplorerContextMenu && resourceExtname not in code-runner.excludedFileExtension",
"command": "code-runner.run",
"group": "navigation"
}
Expand Down Expand Up @@ -359,6 +359,15 @@
"default": true,
"description": "Whether to respect Shebang to run code.",
"scope": "resource"
},
"code-runner.excludedFileExtension": {
"type": "array",
"items": {
"type": "string"
},
"description": "Exclude Code-Runner from running with certain file extensions",
"default": [],
"scope": "resource"
}
}
},
Expand Down
5 changes: 5 additions & 0 deletions src/codeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export class CodeManager implements vscode.Disposable {
this.initialize();

const fileExtension = extname(this._document.fileName);
const excludedExts = this._config.get<string[]>('excludedFileExtension', []);
if (excludedExts.includes(fileExtension)) {
vscode.window.showInformationMessage("The file extension is excluded.");
return;
}
const executor = this.getExecutor(languageId, fileExtension);
// undefined or null
if (executor == null) {
Expand Down
3 changes: 3 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(runByLanguage);
context.subscriptions.push(stop);
context.subscriptions.push(codeManager);

const excludedExts = vscode.workspace.getConfiguration('code-runner').get<string[]>('excludedFileExtension', []);
vscode.commands.executeCommand('setContext', 'code-runner.excludedFileExtension', excludedExts);
}

export function deactivate() {
Expand Down