Skip to content

Commit b1a4586

Browse files
Merge pull request #2977 from github/robertbrignull/fix_jump_to_usage
Revert changes to codeQLModelEditor.jumpToMethod to allow jumping to usages other than the first usage
2 parents aa8896e + 9134e0e commit b1a4586

5 files changed

Lines changed: 39 additions & 15 deletions

File tree

extensions/ql-vscode/src/common/commands.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
import type { QLDebugConfiguration } from "../debugger/debug-configuration";
1414
import type { QueryTreeViewItem } from "../queries-panel/query-tree-view-item";
1515
import type { LanguageSelectionTreeViewItem } from "../language-selection-panel/language-selection-data-provider";
16+
import type { Method, Usage } from "../model-editor/method";
1617

1718
// A command function matching the signature that VS Code calls when
1819
// a command is invoked from a context menu on a TreeView with
@@ -333,7 +334,8 @@ export type ModelEditorCommands = {
333334
"codeQL.openModelEditor": () => Promise<void>;
334335
"codeQL.openModelEditorFromModelingPanel": () => Promise<void>;
335336
"codeQLModelEditor.jumpToMethod": (
336-
methodSignature: string,
337+
method: Method,
338+
usage: Usage,
337339
databaseItem: DatabaseItem,
338340
) => Promise<void>;
339341
};

extensions/ql-vscode/src/model-editor/methods-usage/methods-usage-data-provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export class MethodsUsageDataProvider
106106
command: {
107107
title: "Show usage",
108108
command: "codeQLModelEditor.jumpToMethod",
109-
arguments: [method.signature, this.databaseItem],
109+
arguments: [method, item, this.databaseItem],
110110
},
111111
};
112112
}

extensions/ql-vscode/src/model-editor/model-editor-module.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,11 @@ export class ModelEditorModule extends DisposableObject {
7777
"codeQL.openModelEditorFromModelingPanel":
7878
this.openModelEditor.bind(this),
7979
"codeQLModelEditor.jumpToMethod": async (
80-
methodSignature: string,
80+
method: Method,
81+
usage: Usage,
8182
databaseItem: DatabaseItem,
8283
) => {
83-
this.modelingStore.setSelectedMethod(databaseItem, methodSignature);
84+
this.modelingStore.setSelectedMethod(databaseItem, method, usage);
8485
},
8586
};
8687
}

extensions/ql-vscode/src/model-editor/model-editor-view.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,17 @@ export class ModelEditorView extends AbstractWebview<
374374
}
375375

376376
protected async handleJumpToMethod(methodSignature: string) {
377-
this.modelingStore.setSelectedMethod(this.databaseItem, methodSignature);
377+
const method = this.modelingStore.getMethod(
378+
this.databaseItem,
379+
methodSignature,
380+
);
381+
if (method) {
382+
this.modelingStore.setSelectedMethod(
383+
this.databaseItem,
384+
method,
385+
method.usages[0],
386+
);
387+
}
378388
}
379389

380390
protected async loadExistingModeledMethods(): Promise<void> {

extensions/ql-vscode/src/model-editor/modeling-store.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,19 @@ export class ModelingStore extends DisposableObject {
230230
return this.state.size > 0;
231231
}
232232

233+
/**
234+
* Returns the method for the given database item and method signature.
235+
* Returns undefined if no method exists with that signature.
236+
*/
237+
public getMethod(
238+
dbItem: DatabaseItem,
239+
methodSignature: string,
240+
): Method | undefined {
241+
return this.getState(dbItem).methods.find(
242+
(m) => m.signature === methodSignature,
243+
);
244+
}
245+
233246
/**
234247
* Returns the methods for the given database item and method signatures.
235248
* If the `methodSignatures` argument is not provided or is undefined, returns all methods.
@@ -388,18 +401,16 @@ export class ModelingStore extends DisposableObject {
388401
});
389402
}
390403

391-
public setSelectedMethod(dbItem: DatabaseItem, methodSignature: string) {
404+
/**
405+
* Sets which method is considered to be selected. This method will be shown in the method modeling panel.
406+
*
407+
* The `Method` and `Usage` objects must have been retrieved from the modeling store, and not from
408+
* a webview. This is because we rely on object referential identity so it must be the same object
409+
* that is held internally by the modeling store.
410+
*/
411+
public setSelectedMethod(dbItem: DatabaseItem, method: Method, usage: Usage) {
392412
const dbState = this.getState(dbItem);
393413

394-
const method = dbState.methods.find((m) => m.signature === methodSignature);
395-
if (method === undefined) {
396-
throw new Error(
397-
`No method with signature "${methodSignature}" found in modeling store`,
398-
);
399-
}
400-
401-
const usage = method.usages[0];
402-
403414
dbState.selectedMethod = method;
404415
dbState.selectedUsage = usage;
405416

0 commit comments

Comments
 (0)