Parse new access paths query BQRS output
This commit is contained in:
@@ -1,10 +1,39 @@
|
||||
import type { BaseLogger } from "../../../common/logging";
|
||||
import type { DecodedBqrsChunk } from "../../../common/bqrs-cli-types";
|
||||
import type {
|
||||
BqrsCellValue,
|
||||
BqrsEntityValue,
|
||||
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";
|
||||
|
||||
function checkTupleFormat(
|
||||
tuple: BqrsCellValue[],
|
||||
): tuple is [string, string, string, BqrsEntityValue, string] {
|
||||
if (tuple.length !== 5) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const [type, methodName, value, node, definitionType] = tuple;
|
||||
if (
|
||||
typeof type !== "string" ||
|
||||
typeof methodName !== "string" ||
|
||||
typeof value !== "string" ||
|
||||
typeof node !== "object" ||
|
||||
typeof definitionType !== "string"
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Array.isArray(node)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export function parseAccessPathSuggestionsResults(
|
||||
bqrs: DecodedBqrsChunk,
|
||||
_modelsAsDataLanguage: ModelsAsDataLanguage,
|
||||
@@ -12,22 +41,18 @@ export function parseAccessPathSuggestionsResults(
|
||||
): AccessPathSuggestionRow[] {
|
||||
return bqrs.tuples
|
||||
.map((tuple, index): AccessPathSuggestionRow | null => {
|
||||
const row = tuple.filter(
|
||||
(value): value is string => typeof value === "string",
|
||||
);
|
||||
|
||||
if (row.length !== 5) {
|
||||
if (!checkTupleFormat(tuple)) {
|
||||
void logger.log(
|
||||
`Skipping result ${index} because it has the wrong length`,
|
||||
`Skipping result ${index} because it has the wrong format`,
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
const type = row[0];
|
||||
const methodName = parseRubyMethodFromPath(row[1]);
|
||||
const value = row[2];
|
||||
const details = row[3];
|
||||
const definitionType = row[4];
|
||||
const type = tuple[0];
|
||||
const methodName = parseRubyMethodFromPath(tuple[1]);
|
||||
const value = tuple[2];
|
||||
const node = tuple[3];
|
||||
const definitionType = tuple[4];
|
||||
|
||||
if (!isDefinitionType(definitionType)) {
|
||||
void logger.log(
|
||||
@@ -45,7 +70,7 @@ export function parseAccessPathSuggestionsResults(
|
||||
signature: rubyMethodSignature(type, methodName),
|
||||
},
|
||||
value,
|
||||
details,
|
||||
details: node.label ?? "",
|
||||
definitionType,
|
||||
};
|
||||
})
|
||||
|
||||
@@ -5,6 +5,65 @@ import { parseAccessPathSuggestionsResults } from "../../../../../src/model-edit
|
||||
|
||||
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: "node",
|
||||
kind: "Entity",
|
||||
},
|
||||
{
|
||||
name: "defType",
|
||||
kind: "String",
|
||||
},
|
||||
],
|
||||
tuples: [
|
||||
[
|
||||
"Correctness",
|
||||
"Method[assert!]",
|
||||
"Argument[self]",
|
||||
{
|
||||
label: "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",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it("should not parse an incorrect result format", async () => {
|
||||
const bqrsChunk: DecodedBqrsChunk = {
|
||||
columns: [
|
||||
{
|
||||
@@ -36,28 +95,20 @@ describe("parseAccessPathSuggestionsResults", () => {
|
||||
"self in assert!",
|
||||
"parameter",
|
||||
],
|
||||
["Correctness", "Method[assert!]", "Argument[self]", "parameter"],
|
||||
],
|
||||
};
|
||||
|
||||
const result = parseAccessPathSuggestionsResults(
|
||||
bqrsChunk,
|
||||
ruby,
|
||||
createMockLogger(),
|
||||
const logger = createMockLogger();
|
||||
expect(parseAccessPathSuggestionsResults(bqrsChunk, ruby, logger)).toEqual(
|
||||
[],
|
||||
);
|
||||
expect(logger.log).toHaveBeenCalledTimes(2);
|
||||
expect(logger.log).toHaveBeenCalledWith(
|
||||
"Skipping result 0 because it has the wrong format",
|
||||
);
|
||||
expect(logger.log).toHaveBeenCalledWith(
|
||||
"Skipping result 1 because it has the wrong format",
|
||||
);
|
||||
|
||||
expect(result).toEqual([
|
||||
{
|
||||
method: {
|
||||
packageName: "",
|
||||
typeName: "Correctness",
|
||||
methodName: "assert!",
|
||||
methodParameters: "",
|
||||
signature: "Correctness#assert!",
|
||||
},
|
||||
value: "Argument[self]",
|
||||
details: "self in assert!",
|
||||
definitionType: "parameter",
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,8 +29,8 @@ describe("runSuggestionsQuery", () => {
|
||||
kind: "String",
|
||||
},
|
||||
{
|
||||
name: "details",
|
||||
kind: "String",
|
||||
name: "node",
|
||||
kind: "Entity",
|
||||
},
|
||||
{
|
||||
name: "defType",
|
||||
@@ -42,7 +42,9 @@ describe("runSuggestionsQuery", () => {
|
||||
"Correctness",
|
||||
"Method[assert!]",
|
||||
"Argument[self]",
|
||||
"self in assert!",
|
||||
{
|
||||
label: "self in assert!",
|
||||
},
|
||||
"parameter",
|
||||
],
|
||||
],
|
||||
@@ -62,8 +64,8 @@ describe("runSuggestionsQuery", () => {
|
||||
kind: "String",
|
||||
},
|
||||
{
|
||||
name: "details",
|
||||
kind: "String",
|
||||
name: "node",
|
||||
kind: "Entity",
|
||||
},
|
||||
{
|
||||
name: "defType",
|
||||
@@ -75,14 +77,18 @@ describe("runSuggestionsQuery", () => {
|
||||
"Correctness",
|
||||
"Method[assert!]",
|
||||
"ReturnValue",
|
||||
"call to puts",
|
||||
{
|
||||
label: "call to puts",
|
||||
},
|
||||
"return",
|
||||
],
|
||||
[
|
||||
"Correctness",
|
||||
"Method[assert!]",
|
||||
"Argument[self]",
|
||||
"self in assert!",
|
||||
{
|
||||
label: "self in assert!",
|
||||
},
|
||||
"parameter",
|
||||
],
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user