Skip to content

Commit

Permalink
Merge pull request #127 from mghdotdev/feature/improved-document-linking
Browse files Browse the repository at this point in the history
Feature/improved document linking
  • Loading branch information
mghdotdev authored Oct 14, 2024
2 parents 62e59d1 + 7f65206 commit c70114b
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 6 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Miva IDE CHANGELOG

## v1.25.0 (latest)
## v1.26.0 (latest)

* Added document linking support for the following items:
* `templatefeed`
* `hdft:header`
* `hdft:footer`
* Fixed issue where template files with a dash character in the name was not linking templates correctly.

## v1.25.0

* Added document linking for `<mvt:fragment />` tags.

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-miva-ide",
"displayName": "Miva IDE",
"description": "Syntax highlighting, snippets and tools for building websites with Miva.",
"version": "1.25.0",
"version": "1.26.0",
"engines": {
"vscode": "^1.77.0",
"node": ">=16"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,13 @@ export class MivaMangedTemplatesProvider {
}

const fileName = Utils.basename(URI.parse(document.uri))?.replace('.mvt', '');
const reservedFirstParts = [
'cssui',
'email'
];
const foundDashIndex = fileName.indexOf('-');
const fileNameFirstPart = fileName.slice(0, foundDashIndex === -1 ? undefined : foundDashIndex);
const fileNameRoot = fileNameFirstPart === fileName
const fileNameRoot = (fileNameFirstPart === fileName || !reservedFirstParts.every(firstPart => fileNameFirstPart === firstPart))
? fileName
: fileNameFirstPart;

Expand All @@ -66,6 +70,37 @@ export class MivaMangedTemplatesProvider {
const paramNameLower = parsedItem?.param?.toLowerCase();

switch (nameLower) {
case 'templatefeed': {
if (parsedItem.range) {
const fileNameLower = fileName?.toLowerCase();
const relativePaths = [
{
tooltip: 'Follow link to iterator template',
path: `./templates/TEMPLATEFEED_iterator-${fileNameLower}-templatefeed.mvt`
},
{
tooltip: 'Follow link to footer template',
path: `./templates/TEMPLATEFEED_footer-${fileNameLower}-templatefeed.mvt`
},
{
tooltip: 'Follow link to settings template',
path: `./templates/TEMPLATEFEED_settings-${fileNameLower}-templatefeed.mvt`
}
];

for (let relativePath of relativePaths) {
const target = this.getTargetFromRelativePath(relativePath.path, mmtPath);

links.push({
tooltip: relativePath.tooltip,
range: parsedItem.range,
target
});
}
}

break;
}
case 'product_display_imagemachine': {
const param = paramNameLower?.replace('_deferred', '');

Expand All @@ -81,7 +116,7 @@ export class MivaMangedTemplatesProvider {

break;
}
// <mvt:item name="hdft" param="global_header" /> | <mvt:item name="hdft" param="global_footer" />
// <mvt:item name="hdft" param="global_header" /> | <mvt:item name="hdft" param="global_footer" /> | <mvt:item name="hdft" param="header" /> | <mvt:item name="hdft" param="footer" />
case 'hdft': {
switch (paramNameLower) {
case 'global_header':
Expand All @@ -93,6 +128,20 @@ export class MivaMangedTemplatesProvider {
range: Range.create(document.positionAt(parsedItem.expression.start), document.positionAt(parsedItem.expression.end)),
target
});

break;
}
case 'header':
case 'footer': {
const relativePath = `./templates/${fileNameRoot}-${paramNameLower}.mvt`;
const target = this.getTargetFromRelativePath(relativePath, mmtPath);

links.push({
range: Range.create(document.positionAt(parsedItem.expression.start), document.positionAt(parsedItem.expression.end)),
target
});

break;
}
default:
break;
Expand Down

0 comments on commit c70114b

Please sign in to comment.