Skip to content

Commit 1f7a561

Browse files
committed
Prevent rendering hover for snippet with no liquidDoc definition
1 parent cda2528 commit 1f7a561

File tree

4 files changed

+30
-24
lines changed

4 files changed

+30
-24
lines changed

packages/theme-language-server-common/src/hover/providers/RenderSnippetHoverProvider.spec.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,16 @@ describe('Module: RenderSnippetHoverProvider', async () => {
5454
);
5555
});
5656

57-
it('should return an H3 with snippet name if no LiquidDocDefinition found', async () => {
58-
getSnippetDefinition = async () => ({ name: 'unknown-snippet' });
57+
it('should return null if no LiquidDocDefinition found', async () => {
58+
getSnippetDefinition = async () => ({ name: 'unknown-snippet', liquidDoc: undefined });
5959
provider = createProvider(getSnippetDefinition);
60-
await expect(provider).to.hover(`{% render 'unknown-sni█ppet' %}`, '### unknown-snippet');
60+
await expect(provider).to.hover(`{% render 'unknown-sni█ppet' %}`, null);
61+
});
62+
63+
it('should return null if snippet is null', async () => {
64+
getSnippetDefinition = async () => undefined;
65+
provider = createProvider(getSnippetDefinition);
66+
await expect(provider).to.hover(`{% render 'unknown-sni█ppet' %}`, null);
6167
});
6268

6369
it('should return nothing if not in render tag', async () => {

packages/theme-language-server-common/src/hover/providers/RenderSnippetHoverProvider.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,9 @@ export class RenderSnippetHoverProvider implements BaseHoverProvider {
3232
snippetName,
3333
);
3434

35-
if (!snippetDefinition) {
36-
return null;
37-
}
38-
39-
const liquidDoc = snippetDefinition.liquidDoc;
40-
35+
const liquidDoc = snippetDefinition?.liquidDoc;
4136
if (!liquidDoc) {
42-
return {
43-
contents: {
44-
kind: 'markdown',
45-
value: `### ${snippetDefinition.name}`,
46-
},
47-
};
37+
return null;
4838
}
4939

5040
const parts = [`### ${snippetDefinition.name}`];

packages/theme-language-server-common/src/liquidDoc.spec.ts

+13-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('Unit: makeGetLiquidDocDefinitions', () => {
99
return toSourceCode('/tmp/foo.liquid', code).ast as LiquidHtmlNode;
1010
}
1111

12-
it('should return name if no valid annotations are present in definition', async () => {
12+
it('should return undefined if no renderable content is present', async () => {
1313
const ast = toAST(`
1414
{% doc %}
1515
just a description
@@ -18,12 +18,7 @@ describe('Unit: makeGetLiquidDocDefinitions', () => {
1818
`);
1919

2020
const result = getSnippetDefinition(ast, 'product-card');
21-
expect(result).to.deep.equal({
22-
name: 'product-card',
23-
liquidDoc: {
24-
parameters: [],
25-
},
26-
});
21+
expect(result).to.be.undefined;
2722
});
2823

2924
it('should extract name, description and type from param annotations', async () => {
@@ -65,4 +60,15 @@ describe('Unit: makeGetLiquidDocDefinitions', () => {
6560
},
6661
});
6762
});
63+
64+
it('should return undefined if no renderable content is present', async () => {
65+
const ast = toAST(`
66+
{% doc %}
67+
just a description (update this when we add description to renderable content)
68+
{% enddoc %}
69+
`);
70+
71+
const result = getSnippetDefinition(ast, 'product-card');
72+
expect(result).to.be.undefined;
73+
});
6874
});

packages/theme-language-server-common/src/liquidDoc.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export type LiquidDocParameter = {
2727
export function getSnippetDefinition(
2828
snippet: LiquidHtmlNode,
2929
snippetName: string,
30-
): SnippetDefinition {
30+
): SnippetDefinition | undefined {
3131
const parameters: LiquidDocParameter[] = visit<SourceCodeType.LiquidHtml, LiquidDocParameter>(
3232
snippet,
3333
{
@@ -41,10 +41,14 @@ export function getSnippetDefinition(
4141
},
4242
);
4343

44+
if (parameters.length === 0) {
45+
return undefined;
46+
}
47+
4448
return {
4549
name: snippetName,
4650
liquidDoc: {
47-
parameters: parameters,
51+
parameters,
4852
},
4953
};
5054
}

0 commit comments

Comments
 (0)