Skip to content

Commit

Permalink
fix: semantic model for UI5, starting from version 1.121.0 (#696)
Browse files Browse the repository at this point in the history
* fix: semantic model for UI5 starting with 1.121.0 version

* fix: add change set

* fix: coverage
  • Loading branch information
marufrasully committed Mar 11, 2024
1 parent 44114f3 commit 7edb021
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 7 deletions.
10 changes: 10 additions & 0 deletions .changeset/new-jeans-crash.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion packages/logic-utils/src/utils/type-to-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
2 changes: 1 addition & 1 deletion packages/semantic-model-types/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export interface PrimitiveType {

export interface UnresolvedType {
kind: "UnresolvedType";
name: string;
name: string | string[];
}

export type UI5Type =
Expand Down
10 changes: 9 additions & 1 deletion packages/semantic-model/src/convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}.`,
Expand Down
26 changes: 26 additions & 0 deletions packages/semantic-model/src/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -344,6 +369,7 @@ export function resolveType({
name: primitiveTypeName,
};
}

if (typeName.startsWith("Array<(")) {
const innerTypeName = typeName.slice(
typeName.indexOf("(") + 1,
Expand Down
22 changes: 22 additions & 0 deletions packages/semantic-model/test/unit/unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion test-packages/test-utils/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function buildUI5Model<T extends Partial<UI5SemanticModel>>(
opts: Partial<UI5SemanticModel>
): UI5SemanticModel & Pick<T, keyof UI5SemanticModel>;

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 =
Expand Down
2 changes: 1 addition & 1 deletion test-packages/test-utils/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
4 changes: 2 additions & 2 deletions test-packages/test-utils/src/utils/semantic-model-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const MODEL_CACHE: Record<TestModelVersion, UI5SemanticModel> =
Object.create(null);

const fixes: Record<TestModelVersion, TypeNameFix> = {
"1.71.61": {
"1.71.64": {
array: "any[]",
Array: "any[]",
bloolean: undefined,
Expand Down Expand Up @@ -258,7 +258,7 @@ type LibraryFix = (content: Json) => void;

// Library version -> library name -> fix function
const libraryFixes: Record<TestModelVersion, Record<string, LibraryFix[]>> = {
"1.71.61": {},
"1.71.64": {},
"1.84.41": {},
"1.96.27": {
"sap.ui.mdc": [
Expand Down

0 comments on commit 7edb021

Please sign in to comment.