Skip to content

Commit

Permalink
Merge pull request #2942 from github/robertbrignull/SetModeledMethods…
Browse files Browse the repository at this point in the history
…Message

Convert SetModeledMethodsMessage to include multiple modeled methods
  • Loading branch information
robertbrignull authored Oct 11, 2023
2 parents 2b47d3d + 62c9e51 commit c459d0f
Show file tree
Hide file tree
Showing 14 changed files with 202 additions and 200 deletions.
2 changes: 1 addition & 1 deletion extensions/ql-vscode/src/common/interface-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ interface SetMethodsMessage {

interface SetModeledMethodsMessage {
t: "setModeledMethods";
methods: Record<string, ModeledMethod>;
methods: Record<string, ModeledMethod[]>;
}

interface SetModifiedMethodsMessage {
Expand Down
4 changes: 2 additions & 2 deletions extensions/ql-vscode/src/model-editor/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@ export function getArgumentsList(methodParameters: string): string[] {

export function canMethodBeModeled(
method: Method,
modeledMethod: ModeledMethod | undefined,
modeledMethods: ModeledMethod[],
methodIsUnsaved: boolean,
): boolean {
return (
!method.supported ||
(modeledMethod && modeledMethod?.type !== "none") ||
modeledMethods.some((modeledMethod) => modeledMethod.type !== "none") ||
methodIsUnsaved
);
}
7 changes: 2 additions & 5 deletions extensions/ql-vscode/src/model-editor/model-editor-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ import { AutoModeler } from "./auto-modeler";
import { telemetryListener } from "../common/vscode/telemetry";
import { ModelingStore } from "./modeling-store";
import { ModelEditorViewTracker } from "./model-editor-view-tracker";
import {
convertFromLegacyModeledMethod,
convertToLegacyModeledMethods,
} from "./shared/modeled-methods-legacy";
import { convertFromLegacyModeledMethod } from "./shared/modeled-methods-legacy";

export class ModelEditorView extends AbstractWebview<
ToModelEditorMessage,
Expand Down Expand Up @@ -640,7 +637,7 @@ export class ModelEditorView extends AbstractWebview<
if (event.dbUri === this.databaseItem.databaseUri.toString()) {
await this.postMessage({
t: "setModeledMethods",
methods: convertToLegacyModeledMethods(event.modeledMethods),
methods: event.modeledMethods,
});
}
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,5 @@
import { ModeledMethod } from "../modeled-method";

/**
* Converts a record of a single ModeledMethod indexed by signature to a record of ModeledMethod[] indexed by signature
* for legacy usage. This function should always be used instead of the trivial conversion to track usages of this
* conversion.
*
* This method should only be called inside a `postMessage` call. If it's used anywhere else, consider whether the
* boundary is correct: the boundary should as close as possible to the extension host -> webview boundary.
*
* @param modeledMethods The record of a single ModeledMethod indexed by signature
*/
export function convertToLegacyModeledMethods(
modeledMethods: Record<string, ModeledMethod[]>,
): Record<string, ModeledMethod> {
// Always take the first modeled method in the array
return Object.fromEntries(
Object.entries(modeledMethods)
.map(([signature, modeledMethods]) => {
const modeledMethod = convertToLegacyModeledMethod(modeledMethods);
if (!modeledMethod) {
return null;
}
return [signature, modeledMethod];
})
.filter((entry): entry is [string, ModeledMethod] => entry !== null),
);
}

/**
* Converts a single ModeledMethod to a ModeledMethod[] for legacy usage. This function should always be used instead
* of the trivial conversion to track usages of this conversion.
Expand Down
132 changes: 71 additions & 61 deletions extensions/ql-vscode/src/stories/model-editor/LibraryRow.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,67 +146,77 @@ LibraryRow.args = {
],
},
],
modeledMethods: {
"org.sql2o.Sql2o#Sql2o(String)": {
type: "sink",
input: "Argument[0]",
output: "",
kind: "jndi-injection",
provenance: "df-generated",
signature: "org.sql2o.Sql2o#Sql2o(String)",
packageName: "org.sql2o",
typeName: "Sql2o",
methodName: "Sql2o",
methodParameters: "(String)",
},
"org.sql2o.Connection#createQuery(String)": {
type: "summary",
input: "Argument[this]",
output: "ReturnValue",
kind: "taint",
provenance: "df-manual",
signature: "org.sql2o.Connection#createQuery(String)",
packageName: "org.sql2o",
typeName: "Connection",
methodName: "createQuery",
methodParameters: "(String)",
},
"org.sql2o.Sql2o#open()": {
type: "summary",
input: "Argument[this]",
output: "ReturnValue",
kind: "taint",
provenance: "manual",
signature: "org.sql2o.Sql2o#open()",
packageName: "org.sql2o",
typeName: "Sql2o",
methodName: "open",
methodParameters: "()",
},
"org.sql2o.Query#executeScalar(Class)": {
type: "neutral",
input: "",
output: "",
kind: "",
provenance: "df-generated",
signature: "org.sql2o.Query#executeScalar(Class)",
packageName: "org.sql2o",
typeName: "Query",
methodName: "executeScalar",
methodParameters: "(Class)",
},
"org.sql2o.Sql2o#Sql2o(String,String,String)": {
type: "neutral",
input: "",
output: "",
kind: "",
provenance: "df-generated",
signature: "org.sql2o.Sql2o#Sql2o(String,String,String)",
packageName: "org.sql2o",
typeName: "Sql2o",
methodName: "Sql2o",
methodParameters: "(String,String,String)",
},
modeledMethodsMap: {
"org.sql2o.Sql2o#Sql2o(String)": [
{
type: "sink",
input: "Argument[0]",
output: "",
kind: "jndi-injection",
provenance: "df-generated",
signature: "org.sql2o.Sql2o#Sql2o(String)",
packageName: "org.sql2o",
typeName: "Sql2o",
methodName: "Sql2o",
methodParameters: "(String)",
},
],
"org.sql2o.Connection#createQuery(String)": [
{
type: "summary",
input: "Argument[this]",
output: "ReturnValue",
kind: "taint",
provenance: "df-manual",
signature: "org.sql2o.Connection#createQuery(String)",
packageName: "org.sql2o",
typeName: "Connection",
methodName: "createQuery",
methodParameters: "(String)",
},
],
"org.sql2o.Sql2o#open()": [
{
type: "summary",
input: "Argument[this]",
output: "ReturnValue",
kind: "taint",
provenance: "manual",
signature: "org.sql2o.Sql2o#open()",
packageName: "org.sql2o",
typeName: "Sql2o",
methodName: "open",
methodParameters: "()",
},
],
"org.sql2o.Query#executeScalar(Class)": [
{
type: "neutral",
input: "",
output: "",
kind: "",
provenance: "df-generated",
signature: "org.sql2o.Query#executeScalar(Class)",
packageName: "org.sql2o",
typeName: "Query",
methodName: "executeScalar",
methodParameters: "(Class)",
},
],
"org.sql2o.Sql2o#Sql2o(String,String,String)": [
{
type: "neutral",
input: "",
output: "",
kind: "",
provenance: "df-generated",
signature: "org.sql2o.Sql2o#Sql2o(String,String,String)",
packageName: "org.sql2o",
typeName: "Sql2o",
methodName: "Sql2o",
methodParameters: "(String,String,String)",
},
],
},
modifiedSignatures: new Set(["org.sql2o.Sql2o#Sql2o(String)"]),
inProgressMethods: new InProgressMethods(),
Expand Down
130 changes: 70 additions & 60 deletions extensions/ql-vscode/src/stories/model-editor/ModelEditor.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,65 +216,75 @@ ModelEditor.args = {
},
],
initialModeledMethods: {
"org.sql2o.Sql2o#Sql2o(String)": {
type: "sink",
input: "Argument[0]",
output: "",
kind: "jndi-injection",
provenance: "df-generated",
signature: "org.sql2o.Sql2o#Sql2o(String)",
packageName: "org.sql2o",
typeName: "Sql2o",
methodName: "Sql2o",
methodParameters: "(String)",
},
"org.sql2o.Connection#createQuery(String)": {
type: "summary",
input: "Argument[this]",
output: "ReturnValue",
kind: "taint",
provenance: "df-manual",
signature: "org.sql2o.Connection#createQuery(String)",
packageName: "org.sql2o",
typeName: "Connection",
methodName: "createQuery",
methodParameters: "(String)",
},
"org.sql2o.Sql2o#open()": {
type: "summary",
input: "Argument[this]",
output: "ReturnValue",
kind: "taint",
provenance: "manual",
signature: "org.sql2o.Sql2o#open()",
packageName: "org.sql2o",
typeName: "Sql2o",
methodName: "open",
methodParameters: "()",
},
"org.sql2o.Query#executeScalar(Class)": {
type: "neutral",
input: "",
output: "",
kind: "",
provenance: "df-generated",
signature: "org.sql2o.Query#executeScalar(Class)",
packageName: "org.sql2o",
typeName: "Query",
methodName: "executeScalar",
methodParameters: "(Class)",
},
"org.sql2o.Sql2o#Sql2o(String,String,String)": {
type: "neutral",
input: "",
output: "",
kind: "",
provenance: "df-generated",
signature: "org.sql2o.Sql2o#Sql2o(String,String,String)",
packageName: "org.sql2o",
typeName: "Sql2o",
methodName: "Sql2o",
methodParameters: "(String,String,String)",
},
"org.sql2o.Sql2o#Sql2o(String)": [
{
type: "sink",
input: "Argument[0]",
output: "",
kind: "jndi-injection",
provenance: "df-generated",
signature: "org.sql2o.Sql2o#Sql2o(String)",
packageName: "org.sql2o",
typeName: "Sql2o",
methodName: "Sql2o",
methodParameters: "(String)",
},
],
"org.sql2o.Connection#createQuery(String)": [
{
type: "summary",
input: "Argument[this]",
output: "ReturnValue",
kind: "taint",
provenance: "df-manual",
signature: "org.sql2o.Connection#createQuery(String)",
packageName: "org.sql2o",
typeName: "Connection",
methodName: "createQuery",
methodParameters: "(String)",
},
],
"org.sql2o.Sql2o#open()": [
{
type: "summary",
input: "Argument[this]",
output: "ReturnValue",
kind: "taint",
provenance: "manual",
signature: "org.sql2o.Sql2o#open()",
packageName: "org.sql2o",
typeName: "Sql2o",
methodName: "open",
methodParameters: "()",
},
],
"org.sql2o.Query#executeScalar(Class)": [
{
type: "neutral",
input: "",
output: "",
kind: "",
provenance: "df-generated",
signature: "org.sql2o.Query#executeScalar(Class)",
packageName: "org.sql2o",
typeName: "Query",
methodName: "executeScalar",
methodParameters: "(Class)",
},
],
"org.sql2o.Sql2o#Sql2o(String,String,String)": [
{
type: "neutral",
input: "",
output: "",
kind: "",
provenance: "df-generated",
signature: "org.sql2o.Sql2o#Sql2o(String,String,String)",
packageName: "org.sql2o",
typeName: "Sql2o",
methodName: "Sql2o",
methodParameters: "(String,String,String)",
},
],
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ export function MethodModelingView({ initialViewState }: Props): JSX.Element {
return <NoMethodSelected />;
}

if (!canMethodBeModeled(method, modeledMethod, isMethodModified)) {
if (
!canMethodBeModeled(
method,
convertFromLegacyModeledMethod(modeledMethod),
isMethodModified,
)
) {
return <MethodAlreadyModeled />;
}

Expand Down
6 changes: 3 additions & 3 deletions extensions/ql-vscode/src/view/model-editor/LibraryRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export type LibraryRowProps = {
title: string;
libraryVersion?: string;
methods: Method[];
modeledMethods: Record<string, ModeledMethod>;
modeledMethodsMap: Record<string, ModeledMethod[]>;
modifiedSignatures: Set<string>;
inProgressMethods: InProgressMethods;
viewState: ModelEditorViewState;
Expand All @@ -92,7 +92,7 @@ export const LibraryRow = ({
title,
libraryVersion,
methods,
modeledMethods,
modeledMethodsMap,
modifiedSignatures,
inProgressMethods,
viewState,
Expand Down Expand Up @@ -231,7 +231,7 @@ export const LibraryRow = ({
<ModeledMethodDataGrid
packageName={title}
methods={methods}
modeledMethods={modeledMethods}
modeledMethodsMap={modeledMethodsMap}
modifiedSignatures={modifiedSignatures}
inProgressMethods={inProgressMethods}
viewState={viewState}
Expand Down
Loading

0 comments on commit c459d0f

Please sign in to comment.