From bc4027fa8935a769087bad7132a1b18d5445ccca Mon Sep 17 00:00:00 2001 From: robinhong Date: Tue, 27 Aug 2024 22:52:42 +0800 Subject: [PATCH 1/2] Exclude Code-Runner from running with certain file extensions --- package.json | 17 +++++++++++++---- src/codeManager.ts | 5 +++++ src/extension.ts | 3 +++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 075781c..531fef8 100644 --- a/package.json +++ b/package.json @@ -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" }, @@ -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" } @@ -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" } } }, diff --git a/src/codeManager.ts b/src/codeManager.ts index 3de6e2e..b7ec168 100644 --- a/src/codeManager.ts +++ b/src/codeManager.ts @@ -58,6 +58,11 @@ export class CodeManager implements vscode.Disposable { this.initialize(); const fileExtension = extname(this._document.fileName); + const excludedExts: string[] = this._config.get('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) { diff --git a/src/extension.ts b/src/extension.ts index 7c38f10..2f40d70 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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('excludedFileExtension', []); + vscode.commands.executeCommand('setContext', 'code-runner.excludedFileExtension', excludedExts); } export function deactivate() { From 4c9c30bfa141b7a8877695cd387ee47cb2677594 Mon Sep 17 00:00:00 2001 From: robinhong Date: Tue, 27 Aug 2024 23:47:56 +0800 Subject: [PATCH 2/2] Exclude Code-Runner from running with certain file extensions --- src/codeManager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codeManager.ts b/src/codeManager.ts index b7ec168..a05e5c0 100644 --- a/src/codeManager.ts +++ b/src/codeManager.ts @@ -58,7 +58,7 @@ export class CodeManager implements vscode.Disposable { this.initialize(); const fileExtension = extname(this._document.fileName); - const excludedExts: string[] = this._config.get('excludedFileExtension', []); + const excludedExts = this._config.get('excludedFileExtension', []); if (excludedExts.includes(fileExtension)) { vscode.window.showInformationMessage("The file extension is excluded."); return;