Skip to content

Commit

Permalink
fix: change set and fallback for hover
Browse files Browse the repository at this point in the history
  • Loading branch information
marufrasully committed Sep 19, 2023
1 parent 74d11d1 commit e9076dd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
8 changes: 8 additions & 0 deletions .changeset/quiet-stingrays-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"vscode-ui5-language-assistant": patch
"@ui5-language-assistant/binding-parser": patch
"@ui5-language-assistant/binding": patch
"@ui5-language-assistant/vscode-ui5-language-assistant-bas-ext": patch
---

fix: check binding expression only if it has at least one known property
5 changes: 3 additions & 2 deletions packages/binding/src/definition/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ const buildType = (
};

export const getPropertyBindingInfoElements = (
context: BindContext
context: BindContext,
forHover = false
): PropertyBindingInfoElement[] => {
const elements: PropertyBindingInfoElement[] = [];
const propBinding = context.ui5Model.typedefs[PROPERTY_BINDING_INFO];
Expand Down Expand Up @@ -192,7 +193,7 @@ export const getPropertyBindingInfoElements = (
elements.push({
name: name,
type: builtType,
documentation: getDocumentation(context, property),
documentation: getDocumentation(context, property, forHover),
});
}
return elements;
Expand Down
19 changes: 7 additions & 12 deletions packages/binding/src/services/hover/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ import {
BindingParserTypes,
} from "@ui5-language-assistant/binding-parser";
import { Position } from "vscode-languageserver-types";
import { BindContext } from "../../types";
import { PROPERTY_BINDING_INFO } from "../../constant";
import { getDocumentation } from "../../utils";
import { UI5Typedef } from "@ui5-language-assistant/semantic-model-types";
import { BindContext, PropertyBindingInfoElement } from "../../types";
import { getPropertyBindingInfoElements } from "../../definition/definition";

const getHoverFromBinding = (
context: BindContext,
propertyBinding: UI5Typedef,
propertyBinding: PropertyBindingInfoElement[],
binding: BindingParserTypes.StructureValue
): Hover | undefined => {
let hover: Hover | undefined;
Expand All @@ -43,11 +41,11 @@ const getHoverFromBinding = (
})
) {
// check valid key
const property = propertyBinding.properties.find(
const property = propertyBinding.find(
(prop) => prop.name === element.key?.originalText
);
if (property) {
return { contents: getDocumentation(context, property, true) };
return { contents: property.documentation };
}
}

Expand All @@ -73,10 +71,6 @@ export const getHover = (
attribute: XMLAttribute
): Hover | undefined => {
try {
const propBinding = context.ui5Model.typedefs[PROPERTY_BINDING_INFO];
if (!propBinding) {
return;
}
const ui5Property = getUI5PropertyByXMLAttributeKey(
attribute,
context.ui5Model
Expand All @@ -90,7 +84,8 @@ export const getHover = (
if (text.trim().length === 0) {
return;
}
const properties = propBinding.properties.map((i) => i.name);
const propBinding = getPropertyBindingInfoElements(context, true);
const properties = propBinding.map((i) => i.name);
const extractedText = extractBindingSyntax(text);
for (const bindingSyntax of extractedText) {
const { expression, startIndex } = bindingSyntax;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ const walkAttributes = (
attributes: XMLAttribute[]
): SemanticToken[] => {
const semanticTokens: SemanticToken[] = [];
// todo - use `getPropertyBindingInfoElements` method or similar one, once fallback for aggregation binding is added
const bindingInfo =
context.ui5Model.typedefs[PROPERTY_BINDING_INFO] ??
context.ui5Model.typedefs[AGGREGATION_BINDING_INFO];
Expand Down

0 comments on commit e9076dd

Please sign in to comment.