Skip to content

Commit e3c8a14

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 e3c8a14

File tree

4 files changed

+38
-7
lines changed

4 files changed

+38
-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

+35-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,36 @@ 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+
// Find minimum indentation in one pass, skipping first line and empty lines
118+
let minIndent = Infinity;
119+
120+
for (let i = 1; i < lines.length; i++) {
121+
const line = lines[i];
122+
if (line.trim().length === 0) continue;
123+
124+
const indent = line.match(/^\s*/)[0].length;
125+
if (indent < minIndent) minIndent = indent;
126+
127+
// Early exit if we find a line with no indentation
128+
if (minIndent === 0) break;
129+
}
130+
131+
// If no valid lines found or no indentation to remove
132+
if (minIndent === Infinity || minIndent === 0) return text;
133+
134+
// Process lines directly without creating additional arrays
135+
for (let i = 1; i < lines.length; i++) {
136+
const line = lines[i];
137+
if (line.trim().length > 0) {
138+
lines[i] = line.slice(minIndent);
139+
}
140+
}
141+
142+
return lines.join('\n');
143+
}

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)