Skip to content

Commit

Permalink
fix: relax diagnostic for special property (#708)
Browse files Browse the repository at this point in the history
* fix: relax diagnostic for special property

* fix: default fallback version
  • Loading branch information
marufrasully committed Apr 23, 2024
1 parent 49d45ee commit 98c33e7
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .changeset/fluffy-llamas-do.md
@@ -0,0 +1,7 @@
---
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch
"vscode-ui5-language-assistant": patch
"@ui5-language-assistant/binding": patch
---

fix: relax diagnostic for property which can be used with both aggregation binding info or property binding info
5 changes: 1 addition & 4 deletions packages/binding/src/definition/definition.ts
Expand Up @@ -18,7 +18,7 @@ import {
} from "../types";
import { ui5NodeToFQN } from "@ui5-language-assistant/logic-utils";
import { forOwn } from "lodash";
import { getDocumentation } from "../utils";
import { getAltTypesPrime, getDocumentation } from "../utils";
import { getFallBackElements } from "./fall-back-definition";
import { getSorterPossibleElement } from "./sorter";
import { getFiltersPossibleElement } from "./filter";
Expand Down Expand Up @@ -383,9 +383,6 @@ const buildType = (param: {
return propertyType;
};

const getAltTypesPrime = (aggregation?: UI5Aggregation) =>
aggregation?.altTypes?.find((i) => i.kind === "PrimitiveType");

const removeDuplicate = (builtType: PropertyType[]): PropertyType[] => {
const result = builtType.reduce(
(previous: PropertyType[], current: PropertyType) => {
Expand Down
@@ -1,24 +1,32 @@
import { findRange } from "../../../utils";
import { findRange, getAltTypesPrime } from "../../../utils";
import {
BindingIssue,
BINDING_ISSUE_TYPE,
BindingInfoElement,
} from "../../../types";
import { BindingParserTypes as BindingTypes } from "@ui5-language-assistant/binding-parser";
import { t } from "../../../i18n";
import { UI5Aggregation } from "@ui5-language-assistant/semantic-model-types";

export const checkRequiredElement = (
element: BindingTypes.StructureValue,
bindingElements: BindingInfoElement[]
bindingElements: BindingInfoElement[],
aggregation: UI5Aggregation | undefined
): BindingIssue[] => {
// check required element
const reqEl = bindingElements.find((i) => i.required);
if (reqEl) {
// check required element is applied
const usedRequiredEl = element.elements.find(
let usedRequiredEl = element.elements.find(
/* istanbul ignore next */
(i) => i.key?.text === reqEl.name
);
const altTypes = getAltTypesPrime(aggregation);
if (!usedRequiredEl && altTypes) {
// some property e.g `tooltip` can be used with both `aggregation binding info` or `property binding info`. Therefore `altTypes` is defined in design time.
// if `altTypes` is present, check if any element is used. This is a very broad check to avoid false diagnostic.
usedRequiredEl = element.elements[0];
}
if (!usedRequiredEl) {
return [
{
Expand Down
Expand Up @@ -101,6 +101,6 @@ export const checkBinding = (
issues.push(...checkDependents(bindingElements, binding));
issues.push(...checkNestedParts(binding));
issues.push(...checkBrackets(binding));
issues.push(...checkRequiredElement(binding, bindingElements));
issues.push(...checkRequiredElement(binding, bindingElements, aggregation));
return issues;
};
10 changes: 10 additions & 0 deletions packages/binding/src/utils/index.ts
@@ -1,3 +1,8 @@
import type {
UI5Aggregation,
UI5Type,
} from "@ui5-language-assistant/semantic-model-types";

export {
typesToValue,
valueTypeMap,
Expand All @@ -14,3 +19,8 @@ export { getCursorContext } from "./cursor";
export { getLogger } from "./logger";

export { getDocumentation } from "./documentation";

export const getAltTypesPrime = (
aggregation?: UI5Aggregation
): UI5Type | undefined =>
aggregation?.altTypes?.find((i) => i.kind === "PrimitiveType");
Expand Up @@ -234,4 +234,10 @@ describe("aggregation binding", () => {
const result = await validateView(snippet);
expect(result.map((item) => issueToSnapshot(item))).toStrictEqual([]);
});
it("tooltip [altTypes] - no diagnostics if any element used", async () => {
const snippet = `
<Text text="My Text" tooltip="{ parts:['']}"/>`;
const result = await validateView(snippet);
expect(result.map((item) => issueToSnapshot(item))).toStrictEqual([]);
});
});
2 changes: 1 addition & 1 deletion test-packages/test-utils/api.d.ts
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.64";
export const DEFAULT_UI5_VERSION = "1.71.67";

// TODO: list should be updated continuously!
export type TestModelVersion =
Expand Down
2 changes: 1 addition & 1 deletion test-packages/test-utils/src/api.ts
Expand Up @@ -31,4 +31,4 @@ export {
} from "./utils/expect";
export { getFallbackPatchVersions } from "./utils/download-ui5-resources";

export const DEFAULT_UI5_VERSION = "1.71.64";
export const DEFAULT_UI5_VERSION = "1.71.67";
4 changes: 2 additions & 2 deletions test-packages/test-utils/src/utils/semantic-model-provider.ts
Expand Up @@ -14,7 +14,7 @@ const MODEL_CACHE: Record<TestModelVersion, UI5SemanticModel> =
Object.create(null);

const fixes: Record<TestModelVersion, TypeNameFix> = {
"1.71.64": {
"1.71.67": {
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.64": {},
"1.71.67": {},
"1.84.41": {},
"1.96.27": {
"sap.ui.mdc": [
Expand Down

0 comments on commit 98c33e7

Please sign in to comment.