Skip to content

Commit 51b0597

Browse files
committed
[JAVAVSCODE #196] Run Configuration section is unavailable in the Explorer panel for non-workspace opened Java files
Fixed runConfiguration.ts: `initializeRunConfiguration()` to search for java files in open editors when no workspace is open. 1. Checked for non-workspace opened files by testing the validity of `vscode.workspace.name` AND `vscode.workspace.workspaceFile`. 2. Searched for java extension file names in `vscode.workspace.textDocuments` when no workspace is open. 3. Fixed `RunConfigurationNode.setValue()` to invoke `WorkspaceConfiguration.update()` with `configurationTarget =` : - `true`: when no workspace is open i.e. user global target; - `null`: otherwise i.e. workspace target. Fixes #196 Signed-off-by: Siddharth Srinivasan <[email protected]>
1 parent 3dfa21d commit 51b0597

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

vscode/src/runConfiguration.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,18 @@ import * as vscode from 'vscode';
2323
import { homedir } from 'os';
2424

2525
export async function initializeRunConfiguration(): Promise<boolean> {
26-
const java = await vscode.workspace.findFiles('**/*.java', '**/node_modules/**', 1);
27-
if (java?.length > 0) {
26+
if (vscode.workspace.name || vscode.workspace.workspaceFile) {
27+
const java = await vscode.workspace.findFiles('**/*.java', '**/node_modules/**', 1);
28+
if (java?.length > 0) {
2829
return true;
29-
}
30+
}
31+
} else {
32+
for (let doc of vscode.workspace.textDocuments) {
33+
if (doc.fileName?.endsWith(".java")) {
34+
return true;
35+
}
36+
}
37+
}
3038
return false;
3139
}
3240

@@ -152,7 +160,7 @@ class RunConfigurationNode extends vscode.TreeItem {
152160

153161
setValue(value: string | undefined) {
154162
this.value = value;
155-
this.getConfig().update(this.settingsKey, this.value, false);
163+
this.getConfig().update(this.settingsKey, this.value, vscode.workspace.name || vscode.workspace.workspaceFile ? null : true);
156164
this.updateNode();
157165
}
158166

@@ -192,7 +200,7 @@ const vmOptionsNode = new VMOptionsNode();
192200
class EnvironmentVariablesNode extends RunConfigurationNode {
193201

194202
constructor() {
195-
super('Environment:', 'Customize evironment variables', 'Example: var1=one, varTwo=2', 'env');
203+
super('Environment:', 'Customize environment variables', 'Example: var1=one, varTwo=2', 'env');
196204
}
197205

198206
}

0 commit comments

Comments
 (0)