Skip to content

Commit 8cce294

Browse files
committed
Add support for workspace folder configuration
1 parent 8c46757 commit 8cce294

File tree

2 files changed

+47
-20
lines changed

2 files changed

+47
-20
lines changed

package.json

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@
143143
"haskell": "runhaskell",
144144
"nim": "nim compile --verbosity:0 --hints:off --run"
145145
},
146-
"description": "Set the executor of each language."
146+
"description": "Set the executor of each language.",
147+
"scope": "resource"
147148
},
148149
"code-runner.executorMapByFileExtension": {
149150
"type": "object",
@@ -168,12 +169,14 @@
168169
".hs": "runhaskell",
169170
".nim": "nim compile --verbosity:0 --hints:off --run"
170171
},
171-
"description": "Set the executor of each file extension."
172+
"description": "Set the executor of each file extension.",
173+
"scope": "resource"
172174
},
173175
"code-runner.customCommand": {
174176
"type": "string",
175177
"default": "echo Hello",
176-
"description": "Set the custom command to run."
178+
"description": "Set the custom command to run.",
179+
"scope": "resource"
177180
},
178181
"code-runner.languageIdToFileExtensionMap": {
179182
"type": "object",
@@ -182,77 +185,92 @@
182185
"powershell": ".ps1",
183186
"typescript": ".ts"
184187
},
185-
"description": "Set the mapping of languageId to file extension."
188+
"description": "Set the mapping of languageId to file extension.",
189+
"scope": "resource"
186190
},
187191
"code-runner.defaultLanguage": {
188192
"type": "string",
189193
"default": "",
190-
"description": "Set the default language to run."
194+
"description": "Set the default language to run.",
195+
"scope": "resource"
191196
},
192197
"code-runner.cwd": {
193198
"type": "string",
194199
"default": "",
195-
"description": "Set the working directory."
200+
"description": "Set the working directory.",
201+
"scope": "resource"
196202
},
197203
"code-runner.fileDirectoryAsCwd": {
198204
"type": "boolean",
199205
"default": false,
200-
"description": "Whether to use the directory of the file to be executed as the working directory."
206+
"description": "Whether to use the directory of the file to be executed as the working directory.",
207+
"scope": "resource"
201208
},
202209
"code-runner.clearPreviousOutput": {
203210
"type": "boolean",
204211
"default": false,
205-
"description": "Whether to clear previous output before each run."
212+
"description": "Whether to clear previous output before each run.",
213+
"scope": "resource"
206214
},
207215
"code-runner.saveAllFilesBeforeRun": {
208216
"type": "boolean",
209217
"default": false,
210-
"description": "Whether to save all files before running."
218+
"description": "Whether to save all files before running.",
219+
"scope": "resource"
211220
},
212221
"code-runner.saveFileBeforeRun": {
213222
"type": "boolean",
214223
"default": false,
215-
"description": "Whether to save the current file before running."
224+
"description": "Whether to save the current file before running.",
225+
"scope": "resource"
216226
},
217227
"code-runner.enableAppInsights": {
218228
"type": "boolean",
219229
"default": true,
220-
"description": "Whether to enable AppInsights to track user telemetry data."
230+
"description": "Whether to enable AppInsights to track user telemetry data.",
231+
"scope": "resource"
221232
},
222233
"code-runner.showExecutionMessage": {
223234
"type": "boolean",
224235
"default": true,
225-
"description": "Whether to show extra execution message like [Running] ... and [Done] ..."
236+
"description": "Whether to show extra execution message like [Running] ... and [Done] ...",
237+
"scope": "resource"
226238
},
227239
"code-runner.runInTerminal": {
228240
"type": "boolean",
229241
"default": false,
230-
"description": "Whether to run code in Integrated Terminal."
242+
"description": "Whether to run code in Integrated Terminal.",
243+
"scope": "resource"
231244
},
232245
"code-runner.terminalRoot": {
233246
"type": "string",
234247
"default": "",
235-
"description": "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'"
248+
"description": "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'",
249+
"scope": "resource"
236250
},
237251
"code-runner.preserveFocus": {
238252
"type": "boolean",
239253
"default": true,
240-
"description": "Whether to preserve focus on code editor after code run is triggered."
254+
"description": "Whether to preserve focus on code editor after code run is triggered.",
255+
"scope": "resource"
241256
},
242257
"code-runner.ignoreSelection": {
243258
"type": "boolean",
244259
"default": false,
245-
"description": "Whether to ignore selection to always run entire file."
260+
"description": "Whether to ignore selection to always run entire file.",
261+
"scope": "resource"
246262
},
247263
"code-runner.showRunIconInEditorTitleMenu": {
248264
"type": "boolean",
249265
"default": true,
250-
"description": "Whether to show 'Run Code' icon in editor title menu."
266+
"description": "Whether to show 'Run Code' icon in editor title menu.",
267+
"scope": "resource"
251268
},
252269
"code-runner.temporaryFileName": {
253270
"type": "string",
254271
"default": "tempCodeRunnerFile",
255-
"description": "Temporary file name used in running selected code snippet. When it is set as empty, the file name will be random."
272+
"description": "Temporary file name used in running selected code snippet. When it is set as empty, the file name will be random.",
273+
"scope": "resource"
256274
}
257275
}
258276
},

src/codeManager.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class CodeManager {
7676

7777
public runByLanguage(): void {
7878
this._appInsightsClient.sendEvent("runByLanguage");
79-
const config = vscode.workspace.getConfiguration("code-runner");
79+
const config = this.getConfiguration();
8080
const executorMap = config.get<any>("executorMap");
8181
vscode.window.showQuickPick(Object.keys(executorMap), { placeHolder: "Type or select language to run" }).then((languageId) => {
8282
if (languageId !== undefined) {
@@ -95,7 +95,7 @@ export class CodeManager {
9595
}
9696

9797
private initialize(editor: vscode.TextEditor): void {
98-
this._config = vscode.workspace.getConfiguration("code-runner");
98+
this._config = this.getConfiguration();
9999
this._cwd = this._config.get<string>("cwd");
100100
if (this._cwd) {
101101
return;
@@ -113,6 +113,15 @@ export class CodeManager {
113113
this._cwd = TmpDir;
114114
}
115115

116+
private getConfiguration(): vscode.WorkspaceConfiguration {
117+
const editor = vscode.window.activeTextEditor;
118+
if (editor && editor.document) {
119+
return vscode.workspace.getConfiguration("code-runner", editor.document.uri);
120+
} else {
121+
return vscode.workspace.getConfiguration("code-runner");
122+
}
123+
}
124+
116125
private getWorkspaceFolder(editor: vscode.TextEditor): string {
117126
if (vscode.workspace.workspaceFolders) {
118127
if (editor && editor.document) {

0 commit comments

Comments
 (0)