mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-15 08:23:37 +01:00
testing: make uri optional
This commit is contained in:
Vendored
+3
-3
@@ -2565,7 +2565,7 @@ declare module 'vscode' {
|
||||
/**
|
||||
* URI this TestItem is associated with. May be a file or directory.
|
||||
*/
|
||||
uri: Uri;
|
||||
uri?: Uri;
|
||||
|
||||
/**
|
||||
* Display name describing the test item.
|
||||
@@ -2588,7 +2588,7 @@ declare module 'vscode' {
|
||||
/**
|
||||
* URI this TestItem is associated with. May be a file or directory.
|
||||
*/
|
||||
readonly uri: Uri;
|
||||
readonly uri?: Uri;
|
||||
|
||||
/**
|
||||
* A mapping of children by ID to the associated TestItem instances.
|
||||
@@ -2820,7 +2820,7 @@ declare module 'vscode' {
|
||||
/**
|
||||
* URI this TestItem is associated with. May be a file or file.
|
||||
*/
|
||||
readonly uri: Uri;
|
||||
readonly uri?: Uri;
|
||||
|
||||
/**
|
||||
* Display name describing the test case.
|
||||
|
||||
@@ -666,7 +666,7 @@ export class TestItemFilteredWrapper extends TestItemImpl {
|
||||
}
|
||||
}
|
||||
|
||||
const nowMatches = this.children.size > 0 || this.actual.uri.toString() === this.filterDocument.uri.toString();
|
||||
const nowMatches = this.children.size > 0 || this.actual.uri?.toString() === this.filterDocument.uri.toString();
|
||||
this._cachedMatchesFilter = nowMatches;
|
||||
|
||||
if (nowMatches !== didMatch) {
|
||||
|
||||
@@ -3263,7 +3263,7 @@ const rangeComparator = (a: vscode.Range | undefined, b: vscode.Range | undefine
|
||||
|
||||
export class TestItemImpl implements vscode.TestItem<unknown> {
|
||||
public readonly id!: string;
|
||||
public readonly uri!: vscode.Uri;
|
||||
public readonly uri!: vscode.Uri | undefined;
|
||||
public readonly children!: ReadonlyMap<string, TestItemImpl>;
|
||||
public readonly parent!: TestItemImpl | undefined;
|
||||
|
||||
@@ -3277,7 +3277,7 @@ export class TestItemImpl implements vscode.TestItem<unknown> {
|
||||
/** Extension-owned resolve handler */
|
||||
public resolveHandler?: (token: vscode.CancellationToken) => void;
|
||||
|
||||
constructor(id: string, public label: string, uri: vscode.Uri, public data: unknown) {
|
||||
constructor(id: string, public label: string, uri: vscode.Uri | undefined, public data: unknown) {
|
||||
const api = getPrivateApiFor(this);
|
||||
|
||||
Object.defineProperties(this, {
|
||||
|
||||
@@ -537,6 +537,7 @@ export class EditFocusedTest extends ViewAction<TestingExplorerView> {
|
||||
f1: false,
|
||||
menu: {
|
||||
id: MenuId.TestItem,
|
||||
when: TestingContextKeys.testItemHasUri.isEqualTo(true),
|
||||
},
|
||||
keybinding: {
|
||||
weight: KeybindingWeight.EditorContrib - 10,
|
||||
@@ -568,6 +569,10 @@ export class EditFocusedTest extends ViewAction<TestingExplorerView> {
|
||||
* @override
|
||||
*/
|
||||
private async runForTest(accessor: ServicesAccessor, test: ITestItem, preserveFocus = true) {
|
||||
if (!test.uri) {
|
||||
return;
|
||||
}
|
||||
|
||||
const commandService = accessor.get(ICommandService);
|
||||
const fileService = accessor.get(IFileService);
|
||||
const editorService = accessor.get(IEditorService);
|
||||
|
||||
@@ -113,7 +113,7 @@ export class TestingDecorations extends Disposable implements IEditorContributio
|
||||
updateFontFamilyVar();
|
||||
|
||||
this._register(this.results.onTestChanged(({ item: result }) => {
|
||||
if (this.currentUri && result.item.uri.toString() === this.currentUri.toString()) {
|
||||
if (this.currentUri && result.item.uri && result.item.uri.toString() === this.currentUri.toString()) {
|
||||
this.setDecorations(this.currentUri);
|
||||
}
|
||||
}));
|
||||
|
||||
@@ -687,7 +687,7 @@ class TestsFilter implements ITreeFilter<TestExplorerTreeElement> {
|
||||
}
|
||||
|
||||
for (let e: IActionableTestTreeElement | null = element; e instanceof TestItemTreeElement; e = e!.parent) {
|
||||
return e.test.item.uri.toString() === this._filterToUri
|
||||
return e.test.item.uri?.toString() === this._filterToUri
|
||||
? FilterResult.Include
|
||||
: FilterResult.Exclude;
|
||||
}
|
||||
@@ -735,7 +735,7 @@ class TreeSorter implements ITreeSorter<TestExplorerTreeElement> {
|
||||
|
||||
if (this.viewModel.viewSorting === TestExplorerViewSorting.ByLocation) {
|
||||
if (a instanceof TestItemTreeElement && b instanceof TestItemTreeElement
|
||||
&& a.test.item.uri.toString() === b.test.item.uri.toString() && a.test.item.range && b.test.item.range) {
|
||||
&& a.test.item.uri && b.test.item.uri && a.test.item.uri.toString() === b.test.item.uri.toString() && a.test.item.range && b.test.item.range) {
|
||||
const delta = a.test.item.range.startLineNumber - b.test.item.range.startLineNumber;
|
||||
if (delta !== 0) {
|
||||
return delta;
|
||||
@@ -1013,7 +1013,8 @@ const getActionableElementActions = (
|
||||
const test = element instanceof TestItemTreeElement ? element.test : undefined;
|
||||
const contextOverlay = contextKeyService.createOverlay([
|
||||
['view', Testing.ExplorerViewId],
|
||||
[TestingContextKeys.testItemExtId.key, test?.item.extId]
|
||||
[TestingContextKeys.testItemExtId.key, test?.item.extId],
|
||||
[TestingContextKeys.testItemHasUri.key, !!test?.item.uri],
|
||||
]);
|
||||
const menu = menuService.createMenu(MenuId.TestItem, contextOverlay);
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ export class TestingPeekOpener extends Disposable implements ITestingPeekOpener
|
||||
|
||||
// don't show the peek if the user asked to only auto-open peeks for visible tests,
|
||||
// and this test is not in any of the editors' models.
|
||||
const testUri = evt.item.item.uri.toString();
|
||||
const testUri = evt.item.item.uri?.toString();
|
||||
if (cfg === AutoOpenPeekViewWhen.FailureVisible && (!testUri || !editors.some(e => e.getModel()?.uri.toString() === testUri))) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ export interface ITestItem {
|
||||
extId: string;
|
||||
label: string;
|
||||
children?: never;
|
||||
uri: URI;
|
||||
uri?: URI;
|
||||
range: IRange | null;
|
||||
description: string | null;
|
||||
error: string | IMarkdownString | null;
|
||||
|
||||
@@ -23,4 +23,8 @@ export namespace TestingContextKeys {
|
||||
type: 'string',
|
||||
description: localize('testing.testId', 'ID of the current test item, set when creating or opening menus on test items')
|
||||
});
|
||||
export const testItemHasUri = new RawContextKey<boolean>('testItemHasUri', false, {
|
||||
type: 'string',
|
||||
description: localize('testing.testItemHasUri', 'Boolean indicating whether the test item has a URI defined')
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user