From 7edb02197ed353716a923b687c3ee591a38004af Mon Sep 17 00:00:00 2001 From: Maruf Rasully <100434800+marufrasully@users.noreply.github.com> Date: Mon, 11 Mar 2024 18:39:57 +0100 Subject: [PATCH] fix: semantic model for UI5, starting from version 1.121.0 (#696) * fix: semantic model for UI5 starting with 1.121.0 version * fix: add change set * fix: coverage --- .changeset/new-jeans-crash.md | 10 +++++++ .../logic-utils/src/utils/type-to-string.ts | 2 +- packages/semantic-model-types/api.d.ts | 2 +- packages/semantic-model/src/convert.ts | 10 ++++++- packages/semantic-model/src/resolve.ts | 26 +++++++++++++++++++ .../semantic-model/test/unit/unit.test.ts | 22 ++++++++++++++++ test-packages/test-utils/api.d.ts | 2 +- test-packages/test-utils/src/api.ts | 2 +- .../src/utils/semantic-model-provider.ts | 4 +-- 9 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 .changeset/new-jeans-crash.md diff --git a/.changeset/new-jeans-crash.md b/.changeset/new-jeans-crash.md new file mode 100644 index 000000000..6986403c0 --- /dev/null +++ b/.changeset/new-jeans-crash.md @@ -0,0 +1,10 @@ +--- +"@ui5-language-assistant/test-utils": patch +"@ui5-language-assistant/semantic-model": patch +"vscode-ui5-language-assistant": patch +"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch +"@ui5-language-assistant/semantic-model-types": patch +"@ui5-language-assistant/logic-utils": patch +--- + +Fix semantic model for UI5, starting from version 1.121.0 diff --git a/packages/logic-utils/src/utils/type-to-string.ts b/packages/logic-utils/src/utils/type-to-string.ts index 470dc3a64..b2a425721 100644 --- a/packages/logic-utils/src/utils/type-to-string.ts +++ b/packages/logic-utils/src/utils/type-to-string.ts @@ -14,7 +14,7 @@ export function typeToString(type: UI5Type | undefined): string { return typeToString(type.type) + "[]"; case "PrimitiveType": case "UnresolvedType": - return type.name; + return Array.isArray(type.name) ? type.name.join(",") : type.name; default: return "any"; } diff --git a/packages/semantic-model-types/api.d.ts b/packages/semantic-model-types/api.d.ts index 259d62d37..0cd36497d 100644 --- a/packages/semantic-model-types/api.d.ts +++ b/packages/semantic-model-types/api.d.ts @@ -196,7 +196,7 @@ export interface PrimitiveType { export interface UnresolvedType { kind: "UnresolvedType"; - name: string; + name: string | string[]; } export type UI5Type = diff --git a/packages/semantic-model/src/convert.ts b/packages/semantic-model/src/convert.ts index 5aa50b592..c3e81afe6 100644 --- a/packages/semantic-model/src/convert.ts +++ b/packages/semantic-model/src/convert.ts @@ -93,7 +93,15 @@ function convertLibraryToSemanticModel( return model; } for (const symbol of lib.symbols) { - const fqn = symbol.name; + let fqn = symbol.name; + /** + * Workaround to fix namespace miss match of the `sap.fe.core.controls.buildingBlocks.BuildingBlockBase` and + * "sap.fe.macros.MacroAPI" which extends "sap.fe.core.buildingBlocks.BuildingBlockBase" + * This is a workaround and should be removed once issue is fixed. + */ + if (fqn === "sap.fe.core.controls.buildingBlocks.BuildingBlockBase") { + fqn = "sap.fe.core.buildingBlocks.BuildingBlockBase"; + } if (has(jsonSymbols, fqn)) { error( `${libName}: Duplicate symbol found: ${symbol.kind} ${fqn}. First occurrence is a ${jsonSymbols[fqn].kind}.`, diff --git a/packages/semantic-model/src/resolve.ts b/packages/semantic-model/src/resolve.ts index f65f6756b..48104a666 100644 --- a/packages/semantic-model/src/resolve.ts +++ b/packages/semantic-model/src/resolve.ts @@ -314,6 +314,31 @@ export function resolveType({ if (type === undefined || type.kind !== "UnresolvedType") { return type; } + /** + * JSDoc uses usually `|` to represent union type, but + * starting with UI5 version 1.121.1, it may use `,`. For instance aggregation actions of `sap.fe.macros.Table` is represented by "sap.fe.macros.table.Action,sap.fe.macros.table.ActionGroup" + * Todo: Alignment on union type representation is required. + */ + if (Array.isArray(type.name)) { + const types: UI5Type[] = []; + for (const t of type.name) { + const resolvedType = resolveType({ + model, + type: t, + typeNameFix, + strict, + typedef, + }); + if (!resolvedType) { + continue; + } + types.push(resolvedType); + } + return { + kind: "UnionType", + types, + }; + } const typeName = fixTypeName(type.name, typeNameFix); if (typeName === undefined) { @@ -344,6 +369,7 @@ export function resolveType({ name: primitiveTypeName, }; } + if (typeName.startsWith("Array<(")) { const innerTypeName = typeName.slice( typeName.indexOf("(") + 1, diff --git a/packages/semantic-model/test/unit/unit.test.ts b/packages/semantic-model/test/unit/unit.test.ts index 2a463d1e9..caa33d9a0 100644 --- a/packages/semantic-model/test/unit/unit.test.ts +++ b/packages/semantic-model/test/unit/unit.test.ts @@ -9,6 +9,7 @@ import { UI5Class, UI5SemanticModel, UI5Type, + UnresolvedType, } from "@ui5-language-assistant/semantic-model-types"; import { resolveType, setParent } from "../../src/resolve"; import { getSymbolMaps } from "../../src/utils"; @@ -33,6 +34,27 @@ describe("The ui5-language-assistant semantic model package unit tests", () => { }) ).toEqual(stringPrimitiveType); }); + + it("unresolved type - array", () => { + const model = buildUI5Model({}); + model.classes["sap.fe.macros.table.Action"] = {} as UI5Class; + model.classes["sap.fe.macros.table.ActionGroup"] = {} as UI5Class; + + const type: UnresolvedType = { + kind: "UnresolvedType", + name: ["sap.fe.macros.table.Action", "sap.fe.macros.table.ActionGroup"], + }; + const result = resolveType({ + model, + type: type, + typeNameFix: {}, + strict: true, + }); + expect(result).toEqual({ + kind: "UnionType", + types: [{}, {}], + }); + }); }); describe("setParent", () => { diff --git a/test-packages/test-utils/api.d.ts b/test-packages/test-utils/api.d.ts index 46fb43006..75c7ddb75 100644 --- a/test-packages/test-utils/api.d.ts +++ b/test-packages/test-utils/api.d.ts @@ -88,7 +88,7 @@ export function buildUI5Model>( opts: Partial ): UI5SemanticModel & Pick; -export const DEFAULT_UI5_VERSION = "1.71.61"; +export const DEFAULT_UI5_VERSION = "1.71.64"; // TODO: list should be updated continuously! export type TestModelVersion = diff --git a/test-packages/test-utils/src/api.ts b/test-packages/test-utils/src/api.ts index 72db103ea..636b0763c 100644 --- a/test-packages/test-utils/src/api.ts +++ b/test-packages/test-utils/src/api.ts @@ -31,4 +31,4 @@ export { } from "./utils/expect"; export { getFallbackPatchVersions } from "./utils/download-ui5-resources"; -export const DEFAULT_UI5_VERSION = "1.71.61"; +export const DEFAULT_UI5_VERSION = "1.71.64"; diff --git a/test-packages/test-utils/src/utils/semantic-model-provider.ts b/test-packages/test-utils/src/utils/semantic-model-provider.ts index a14b4fc02..8a4370bcb 100644 --- a/test-packages/test-utils/src/utils/semantic-model-provider.ts +++ b/test-packages/test-utils/src/utils/semantic-model-provider.ts @@ -14,7 +14,7 @@ const MODEL_CACHE: Record = Object.create(null); const fixes: Record = { - "1.71.61": { + "1.71.64": { array: "any[]", Array: "any[]", bloolean: undefined, @@ -258,7 +258,7 @@ type LibraryFix = (content: Json) => void; // Library version -> library name -> fix function const libraryFixes: Record> = { - "1.71.61": {}, + "1.71.64": {}, "1.84.41": {}, "1.96.27": { "sap.ui.mdc": [