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 { interface JumpToUsageMessage {
t: "jumpToUsage"; t: "jumpToUsage";
method: ExternalApiUsage;
usage: Usage; usage: Usage;
} }

View File

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

View File

@@ -175,23 +175,11 @@ export class ModelEditorModule extends DisposableObject {
await ensureDir(this.queryStorageDir); 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); 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); await this.methodModelingPanel.setMethod(method);
} }
} }

View File

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

View File

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