Skip to content

Commit cd8e2c6

Browse files
committed
fix: #92
1 parent 71430de commit cd8e2c6

File tree

4 files changed

+19
-18
lines changed

4 files changed

+19
-18
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to the "magento-toolbox" extension will be documented in thi
44

55
Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.
66

7+
## [Unreleased]
8+
- Fixed: Issue [#92](https://github.com/magebitcom/magento-toolbox/issues/92) (Definitions and hovers dont work on element content values that are on a new line)
9+
710
## [1.6.0] - 2025-04-09
811

912
- Added: Event name autocomplete

src/common/xml/XmlSuggestionProvider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export abstract class XmlSuggestionProvider<T> {
6868
}
6969

7070
const value = attribute?.value || '';
71+
const trimmedValue = value.trim();
7172

7273
const range = attribute
7374
? new Range(
@@ -78,7 +79,7 @@ export abstract class XmlSuggestionProvider<T> {
7879
)
7980
: new Range(0, 0, 0, 0);
8081

81-
return this.getSuggestionItems(value, range, document, element, attribute);
82+
return this.getSuggestionItems(trimmedValue, range, document, element, attribute);
8283
}
8384

8485
public getElementContentSuggestionProviders(
@@ -95,6 +96,7 @@ export abstract class XmlSuggestionProvider<T> {
9596

9697
const textContents = element.textContents.length > 0 ? element.textContents[0] : null;
9798
const elementValue = textContents?.text ?? '';
99+
const trimmedElementValue = elementValue.trim();
98100

99101
const range = textContents
100102
? new Range(
@@ -105,7 +107,7 @@ export abstract class XmlSuggestionProvider<T> {
105107
)
106108
: new Range(0, 0, 0, 0);
107109

108-
return this.getSuggestionItems(elementValue, range, document, element);
110+
return this.getSuggestionItems(trimmedElementValue, range, document, element);
109111
}
110112

111113
protected matchesConditions(

src/definition/XmlClasslikeDefinitionProvider.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ export class XmlClasslikeDefinitionProvider implements DefinitionProvider {
2626
return null;
2727
}
2828

29-
const range = document.getWordRangeAtPosition(position, /("[^"]+")|(>[^<]+<)/);
29+
const range = document.getWordRangeAtPosition(
30+
position,
31+
/((?:\\{1,2}\w+|\w+\\{1,2})(?:\w+\\{0,2})+)/
32+
);
3033

3134
if (!range) {
3235
return null;
@@ -41,7 +44,7 @@ export class XmlClasslikeDefinitionProvider implements DefinitionProvider {
4144
}
4245

4346
// also handle constants
44-
const potentialNamespace = word.replace(/["<>]/g, '').split(':').shift();
47+
const potentialNamespace = word.split(':').shift()?.trim();
4548

4649
if (!potentialNamespace) {
4750
return null;
@@ -57,16 +60,11 @@ export class XmlClasslikeDefinitionProvider implements DefinitionProvider {
5760

5861
const targetPosition = await this.getClasslikeNameRange(document, classUri);
5962

60-
const originSelectionRange = new Range(
61-
range.start.with({ character: range.start.character + 1 }),
62-
range.end.with({ character: range.end.character - 1 })
63-
);
64-
6563
return [
6664
{
6765
targetUri: classUri,
6866
targetRange: targetPosition,
69-
originSelectionRange,
67+
originSelectionRange: range,
7068
} as LocationLink,
7169
];
7270
}

src/hover/XmlClasslikeHoverProvider.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ export default class XmlClasslikeHoverProvider implements HoverProvider {
1414
return null;
1515
}
1616

17-
const range = document.getWordRangeAtPosition(position, /("[^"]+")|(>[^<]+<)/);
17+
const range = document.getWordRangeAtPosition(
18+
position,
19+
/((?:\\{1,2}\w+|\w+\\{1,2})(?:\w+\\{0,2})+)/
20+
);
1821

1922
if (!range) {
2023
return null;
@@ -28,7 +31,7 @@ export default class XmlClasslikeHoverProvider implements HoverProvider {
2831
return null;
2932
}
3033

31-
const potentialNamespace = word.replace(/["<>]/g, '').split(':').shift();
34+
const potentialNamespace = word.split(':').shift()?.trim();
3235

3336
if (!potentialNamespace) {
3437
return null;
@@ -45,11 +48,6 @@ export default class XmlClasslikeHoverProvider implements HoverProvider {
4548
const phpFile = await PhpDocumentParser.parseUri(document, classUri);
4649
const classLikeInfo = new ClasslikeInfo(phpFile);
4750

48-
const rangeWithoutTags = new Range(
49-
range.start.with({ character: range.start.character + 1 }),
50-
range.end.with({ character: range.end.character - 1 })
51-
);
52-
53-
return new Hover(classLikeInfo.getHover(), rangeWithoutTags);
51+
return new Hover(classLikeInfo.getHover(), range);
5452
}
5553
}

0 commit comments

Comments
 (0)