Merge pull request #2926 from github/robertbrignull/JumpToUsageMessage

Only include method signature in JumpToUsageMessage
This commit is contained in:
Robert
2023-10-10 11:12:36 +01:00
committed by GitHub
7 changed files with 44 additions and 36 deletions

View File

@@ -12,7 +12,6 @@ import type {
} from "../variant-analysis/shared/variant-analysis";
import type { QLDebugConfiguration } from "../debugger/debug-configuration";
import type { QueryTreeViewItem } from "../queries-panel/query-tree-view-item";
import type { Method, Usage } from "../model-editor/method";
// A command function matching the signature that VS Code calls when
// a command is invoked from a context menu on a TreeView with
@@ -324,9 +323,8 @@ export type PackagingCommands = {
export type ModelEditorCommands = {
"codeQL.openModelEditor": () => Promise<void>;
"codeQL.openModelEditorFromModelingPanel": () => Promise<void>;
"codeQLModelEditor.jumpToUsageLocation": (
method: Method,
usage: Usage,
"codeQLModelEditor.jumpToMethod": (
methodSignature: string,
databaseItem: DatabaseItem,
) => Promise<void>;
};

View File

@@ -17,7 +17,7 @@ import {
} from "../variant-analysis/shared/variant-analysis-filter-sort";
import { ErrorLike } from "../common/errors";
import { DataFlowPaths } from "../variant-analysis/shared/data-flow-paths";
import { Method, Usage } from "../model-editor/method";
import { Method } from "../model-editor/method";
import { ModeledMethod } from "../model-editor/modeled-method";
import {
MethodModelingPanelViewState,
@@ -526,10 +526,9 @@ interface SwitchModeMessage {
mode: Mode;
}
interface JumpToUsageMessage {
t: "jumpToUsage";
method: Method;
usage: Usage;
interface JumpToMethodMessage {
t: "jumpToMethod";
methodSignature: string;
}
interface OpenDatabaseMessage {
@@ -602,7 +601,7 @@ export type FromModelEditorMessage =
| RefreshMethods
| OpenDatabaseMessage
| OpenExtensionPackMessage
| JumpToUsageMessage
| JumpToMethodMessage
| SaveModeledMethods
| GenerateMethodMessage
| GenerateMethodsFromLlmMessage

View File

@@ -83,6 +83,9 @@ export class MethodsUsageDataProvider
};
} else {
const method = this.getParent(item);
if (!method || !isExternalApiUsage(method)) {
throw new Error("Parent not found for tree item");
}
return {
label: item.label,
description: `${this.relativePathWithinDatabase(item.url.uri)} [${
@@ -91,8 +94,8 @@ export class MethodsUsageDataProvider
collapsibleState: TreeItemCollapsibleState.None,
command: {
title: "Show usage",
command: "codeQLModelEditor.jumpToUsageLocation",
arguments: [method, item, this.databaseItem],
command: "codeQLModelEditor.jumpToMethod",
arguments: [method.signature, this.databaseItem],
},
};
}

View File

@@ -77,12 +77,11 @@ export class ModelEditorModule extends DisposableObject {
"codeQL.openModelEditor": this.openModelEditor.bind(this),
"codeQL.openModelEditorFromModelingPanel":
this.openModelEditor.bind(this),
"codeQLModelEditor.jumpToUsageLocation": async (
method: Method,
usage: Usage,
"codeQLModelEditor.jumpToMethod": async (
methodSignature: string,
databaseItem: DatabaseItem,
) => {
this.modelingStore.setSelectedMethod(databaseItem, method, usage);
this.modelingStore.setSelectedMethod(databaseItem, methodSignature);
},
};
}

View File

@@ -31,7 +31,7 @@ import {
externalApiQueriesProgressMaxStep,
runExternalApiQueries,
} from "./external-api-usage-queries";
import { Method, Usage } from "./method";
import { Method } from "./method";
import { ModeledMethod } from "./modeled-method";
import { ExtensionPack } from "./shared/extension-pack";
import { ModelConfigListener } from "../config";
@@ -197,9 +197,11 @@ export class ModelEditorView extends AbstractWebview<
);
break;
case "jumpToUsage":
await this.handleJumpToUsage(msg.method, msg.usage);
void telemetryListener?.sendUIInteraction("model-editor-jump-to-usage");
case "jumpToMethod":
await this.handleJumpToMethod(msg.methodSignature);
void telemetryListener?.sendUIInteraction(
"model-editor-jump-to-method",
);
break;
case "saveModeledMethods":
@@ -363,8 +365,8 @@ export class ModelEditorView extends AbstractWebview<
});
}
protected async handleJumpToUsage(method: Method, usage: Usage) {
this.modelingStore.setSelectedMethod(this.databaseItem, method, usage);
protected async handleJumpToMethod(methodSignature: string) {
this.modelingStore.setSelectedMethod(this.databaseItem, methodSignature);
}
protected async loadExistingModeledMethods(): Promise<void> {

View File

@@ -311,9 +311,18 @@ export class ModelingStore extends DisposableObject {
});
}
public setSelectedMethod(dbItem: DatabaseItem, method: Method, usage: Usage) {
public setSelectedMethod(dbItem: DatabaseItem, methodSignature: string) {
const dbState = this.getState(dbItem);
const method = dbState.methods.find((m) => m.signature === methodSignature);
if (method === undefined) {
throw new Error(
`No method with signature "${methodSignature}" found in modeling store`,
);
}
const usage = method.usages[0];
dbState.selectedMethod = method;
dbState.selectedUsage = usage;

View File

@@ -107,8 +107,8 @@ const ModelableMethodRow = forwardRef<HTMLElement | undefined, MethodRowProps>(
? modeledMethodsProp
: modeledMethodsProp.slice(0, 1);
const jumpToUsage = useCallback(
() => sendJumpToUsageMessage(method),
const jumpToMethod = useCallback(
() => sendJumpToMethodMessage(method),
[method],
);
@@ -126,11 +126,11 @@ const ModelableMethodRow = forwardRef<HTMLElement | undefined, MethodRowProps>(
<MethodClassifications method={method} />
<MethodName {...props.method} />
{viewState.mode === Mode.Application && (
<UsagesButton onClick={jumpToUsage}>
<UsagesButton onClick={jumpToMethod}>
{method.usages.length}
</UsagesButton>
)}
<ViewLink onClick={jumpToUsage}>View</ViewLink>
<ViewLink onClick={jumpToMethod}>View</ViewLink>
{props.modelingInProgress && <ProgressRing />}
</ApiOrMethodRow>
</VSCodeDataGridCell>
@@ -206,8 +206,8 @@ const UnmodelableMethodRow = forwardRef<
>((props, ref) => {
const { method, viewState, revealedMethodSignature } = props;
const jumpToUsage = useCallback(
() => sendJumpToUsageMessage(method),
const jumpToMethod = useCallback(
() => sendJumpToMethodMessage(method),
[method],
);
@@ -222,11 +222,11 @@ const UnmodelableMethodRow = forwardRef<
<ModelingStatusIndicator status="saved" />
<MethodName {...props.method} />
{viewState.mode === Mode.Application && (
<UsagesButton onClick={jumpToUsage}>
<UsagesButton onClick={jumpToMethod}>
{method.usages.length}
</UsagesButton>
)}
<ViewLink onClick={jumpToUsage}>View</ViewLink>
<ViewLink onClick={jumpToMethod}>View</ViewLink>
<MethodClassifications method={method} />
</ApiOrMethodRow>
</VSCodeDataGridCell>
@@ -238,12 +238,10 @@ const UnmodelableMethodRow = forwardRef<
});
UnmodelableMethodRow.displayName = "UnmodelableMethodRow";
function sendJumpToUsageMessage(method: Method) {
function sendJumpToMethodMessage(method: Method) {
vscode.postMessage({
t: "jumpToUsage",
method,
// In framework mode, the first and only usage is the definition of the method
usage: method.usages[0],
t: "jumpToMethod",
methodSignature: method.signature,
});
}