Skip to content

Commit df4c189

Browse files
committedMar 6, 2025
Renaming liquid doc params refactors render tag alias param
1 parent 22dd956 commit df4c189

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed
 

‎.changeset/thick-suits-float.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/theme-language-server-common': minor
3+
---
4+
5+
Renaming liquid doc params refactors render tag alias param

‎packages/theme-language-server-common/src/rename/providers/LiquidVariableRenameProvider.spec.ts

+59
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,65 @@ describe('LiquidVariableRenameProvider', () => {
434434
},
435435
});
436436
});
437+
438+
['with', 'for'].forEach((aliasTag) => {
439+
it(`updates render tag's '${aliasTag} as' alias when exists`, async () => {
440+
const renderTagSource = `<div>{% render 'example-snippet' ${aliasTag} 'Bob' as name %}</div>`;
441+
442+
createSectionWithSource(documentManager, 'section1', renderTagSource);
443+
createSectionWithSource(
444+
documentManager,
445+
'section2',
446+
`<div>{% render 'example-snippet' ${aliasTag} 'Bob' as friend %}</div>`,
447+
);
448+
449+
const params = {
450+
textDocument,
451+
position: Position.create(1, 11),
452+
newName: 'first_name',
453+
};
454+
const result = await provider.rename(params);
455+
assert(result);
456+
assert(result.documentChanges);
457+
458+
expect(connection.spies.sendRequest).toHaveBeenCalledOnce();
459+
expect(connection.spies.sendRequest).toHaveBeenCalledWith('workspace/applyEdit', {
460+
label: `Rename snippet parameter 'name' to 'first_name'`,
461+
edit: {
462+
changeAnnotations: {
463+
renameSnippetParameter: {
464+
label: `Rename snippet parameter 'name' to 'first_name'`,
465+
needsConfirmation: false,
466+
},
467+
},
468+
documentChanges: [
469+
{
470+
textDocument: {
471+
uri: getSectionUri('section1'),
472+
version: 1,
473+
},
474+
edits: [
475+
{
476+
newText: 'as first_name',
477+
range: {
478+
end: {
479+
character: renderTagSource.indexOf('as name') + 'as name'.length,
480+
line: 0,
481+
},
482+
start: {
483+
character: renderTagSource.indexOf('as name'),
484+
line: 0,
485+
},
486+
},
487+
},
488+
],
489+
annotationId: 'renameSnippetParameter',
490+
},
491+
],
492+
},
493+
});
494+
});
495+
});
437496
});
438497
});
439498

‎packages/theme-language-server-common/src/rename/providers/LiquidVariableRenameProvider.ts

+17
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,23 @@ async function updateRenderTags(
245245
),
246246
};
247247
}
248+
249+
if (node.alias === oldParamName && node.variable) {
250+
// `as variable` is not captured in our liquid parser yet,
251+
// so we have to check it manually and replace it
252+
const aliasMatch = /as\s+([^\s,]+)/g;
253+
const match = aliasMatch.exec(node.source.slice(node.position.start, node.position.end));
254+
255+
if (!match) return;
256+
257+
return {
258+
newText: `as ${newParamName}`,
259+
range: Range.create(
260+
textDocument.positionAt(node.position.start + match.index),
261+
textDocument.positionAt(node.position.start + match.index + match[0].length),
262+
),
263+
};
264+
}
248265
},
249266
});
250267

0 commit comments

Comments
 (0)
Failed to load comments.