Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/document-link-block-tag.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@shopify/theme-language-server-common': patch
---

Add a document link for the `{% block 'name' %}` tag so cmd+click on the block
name navigates to `blocks/<name>.liquid`.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ describe('DocumentLinksProvider', () => {
{% assign x = 'assign.css' | asset_url %}
{{ 'asset.js' | asset_url }}
{% content_for 'block', type: 'block_name' %}
{% block 'container' %}{% endblock %}
{% block '_private' %}{% endblock %}
{% block 'with_args', block.settings.alignment: 'center' %}{% endblock %}
`;

documentManager.open(uriString, liquidHtmlContent, 1);
Expand All @@ -56,11 +59,24 @@ describe('DocumentLinksProvider', () => {
'file:///path/to/project/assets/assign.css',
'file:///path/to/project/assets/asset.js',
'file:///path/to/project/blocks/block_name.liquid',
'file:///path/to/project/blocks/container.liquid',
'file:///path/to/project/blocks/_private.liquid',
'file:///path/to/project/blocks/with_args.liquid',
];

expect(result.length).toBe(expectedUrls.length);
for (let i = 0; i < expectedUrls.length; i++) {
expect(result[i].target).toBe(expectedUrls[i]);
}
});

it('should not create a link for the {% partial %} tag', async () => {
uriString = 'file:///path/to/liquid-html-document.liquid';
rootUri = 'file:///path/to/project';

documentManager.open(uriString, `{% partial 'x' %}{% endpartial %}`, 1);

const result = await documentLinksProvider.documentLinks(uriString);
expect(result).toEqual([]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ function documentLinksVisitor(
);
}

// {% block 'name' %}
if (node.name === NamedTags.block && typeof node.markup !== 'string') {
const blockName = node.markup.name;
return DocumentLink.create(
range(textDocument, blockName),
Utils.resolvePath(root, 'blocks', blockName.value + '.liquid').toString(),
);
}

// {% content_for 'block', type: 'block_name' %}
if (node.name === NamedTags.content_for && typeof node.markup !== 'string') {
const typeArg = node.markup.args.find((arg) => arg.name === 'type');
Expand Down
Loading