Covert to canonical usage object before calling reveal

This commit is contained in:
Robert
2023-08-08 16:46:34 +01:00
parent e37a833c9a
commit 6aea8fee3a
2 changed files with 27 additions and 1 deletions

View File

@@ -61,6 +61,17 @@ export class ModelDetailsDataProvider
return [];
}
}
public resolveCanonicalUsage(usage: Usage): Usage | undefined {
for (const externalApiUsage of this.externalApiUsages) {
for (const u of externalApiUsage.usages) {
if (usagesAreEqual(u, usage)) {
return u;
}
}
}
return undefined;
}
}
export type ModelDetailsTreeViewItem = ExternalApiUsage | Usage;
@@ -70,3 +81,15 @@ function isExternalApiUsage(
): item is ExternalApiUsage {
return (item as any).usages !== undefined;
}
function usagesAreEqual(u1: Usage, u2: Usage): boolean {
return (
u1.label === u2.label &&
u1.classification === u2.classification &&
u1.url.uri === u2.url.uri &&
u1.url.startLine === u2.url.startLine &&
u1.url.startColumn === u2.url.startColumn &&
u1.url.endLine === u2.url.endLine &&
u1.url.endColumn === u2.url.endColumn
);
}

View File

@@ -30,6 +30,9 @@ export class ModelDetailsPanel extends DisposableObject {
}
public async revealItem(usage: Usage): Promise<void> {
await this.treeView.reveal(usage);
const canonicalUsage = this.dataProvider.resolveCanonicalUsage(usage);
if (canonicalUsage !== undefined) {
await this.treeView.reveal(canonicalUsage);
}
}
}