MCPcopy Create free account
hub / github.com/cursorless-dev/cursorless / transformSnippetVariables

Function transformSnippetVariables

src/actions/WrapWithSnippet.ts:128–146  ·  view source on GitHub ↗

* Replaces the snippet variable with name `placeholderName` with TM_SELECTED_TEXT * * Also replaces any unknown variables with placeholders. We do this so it's * easier to leave one of the placeholders blank. We may make it so that you * can disable this with a setting in the future * @param pa

(
  parsedSnippet: TextmateSnippet,
  placeholderName: string
)

Source from the content-addressed store, hash-verified

126 * @param placeholderName The variable name to replace with TM_SELECTED_TEXT
127 */
128function transformSnippetVariables(
129 parsedSnippet: TextmateSnippet,
130 placeholderName: string
131) {
132 var placeholderIndex = getMaxPlaceholderIndex(parsedSnippet) + 1;
133
134 parsedSnippet.walk((candidate) => {
135 if (candidate instanceof Variable) {
136 if (candidate.name === placeholderName) {
137 candidate.name = "TM_SELECTED_TEXT";
138 } else if (!KnownSnippetVariableNames[candidate.name]) {
139 const placeholder = new Placeholder(placeholderIndex++);
140 candidate.children.forEach((child) => placeholder.appendChild(child));
141 candidate.parent.replace(candidate, [placeholder]);
142 }
143 }
144 return true;
145 });
146}
147
148function getMaxPlaceholderIndex(parsedSnippet: TextmateSnippet) {
149 var placeholderIndex = 0;

Callers 1

runMethod · 0.85

Calls 2

getMaxPlaceholderIndexFunction · 0.85
walkMethod · 0.65

Tested by

no test coverage detected