Skip to content

Commit 6385b2c

Browse files
authored
Add welcome page for test explorer in LightWeight mode (#1046)
1 parent 35934b2 commit 6385b2c

File tree

4 files changed

+26
-45
lines changed

4 files changed

+26
-45
lines changed

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@
7070
}
7171
]
7272
},
73+
"viewsWelcome": [
74+
{
75+
"view": "testExplorer",
76+
"contents": "No test cases are listed because the Java Language Server is currently running in [LightWeight Mode](https://aka.ms/vscode-java-lightweight). To show test cases, click on the button to switch to Standard Mode.\n[Switch to Standard Mode](command:java.server.mode.switch?%5B%22Standard%22,true%5D)",
77+
"when": "java:serverMode == LightWeight"
78+
}
79+
],
7380
"menus": {
7481
"view/title": [
7582
{

src/constants/commands.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
export namespace JavaLanguageServerCommands {
55
export const EXECUTE_WORKSPACE_COMMAND: string = 'java.execute.workspaceCommand';
6-
export const SWITCH_SERVER_MODE: string = 'java.server.mode.switch';
76
}
87

98
export namespace JavaTestRunnerDelegateCommands {
@@ -30,5 +29,4 @@ export namespace JavaTestRunnerCommands {
3029
export const RELAUNCH_TESTS: string = 'java.test.relaunch';
3130
export const JAVA_TEST_CANCEL: string = 'java.test.cancel';
3231
export const JAVA_CONFIG_MIGRATE: string = 'java.test.config.migrate';
33-
export const JAVA_TEST_SWITCH_SERVER_MODE: string = 'java.test.switch.server.mode';
3432
}

src/explorer/testExplorer.ts

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
import * as path from 'path';
55
import { Command, Disposable, Event, EventEmitter, ExtensionContext, extensions, Range, ThemeIcon, TreeDataProvider, TreeItem, TreeItemCollapsibleState, Uri, workspace, WorkspaceFolder } from 'vscode';
66
import { JavaTestRunnerCommands } from '../constants/commands';
7-
import { isStandardServerReady, isSwitchingServer } from '../extension';
7+
import { isLightWeightMode, isSwitchingServer } from '../extension';
88
import { ITestItem, TestKind, TestLevel } from '../protocols';
99
import { ITestResult, TestStatus } from '../runners/models';
1010
import { testFileWatcher } from '../testFileWatcher';
1111
import { testItemModel } from '../testItemModel';
1212
import { testResultManager } from '../testResultManager';
1313

14-
const LIGHTWEIGHT_NODE_ID: string = ':LIGHTWEIGHT_MODE:';
1514
export class TestExplorer implements TreeDataProvider<ITestItem>, Disposable {
1615
public readonly testExplorerViewId: string = 'testExplorer';
1716

@@ -26,20 +25,6 @@ export class TestExplorer implements TreeDataProvider<ITestItem>, Disposable {
2625
}
2726

2827
public getTreeItem(element: ITestItem): TreeItem | Thenable<TreeItem> {
29-
if (element.id === LIGHTWEIGHT_NODE_ID) {
30-
return {
31-
label: element.displayName,
32-
collapsibleState: TreeItemCollapsibleState.None,
33-
command: {
34-
command: JavaTestRunnerCommands.JAVA_TEST_SWITCH_SERVER_MODE,
35-
title: 'Switch to Standard mode',
36-
},
37-
contextValue: 'UNTESTABLE_NODE',
38-
tooltip: 'Switch the Java Language Server to Standard mode to show all the test cases',
39-
iconPath: new ThemeIcon('info'),
40-
};
41-
}
42-
4328
return {
4429
label: element.displayName,
4530
collapsibleState: this.resolveCollapsibleState(element),
@@ -50,28 +35,15 @@ export class TestExplorer implements TreeDataProvider<ITestItem>, Disposable {
5035
}
5136

5237
public async getChildren(element?: ITestItem): Promise<ITestItem[]> {
38+
if (isLightWeightMode()) {
39+
return [];
40+
}
5341
if (isSwitchingServer()) {
5442
await new Promise<void>((resolve: () => void): void => {
5543
extensions.getExtension('redhat.java')!.exports.onDidServerModeChange(resolve);
5644
});
5745
}
58-
if (!isStandardServerReady()) {
59-
return [
60-
{
61-
id: LIGHTWEIGHT_NODE_ID,
62-
displayName: 'Click to load test cases...',
63-
fullName: LIGHTWEIGHT_NODE_ID,
64-
kind: TestKind.None,
65-
project: '',
66-
level: TestLevel.Folder,
67-
location: {
68-
uri: '',
69-
range: new Range(0, 0, 0, 0),
70-
},
71-
children: undefined,
72-
},
73-
];
74-
}
46+
7547
let nodes: ITestItem[] = [];
7648
if (!element) {
7749
nodes = this.getWorkspaceFolders();

src/extension.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import * as fse from 'fs-extra';
55
import * as os from 'os';
66
import * as path from 'path';
7-
import { commands, DebugConfiguration, Event, Extension, ExtensionContext, extensions, Range, Uri, window } from 'vscode';
7+
import { DebugConfiguration, Event, Extension, ExtensionContext, extensions, Range, Uri, window } from 'vscode';
88
import { dispose as disposeTelemetryWrapper, initializeFromJsonFile, instrumentOperation, instrumentOperationAsVsCodeCommand } from 'vscode-extension-telemetry-wrapper';
99
import { testCodeLensController } from './codelens/TestCodeLensController';
1010
import { debugTestsFromExplorer, openTextDocument, runTestsFromExplorer } from './commands/explorerCommands';
1111
import { openLogFile, showOutputChannel } from './commands/logCommands';
1212
import { runFromCodeLens } from './commands/runFromCodeLens';
13-
import { JavaLanguageServerCommands, JavaTestRunnerCommands } from './constants/commands';
13+
import { JavaTestRunnerCommands } from './constants/commands';
1414
import { testExplorer } from './explorer/testExplorer';
1515
import { logger } from './logger/logger';
1616
import { ITestItem } from './protocols';
@@ -100,12 +100,6 @@ async function doActivate(_operationId: string, context: ExtensionContext): Prom
100100
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.OPEN_TEST_LOG, async () => await openLogFile(storagePath)),
101101
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.JAVA_TEST_CANCEL, async () => await runnerScheduler.cleanUp(true /* isCancel */)),
102102
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.JAVA_CONFIG_MIGRATE, async () => await migrateTestConfig()),
103-
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.JAVA_TEST_SWITCH_SERVER_MODE, async () => {
104-
if (isSwitchingServer()) {
105-
return;
106-
}
107-
await commands.executeCommand(JavaLanguageServerCommands.SWITCH_SERVER_MODE);
108-
}),
109103
);
110104
}
111105

@@ -115,15 +109,25 @@ export function isStandardServerReady(): boolean {
115109
return true;
116110
}
117111

118-
if (serverMode !== 'Standard') {
112+
if (serverMode !== LanguageServerMode.Standard) {
119113
return false;
120114
}
121115

122116
return true;
123117
}
124118

119+
export function isLightWeightMode(): boolean {
120+
return serverMode === LanguageServerMode.LightWeight;
121+
}
122+
125123
export function isSwitchingServer(): boolean {
126-
return serverMode === 'Hybrid';
124+
return serverMode === LanguageServerMode.Hybrid;
127125
}
128126

129127
let serverMode: string | undefined;
128+
129+
const enum LanguageServerMode {
130+
LightWeight = 'LightWeight',
131+
Standard = 'Standard',
132+
Hybrid = 'Hybrid',
133+
}

0 commit comments

Comments
 (0)