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

fix: Improve the accessibility of opening document #1129

Merged
merged 1 commit into from
Jan 26, 2021
Merged
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
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
],
"aiKey": "90c182a8-8dab-45d4-bfb8-1353eb55aa7f",
"engines": {
"vscode": "^1.51.0"
"vscode": "^1.52.0"
},
"categories": [
"Other"
Expand Down Expand Up @@ -457,7 +457,7 @@
"@types/node": "^14.0.1",
"@types/pug": "^2.0.4",
"@types/sinon": "^9.0.3",
"@types/vscode": "1.51.0",
"@types/vscode": "1.52.0",
"bootstrap": "^4.5.0",
"filemanager-webpack-plugin": "^2.0.5",
"gulp": "^4.0.2",
Expand Down
2 changes: 1 addition & 1 deletion src/commands/explorerCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { executeTestsFromUri } from './runFromUri';

export async function openTextDocument(uri: Uri, range?: Range): Promise<void> {
const document: TextDocument = await workspace.openTextDocument(uri);
await window.showTextDocument(document, {preserveFocus: true, selection: range, viewColumn: ViewColumn.One});
await window.showTextDocument(document, {selection: range, viewColumn: ViewColumn.One});
}

export async function runTestsFromExplorer(node?: ITestItem, launchConfiguration?: DebugConfiguration): Promise<void> {
Expand Down
9 changes: 4 additions & 5 deletions src/commands/testReportCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

import { commands, Position, QuickPickItem, Range, Uri, ViewColumn, window } from 'vscode';
import { ILocation } from '../../extension.bundle';
import { JavaTestRunnerCommands } from '../constants/commands';
import { logger } from '../logger/logger';
import { resolveStackTraceLocation, searchTestLocation } from '../utils/commandUtils';
import { openTextDocument } from './explorerCommands';

export async function openStackTrace(trace: string, fullName: string): Promise<void> {
if (!trace || !fullName) {
Expand All @@ -22,7 +22,6 @@ export async function openStackTrace(trace: string, fullName: string): Promise<v
lineNumber = parseInt(lineNumberGroup[1], 10) - 1;
}
await window.showTextDocument(Uri.parse(uri), {
preserveFocus: true,
selection: new Range(new Position(lineNumber, 0), new Position(lineNumber + 1, 0)),
viewColumn: ViewColumn.One,
});
Expand All @@ -38,17 +37,17 @@ export async function openStackTrace(trace: string, fullName: string): Promise<v

export async function openTestSourceLocation(uri: string, range: string, fullName: string): Promise<void> {
if (uri && range) {
return openTextDocument(Uri.parse(uri), JSON.parse(range) as Range);
return commands.executeCommand(JavaTestRunnerCommands.OPEN_DOCUMENT, Uri.parse(uri), JSON.parse(range) as Range);
} else if (fullName) {
const items: ILocation[] = await searchTestLocation(fullName.slice(fullName.indexOf('@') + 1));
if (items.length === 1) {
return openTextDocument(Uri.parse(items[0].uri), items[0].range);
return commands.executeCommand(JavaTestRunnerCommands.OPEN_DOCUMENT, Uri.parse(items[0].uri), items[0].range);
} else if (items.length > 1) {
const pick: ILocationQuickPick | undefined = await window.showQuickPick(items.map((item: ILocation) => {
return { label: fullName, detail: Uri.parse(item.uri).fsPath, location: item };
}), { placeHolder: 'Select the file you want to navigate to' });
if (pick) {
return openTextDocument(Uri.parse(pick.location.uri), pick.location.range);
return commands.executeCommand(JavaTestRunnerCommands.OPEN_DOCUMENT, Uri.parse(pick.location.uri), pick.location.range);
}
} else {
logger.error('No test item could be found from Language Server.');
Expand Down
4 changes: 4 additions & 0 deletions src/constants/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,7 @@ export namespace JavaTestRunnerCommands {
export const JAVA_TEST_REPORT_OPEN_STACKTRACE: string = 'java.test.report.openStackTrace';
export const JAVA_TEST_REPORT_OPEN_TEST_SOURCE_LOCATION: string = 'java.test.report.openTestSourceLocation';
}

export namespace VsCodeCommands {
export const VSCODE_OPEN: string = 'vscode.open';
}
8 changes: 4 additions & 4 deletions src/explorer/testExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import * as path from 'path';
import { Command, Disposable, Event, EventEmitter, ExtensionContext, extensions, Range, ThemeColor, ThemeIcon, TreeDataProvider, TreeItem, TreeItemCollapsibleState, Uri, workspace, WorkspaceFolder } from 'vscode';
import { JavaTestRunnerCommands } from '../constants/commands';
import { VsCodeCommands } from '../constants/commands';
import { isLightWeightMode, isSwitchingServer } from '../extension';
import { ITestItem, TestKind, TestLevel } from '../protocols';
import { ITestResult, TestStatus } from '../runners/models';
Expand Down Expand Up @@ -128,9 +128,9 @@ export class TestExplorer implements TreeDataProvider<ITestItem>, Disposable {
private resolveCommand(element: ITestItem): Command | undefined {
if (element.level >= TestLevel.Class) {
return {
command: JavaTestRunnerCommands.OPEN_DOCUMENT,
title: '',
arguments: [Uri.parse(element.location.uri), element.location.range],
command: VsCodeCommands.VSCODE_OPEN,
title: 'Open File',
arguments: [Uri.parse(element.location.uri), { preserveFocus: true, selection: element.location.range }],
};
}
return undefined;
Expand Down
26 changes: 24 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as fse from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
import { commands, DebugConfiguration, Event, Extension, ExtensionContext, extensions, Range, Uri, window, workspace } from 'vscode';
import { commands, DebugConfiguration, Event, Extension, ExtensionContext, extensions, Range, TreeView, TreeViewExpansionEvent, TreeViewSelectionChangeEvent, Uri, window, workspace } from 'vscode';
import { dispose as disposeTelemetryWrapper, initializeFromJsonFile, instrumentOperation, instrumentOperationAsVsCodeCommand } from 'vscode-extension-telemetry-wrapper';
import { sendInfo } from 'vscode-extension-telemetry-wrapper';
import { testCodeLensController } from './codelens/TestCodeLensController';
Expand Down Expand Up @@ -35,6 +35,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
}

export async function deactivate(): Promise<void> {
sendInfo('treeViewEventSummary', EventCounter.dict);
await disposeTelemetryWrapper();
await runnerScheduler.cleanUp(false /* isCancel */);
}
Expand Down Expand Up @@ -87,12 +88,13 @@ async function doActivate(_operationId: string, context: ExtensionContext): Prom

await testFileWatcher.registerListeners();
testExplorer.initialize(context);
const testTreeView: TreeView<ITestItem> = window.createTreeView(testExplorer.testExplorerViewId, { treeDataProvider: testExplorer, showCollapseAll: true });
runnerScheduler.initialize(context);
testReportProvider.initialize(context, javaLanguageSupportVersion);

context.subscriptions.push(
testExplorer,
window.createTreeView(testExplorer.testExplorerViewId, { treeDataProvider: testExplorer, showCollapseAll: true }),
testTreeView,
testStatusBarProvider,
testResultManager,
testReportProvider,
Expand Down Expand Up @@ -120,6 +122,17 @@ async function doActivate(_operationId: string, context: ExtensionContext): Prom
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.JAVA_TEST_REPORT_OPEN_TEST_SOURCE_LOCATION, async (uri: string, range: string, fullName: string) => await openTestSourceLocation(uri, range, fullName)),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.RUN_TEST_FROM_JAVA_PROJECT_EXPLORER, async (node: any) => await runTestsFromJavaProjectExplorer(node, false /* isDebug */)),
instrumentOperationAsVsCodeCommand(JavaTestRunnerCommands.DEBUG_TEST_FROM_JAVA_PROJECT_EXPLORER, async (node: any) => await runTestsFromJavaProjectExplorer(node, true /* isDebug */)),

// track the test tree view events.
testTreeView.onDidChangeSelection((_e: TreeViewSelectionChangeEvent<ITestItem>) => {
EventCounter.increase('didChangeSelection');
}),
testTreeView.onDidCollapseElement((_e: TreeViewExpansionEvent<ITestItem>) => {
EventCounter.increase('didCollapseElement');
}),
testTreeView.onDidExpandElement((_e: TreeViewExpansionEvent<ITestItem>) => {
EventCounter.increase('didExpandElement');
}),
);

setContextKeyForDeprecatedConfig();
Expand Down Expand Up @@ -163,3 +176,12 @@ const enum LanguageServerMode {
}

export let progressProvider: IProgressProvider | undefined;

class EventCounter {
public static dict: {[key: string]: number} = {};

public static increase(event: string): void {
const count: number = this.dict[event] ?? 0;
this.dict[event] = count + 1;
}
}
3 changes: 2 additions & 1 deletion src/utils/configUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as _ from 'lodash';
import * as path from 'path';
import { commands, ConfigurationTarget, QuickPickItem, TextDocument, Uri, window, workspace, WorkspaceConfiguration, WorkspaceFolder } from 'vscode';
import { sendInfo } from 'vscode-extension-telemetry-wrapper';
import { VsCodeCommands } from '../constants/commands';
import { BUILTIN_CONFIG_NAME, CONFIG_DOCUMENT_URL, CONFIG_SETTING_KEY, DEFAULT_CONFIG_NAME_SETTING_KEY, HINT_FOR_DEFAULT_CONFIG_SETTING_KEY } from '../constants/configs';
import { LEARN_MORE, NEVER_SHOW, NO, OPEN_SETTING, YES } from '../constants/dialogOptions';
import { logger } from '../logger/logger';
Expand Down Expand Up @@ -90,7 +91,7 @@ export async function migrateTestConfig(): Promise<void> {
await window.showTextDocument(document, { preview: false });
}
} else if (choice === LEARN_MORE) {
commands.executeCommand('vscode.open', Uri.parse(CONFIG_DOCUMENT_URL));
commands.executeCommand(VsCodeCommands.VSCODE_OPEN, Uri.parse(CONFIG_DOCUMENT_URL));
}
}

Expand Down