Skip to content

Commit

Permalink
fix: add read me file, manual test and fix type (#648)
Browse files Browse the repository at this point in the history
* fix: add read me file, manual test and fix type

* fix: review commit and code coverage

* fix: remove only

* fix: review comment 02
  • Loading branch information
marufrasully authored Aug 11, 2023
1 parent 34c8fe1 commit 069457b
Show file tree
Hide file tree
Showing 11 changed files with 516 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/light-fireants-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch
"vscode-ui5-language-assistant": patch
"@ui5-language-assistant/binding": patch
---

Add read me file, manual test and fix type
7 changes: 7 additions & 0 deletions packages/binding/src/definition/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ const buildType = (
);
}
break;
case "ArrayType":
if (type.type?.kind === "UI5Typedef") {
propertyType.push(...buildType(context, type.type, name, true));
}
break;
}
return propertyType;
};
Expand All @@ -169,10 +174,12 @@ export const getPropertyBindingInfoElements = (
const index = previous.findIndex((i) => i.kind === current.kind);
if (index !== -1) {
// there is duplicate
/* istanbul ignore next */
if (current.possibleValue?.values.length !== 0) {
// has possible value, remove previous - keep current
return [...previous.slice(index), current];
}
/* istanbul ignore next */
if (previous[index].possibleValue?.values.length !== 0) {
// has possible value - keep it
return previous;
Expand Down
3 changes: 3 additions & 0 deletions packages/binding/src/services/hover/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const getHoverFromBinding = (
binding: BindingParserTypes.StructureValue
): Hover | undefined => {
let hover: Hover | undefined;
/* istanbul ignore next */
const cursorPos = context.textDocumentPosition?.position;
for (const element of binding.elements) {
if (
Expand Down Expand Up @@ -84,6 +85,7 @@ export const getHover = (
return;
}
const value = attribute.syntax.value;
/* istanbul ignore next */
const text = attribute.value ?? "";
if (text.trim().length === 0) {
return;
Expand All @@ -101,6 +103,7 @@ export const getHover = (
line: value?.startLine ? value.startLine - 1 : 0, // zero based index
};
const { ast, errors } = parseBinding(expression, position);
/* istanbul ignore next */
const cursorPos = context.textDocumentPosition?.position;
const binding = ast.bindings.find(
(b) =>
Expand Down
5 changes: 5 additions & 0 deletions packages/binding/src/utils/documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ const getType = (type: UI5Type | undefined): string[] => {
result.push(unionType.join(" | "));
}
break;
case "ArrayType":
if (type.type?.kind === "UI5Typedef") {
result.push(...getType(type.type));
}
break;
}
return result;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,258 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`definition getPropertyBindingInfoElements check fallback 1`] = `
Array [
Object {
"documentation": Object {
"kind": "plaintext",
"value": "",
},
"name": "path",
"type": Array [
Object {
"dependents": Array [],
"kind": "string",
"notAllowedElements": Array [
"value",
"parts",
],
},
],
},
Object {
"documentation": Object {
"kind": "plaintext",
"value": "",
},
"name": "value",
"type": Array [
Object {
"dependents": Array [],
"kind": "string",
"notAllowedElements": Array [
"path",
"parts",
],
},
],
},
Object {
"documentation": Object {
"kind": "plaintext",
"value": "",
},
"name": "model",
"type": Array [
Object {
"dependents": Array [],
"kind": "string",
"notAllowedElements": Array [],
},
],
},
Object {
"documentation": Object {
"kind": "plaintext",
"value": "",
},
"name": "suspended",
"type": Array [
Object {
"dependents": Array [],
"kind": "boolean",
"notAllowedElements": Array [],
},
],
},
Object {
"documentation": Object {
"kind": "plaintext",
"value": "",
},
"name": "formatter",
"type": Array [
Object {
"dependents": Array [],
"kind": "string",
"notAllowedElements": Array [],
},
],
},
Object {
"documentation": Object {
"kind": "plaintext",
"value": "",
},
"name": "useRawValues",
"type": Array [
Object {
"dependents": Array [],
"kind": "boolean",
"notAllowedElements": Array [],
},
],
},
Object {
"documentation": Object {
"kind": "plaintext",
"value": "",
},
"name": "useInternalValues",
"type": Array [
Object {
"dependents": Array [],
"kind": "boolean",
"notAllowedElements": Array [],
},
],
},
Object {
"documentation": Object {
"kind": "plaintext",
"value": "",
},
"name": "type",
"type": Array [
Object {
"dependents": Array [],
"kind": "string",
"notAllowedElements": Array [],
},
],
},
Object {
"documentation": Object {
"kind": "plaintext",
"value": "",
},
"name": "targetType",
"type": Array [
Object {
"dependents": Array [],
"kind": "string",
"notAllowedElements": Array [],
},
],
},
Object {
"documentation": Object {
"kind": "plaintext",
"value": "",
},
"name": "formatOptions",
"type": Array [
Object {
"dependents": Array [
Object {
"name": "type",
"type": Array [
Object {
"dependents": Array [],
"kind": "string",
"notAllowedElements": Array [],
},
],
},
],
"kind": "object",
"notAllowedElements": Array [],
},
],
},
Object {
"documentation": Object {
"kind": "plaintext",
"value": "",
},
"name": "constraints",
"type": Array [
Object {
"dependents": Array [
Object {
"name": "type",
"type": Array [
Object {
"dependents": Array [],
"kind": "string",
"notAllowedElements": Array [],
},
],
},
],
"kind": "object",
"notAllowedElements": Array [],
},
],
},
Object {
"documentation": Object {
"kind": "plaintext",
"value": "",
},
"name": "mode",
"type": Array [
Object {
"dependents": Array [],
"kind": "string",
"notAllowedElements": Array [],
},
],
},
Object {
"documentation": Object {
"kind": "plaintext",
"value": "",
},
"name": "parameters",
"type": Array [
Object {
"dependents": Array [],
"kind": "object",
"notAllowedElements": Array [],
},
],
},
Object {
"documentation": Object {
"kind": "plaintext",
"value": "",
},
"name": "events",
"type": Array [
Object {
"dependents": Array [],
"kind": "object",
"notAllowedElements": Array [],
},
],
},
Object {
"documentation": Object {
"kind": "plaintext",
"value": "",
},
"name": "parts",
"type": Array [
Object {
"collection": true,
"dependents": Array [],
"kind": "string",
"notAllowedElements": Array [],
},
Object {
"collection": true,
"dependents": Array [],
"kind": "object",
"notAllowedElements": Array [
"path",
"value",
],
},
],
},
]
`;

exports[`definition getPropertyBindingInfoElements get binding elements 1`] = `
Array [
Object {
Expand Down
15 changes: 15 additions & 0 deletions packages/binding/test/unit/definition/definition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { getContext } from "@ui5-language-assistant/context";
import { BindContext } from "../../../src/types";
import { getPropertyBindingInfoElements } from "../../../src/definition/definition";
import { UI5Typedef } from "@ui5-language-assistant/semantic-model-types";

describe("definition", () => {
let framework: TestFramework;
Expand Down Expand Up @@ -39,5 +40,19 @@ describe("definition", () => {
const result = getPropertyBindingInfoElements(context);
expect(result).toMatchSnapshot();
});
it("check fallback", () => {
const result = getPropertyBindingInfoElements({
...context,
ui5Model: {
...context.ui5Model,
typedefs: {
...context.ui5Model.typedefs,
"sap.ui.base.ManagedObject.PropertyBindingInfo":
undefined as unknown as UI5Typedef,
},
},
});
expect(result).toMatchSnapshot();
});
});
});
Loading

0 comments on commit 069457b

Please sign in to comment.