Skip to content

Commit 81a3bef

Browse files
committed
Improve liquid doc indentation and hover formatting
---- - Render Description as markdown instead of plaintext - Fix indentation for multi-line examples and descriptions
1 parent 5005c31 commit 81a3bef

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

packages/theme-check-common/src/liquid-doc/liquidDoc.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ describe('Unit: getSnippetDefinition', () => {
129129
liquidDoc: {
130130
examples: [
131131
{
132-
content: '{{ product }}\n {{ product.title }}',
132+
content: '{{ product }}\n{{ product.title }}',
133133
nodeType: 'example',
134134
},
135135
],
@@ -276,7 +276,7 @@ describe('Unit: getSnippetDefinition', () => {
276276
name: 'product-card',
277277
liquidDoc: {
278278
description: {
279-
content: 'this is an implicit description\n in a header',
279+
content: 'this is an implicit description\nin a header',
280280
nodeType: 'description',
281281
},
282282
parameters: [

packages/theme-check-common/src/liquid-doc/liquidDoc.ts

+26-2
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@ export function getSnippetDefinition(
6868
},
6969
LiquidDocExampleNode(node: LiquidDocExampleNode) {
7070
return {
71-
content: node.content.value.trim(),
71+
content: fixIndentation(node.content.value.trim()),
7272
nodeType: 'example',
7373
};
7474
},
7575
LiquidDocDescriptionNode(node: LiquidDocDescriptionNode) {
7676
return {
77-
content: node.content.value.trim(),
77+
content: fixIndentation(node.content.value.trim()),
7878
nodeType: 'description',
7979
};
8080
},
@@ -108,3 +108,27 @@ export function getSnippetDefinition(
108108
},
109109
};
110110
}
111+
112+
function fixIndentation(text: string): string {
113+
const lines = text.split('\n');
114+
115+
if (lines.length <= 1) return text;
116+
117+
const nonEmptyLines = lines.slice(1).filter((line) => line.trim().length > 0);
118+
const indentLengths = nonEmptyLines.map((line) => {
119+
const match = line.match(/^\s*/);
120+
return match ? match[0].length : 0;
121+
});
122+
123+
if (indentLengths.length === 0) return text;
124+
125+
const minIndent = Math.min(...indentLengths);
126+
127+
return [
128+
lines[0],
129+
...lines.slice(1).map((line) => {
130+
if (line.trim().length === 0) return line; // Skip empty lines
131+
return line.slice(minIndent);
132+
}),
133+
].join('\n');
134+
}

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

-2
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ describe('Module: RenderSnippetHoverProvider', async () => {
7575
**Description:**
7676
7777
78-
\`\`\`plaintext
7978
This is a description
80-
\`\`\`
8179
8280
**Parameters:**
8381
- \`title\`: string - The title of the product

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class RenderSnippetHoverProvider implements BaseHoverProvider {
5151

5252
if (liquidDoc.description) {
5353
const description = liquidDoc.description.content;
54-
parts.push('', '**Description:**', '\n', `\`\`\`plaintext\n${description}\n\`\`\``);
54+
parts.push('', '**Description:**', '\n', description);
5555
}
5656

5757
if (liquidDoc.parameters?.length) {

0 commit comments

Comments
 (0)