Update jump to usage to include the method (#2773)

This commit is contained in:
Charis Kyriakou
2023-09-01 13:30:54 +01:00
committed by GitHub
parent 1861692055
commit 2d033bff57
5 changed files with 15 additions and 21 deletions

View File

@@ -523,6 +523,7 @@ interface SwitchModeMessage {
interface JumpToUsageMessage {
t: "jumpToUsage";
method: ExternalApiUsage;
usage: Usage;
}

View File

@@ -71,6 +71,7 @@ export class MethodsUsageDataProvider
iconPath: new ThemeIcon("symbol-method"),
};
} else {
const method = this.getParent(item);
return {
label: item.label,
description: `${this.relativePathWithinDatabase(item.url.uri)} [${
@@ -80,7 +81,7 @@ export class MethodsUsageDataProvider
command: {
title: "Show usage",
command: "codeQLModelEditor.jumpToUsageLocation",
arguments: [item, this.databaseItem],
arguments: [method, item, this.databaseItem],
},
iconPath: new ThemeIcon("error", new ThemeColor("errorForeground")),
};

View File

@@ -175,23 +175,11 @@ export class ModelEditorModule extends DisposableObject {
await ensureDir(this.queryStorageDir);
}
private async showMethod(usage: Usage): Promise<void> {
private async showMethod(
method: ExternalApiUsage,
usage: Usage,
): Promise<void> {
await this.methodsUsagePanel.revealItem(usage);
// For now, just construct a dummy method and show it in the method modeling panel
// because the method isn't easily accessible yet.
const method: ExternalApiUsage = {
library: "sql2o",
libraryVersion: "1.6.0",
signature: "org.sql2o.Connection#createQuery(String)",
packageName: "org.sql2o",
typeName: "Connection",
methodName: "createQuery",
methodParameters: "(String)",
supported: true,
supportedType: "summary",
usages: [],
};
await this.methodModelingPanel.setMethod(method);
}
}

View File

@@ -65,7 +65,10 @@ export class ModelEditorView extends AbstractWebview<
databaseItem: DatabaseItem,
hideModeledApis: boolean,
) => Promise<void>,
private readonly showMethod: (usage: Usage) => Promise<void>,
private readonly showMethod: (
method: ExternalApiUsage,
usage: Usage,
) => Promise<void>,
private readonly handleViewBecameActive: (view: ModelEditorView) => void,
private readonly handleViewWasDisposed: (view: ModelEditorView) => void,
private readonly isMostRecentlyActiveView: (
@@ -190,7 +193,7 @@ export class ModelEditorView extends AbstractWebview<
break;
case "jumpToUsage":
await this.handleJumpToUsage(msg.usage);
await this.handleJumpToUsage(msg.method, msg.usage);
break;
case "saveModeledMethods":
@@ -267,8 +270,8 @@ export class ModelEditorView extends AbstractWebview<
});
}
protected async handleJumpToUsage(usage: Usage) {
await this.showMethod(usage);
protected async handleJumpToUsage(method: ExternalApiUsage, usage: Usage) {
await this.showMethod(method, usage);
await showResolvableLocation(usage.url, this.databaseItem, this.app.logger);
}

View File

@@ -314,6 +314,7 @@ function UnmodelableMethodRow(props: Props) {
function sendJumpToUsageMessage(externalApiUsage: ExternalApiUsage) {
vscode.postMessage({
t: "jumpToUsage",
method: externalApiUsage,
// In framework mode, the first and only usage is the definition of the method
usage: externalApiUsage.usages[0],
});