Skip to content

Commit 6f1ddbb

Browse files
committed
Render snippet name on hover when file exists without liquidDoc definition
1 parent 02b8967 commit 6f1ddbb

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('Module: RenderSnippetHoverProvider', async () => {
5757
it('should return null if no LiquidDocDefinition found', async () => {
5858
getSnippetDefinition = async () => ({ name: 'unknown-snippet', liquidDoc: undefined });
5959
provider = createProvider(getSnippetDefinition);
60-
await expect(provider).to.hover(`{% render 'unknown-sni█ppet' %}`, null);
60+
await expect(provider).to.hover(`{% render 'unknown-sni█ppet' %}`, `### unknown-snippet`);
6161
});
6262

6363
it('should return null if snippet is null', async () => {

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

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

35-
const liquidDoc = snippetDefinition?.liquidDoc;
36-
if (!liquidDoc) {
35+
if (!snippetDefinition) {
3736
return null;
3837
}
3938

39+
const liquidDoc = snippetDefinition.liquidDoc;
40+
41+
if (!liquidDoc) {
42+
return {
43+
contents: {
44+
kind: 'markdown',
45+
value: `### ${snippetDefinition.name}`,
46+
},
47+
};
48+
}
49+
4050
const parts = [`### ${snippetDefinition.name}`];
4151

4252
if (liquidDoc.parameters?.length) {

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

+7-13
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 undefined if no renderable content is present', async () => {
12+
it('should return default snippet definition if no renderable content is present', async () => {
1313
const ast = toAST(`
1414
{% doc %}
1515
just a description
@@ -18,7 +18,12 @@ describe('Unit: makeGetLiquidDocDefinitions', () => {
1818
`);
1919

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

2429
it('should extract name, description and type from param annotations', async () => {
@@ -60,15 +65,4 @@ describe('Unit: makeGetLiquidDocDefinitions', () => {
6065
},
6166
});
6267
});
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-
});
7468
});

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

+1-5
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 | undefined {
30+
): SnippetDefinition {
3131
const parameters: LiquidDocParameter[] = visit<SourceCodeType.LiquidHtml, LiquidDocParameter>(
3232
snippet,
3333
{
@@ -41,10 +41,6 @@ export function getSnippetDefinition(
4141
},
4242
);
4343

44-
if (parameters.length === 0) {
45-
return undefined;
46-
}
47-
4844
return {
4945
name: snippetName,
5046
liquidDoc: {

0 commit comments

Comments
 (0)