Add access path suggestions to MaD model for Ruby (#3303)
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
|||||||
rubyMethodSignature,
|
rubyMethodSignature,
|
||||||
rubyPath,
|
rubyPath,
|
||||||
} from "./access-paths";
|
} from "./access-paths";
|
||||||
|
import { parseAccessPathSuggestionsResults } from "./suggestions";
|
||||||
|
|
||||||
export const ruby: ModelsAsDataLanguage = {
|
export const ruby: ModelsAsDataLanguage = {
|
||||||
availableModes: [Mode.Framework],
|
availableModes: [Mode.Framework],
|
||||||
@@ -168,6 +169,9 @@ export const ruby: ModelsAsDataLanguage = {
|
|||||||
},
|
},
|
||||||
parseResults: parseGenerateModelResults,
|
parseResults: parseGenerateModelResults,
|
||||||
},
|
},
|
||||||
|
accessPathSuggestions: {
|
||||||
|
parseResults: parseAccessPathSuggestionsResults,
|
||||||
|
},
|
||||||
getArgumentOptions: (method) => {
|
getArgumentOptions: (method) => {
|
||||||
const argumentsList = getArgumentsList(method.methodParameters).map(
|
const argumentsList = getArgumentsList(method.methodParameters).map(
|
||||||
(argument, index): MethodArgument => {
|
(argument, index): MethodArgument => {
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
import type { BaseLogger } from "../../../common/logging";
|
||||||
|
import type { DecodedBqrsChunk } from "../../../common/bqrs-cli-types";
|
||||||
|
import type { ModelsAsDataLanguage } from "../models-as-data";
|
||||||
|
import type { AccessPathSuggestionRow } from "../../suggestions";
|
||||||
|
import { isDefinitionType } from "../../suggestions";
|
||||||
|
import { parseRubyMethodFromPath, rubyMethodSignature } from "./access-paths";
|
||||||
|
|
||||||
|
export function parseAccessPathSuggestionsResults(
|
||||||
|
bqrs: DecodedBqrsChunk,
|
||||||
|
_modelsAsDataLanguage: ModelsAsDataLanguage,
|
||||||
|
logger: BaseLogger,
|
||||||
|
): AccessPathSuggestionRow[] {
|
||||||
|
return bqrs.tuples
|
||||||
|
.map((tuple, index): AccessPathSuggestionRow | null => {
|
||||||
|
const row = tuple.filter(
|
||||||
|
(value): value is string => typeof value === "string",
|
||||||
|
);
|
||||||
|
|
||||||
|
if (row.length !== 5) {
|
||||||
|
void logger.log(
|
||||||
|
`Skipping result ${index} because it has the wrong length`,
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const type = row[0];
|
||||||
|
const methodName = parseRubyMethodFromPath(row[1]);
|
||||||
|
const value = row[2];
|
||||||
|
const details = row[3];
|
||||||
|
const definitionType = row[4];
|
||||||
|
|
||||||
|
if (!isDefinitionType(definitionType)) {
|
||||||
|
void logger.log(
|
||||||
|
`Skipping result ${index} because it has an invalid definition type`,
|
||||||
|
);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
method: {
|
||||||
|
packageName: "",
|
||||||
|
typeName: type,
|
||||||
|
methodName,
|
||||||
|
methodParameters: "",
|
||||||
|
signature: rubyMethodSignature(type, methodName),
|
||||||
|
},
|
||||||
|
value,
|
||||||
|
details,
|
||||||
|
definitionType,
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.filter(
|
||||||
|
(suggestion): suggestion is AccessPathSuggestionRow =>
|
||||||
|
suggestion !== null,
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -37,3 +37,11 @@ export type AccessPathOption = {
|
|||||||
details?: string;
|
details?: string;
|
||||||
followup?: AccessPathOption[];
|
followup?: AccessPathOption[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function isDefinitionType(
|
||||||
|
value: string,
|
||||||
|
): value is AccessPathSuggestionDefinitionType {
|
||||||
|
return Object.values(AccessPathSuggestionDefinitionType).includes(
|
||||||
|
value as AccessPathSuggestionDefinitionType,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
import type { DecodedBqrsChunk } from "../../../../../src/common/bqrs-cli-types";
|
||||||
|
import { ruby } from "../../../../../src/model-editor/languages/ruby";
|
||||||
|
import { createMockLogger } from "../../../../__mocks__/loggerMock";
|
||||||
|
import { parseAccessPathSuggestionsResults } from "../../../../../src/model-editor/languages/ruby/suggestions";
|
||||||
|
|
||||||
|
describe("parseAccessPathSuggestionsResults", () => {
|
||||||
|
it("should parse the results", async () => {
|
||||||
|
const bqrsChunk: DecodedBqrsChunk = {
|
||||||
|
columns: [
|
||||||
|
{
|
||||||
|
name: "type",
|
||||||
|
kind: "String",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "path",
|
||||||
|
kind: "String",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "value",
|
||||||
|
kind: "String",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "details",
|
||||||
|
kind: "String",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "defType",
|
||||||
|
kind: "String",
|
||||||
|
},
|
||||||
|
],
|
||||||
|
tuples: [
|
||||||
|
[
|
||||||
|
"Correctness",
|
||||||
|
"Method[assert!]",
|
||||||
|
"Argument[self]",
|
||||||
|
"self in assert!",
|
||||||
|
"parameter",
|
||||||
|
],
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const result = parseAccessPathSuggestionsResults(
|
||||||
|
bqrsChunk,
|
||||||
|
ruby,
|
||||||
|
createMockLogger(),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result).toEqual([
|
||||||
|
{
|
||||||
|
method: {
|
||||||
|
packageName: "",
|
||||||
|
typeName: "Correctness",
|
||||||
|
methodName: "assert!",
|
||||||
|
methodParameters: "",
|
||||||
|
signature: "Correctness#assert!",
|
||||||
|
},
|
||||||
|
value: "Argument[self]",
|
||||||
|
details: "self in assert!",
|
||||||
|
definitionType: "parameter",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user