Merge pull request #3297 from github/koesie10/more-consistency-information

Add more information for consistency check errors
This commit is contained in:
Koen Vlaswinkel
2024-01-31 16:26:45 +01:00
committed by GitHub
2 changed files with 18 additions and 7 deletions

View File

@@ -3,7 +3,10 @@ import type { ModeledMethod } from "./modeled-method";
import type { BaseLogger } from "../common/logging";
interface Notifier {
missingMethod(signature: string): void;
missingMethod(
signature: string,
modeledMethods: readonly ModeledMethod[],
): void;
inconsistentSupported(signature: string, expectedSupported: boolean): void;
}
@@ -21,14 +24,14 @@ export function checkConsistency(
);
for (const signature in modeledMethods) {
const modeledMethodsForSignature = modeledMethods[signature];
const method = methodsBySignature[signature];
if (!method) {
notifier.missingMethod(signature);
notifier.missingMethod(signature, modeledMethodsForSignature);
continue;
}
const modeledMethodsForSignature = modeledMethods[signature];
checkMethodConsistency(method, modeledMethodsForSignature, notifier);
}
}
@@ -51,9 +54,14 @@ function checkMethodConsistency(
export class DefaultNotifier implements Notifier {
constructor(private readonly logger: BaseLogger) {}
missingMethod(signature: string) {
missingMethod(signature: string, modeledMethods: readonly ModeledMethod[]) {
const modelTypes = modeledMethods
.map((m) => m.type)
.filter((t) => t !== "none")
.join(", ");
void this.logger.log(
`Model editor query consistency check: Missing method ${signature} for method that is modeled.`,
`Model editor query consistency check: Missing method ${signature} for method that is modeled as ${modelTypes}`,
);
}

View File

@@ -14,17 +14,20 @@ describe("checkConsistency", () => {
});
it("should call missingMethod when method is missing", () => {
const modeledMethods = [createSourceModeledMethod()];
checkConsistency(
[],
{
"Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SeparatedList`1(System.Collections.Generic.IEnumerable<TNode>)":
[createSourceModeledMethod()],
modeledMethods,
},
notifier,
);
expect(notifier.missingMethod).toHaveBeenCalledWith(
"Microsoft.CodeAnalysis.CSharp.SyntaxFactory.SeparatedList`1(System.Collections.Generic.IEnumerable<TNode>)",
modeledMethods,
);
expect(notifier.inconsistentSupported).not.toHaveBeenCalled();
});