Skip to content

Commit e6c70a4

Browse files
Update format
1 parent f315e6b commit e6c70a4

File tree

3 files changed

+170
-150
lines changed

3 files changed

+170
-150
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"link": {
3+
"definitions": [
4+
{
5+
"scope": {
6+
"langIds": [
7+
"markdown"
8+
]
9+
},
10+
"body": [
11+
"[$text](${url:$CLIPBOARD})"
12+
]
13+
},
14+
{
15+
"scope": {
16+
"langIds": [
17+
"typescript",
18+
"javascript",
19+
"typescriptreact",
20+
"javascriptreact"
21+
]
22+
},
23+
"body": [
24+
"{@link $text}"
25+
]
26+
}
27+
],
28+
"description": "Link"
29+
}
30+
}

packages/cursorless-vscode/src/migrateSnippets.ts

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ export async function migrateSnippets(
3737

3838
const spokenFormsInverted: SpokenForms = {
3939
insertion: swapKeyValue(spokenForms.insertion),
40-
insertionWithPhrase: swapKeyValue(
41-
spokenForms.insertionWithPhrase,
42-
(name) => name.split(".")[0],
43-
),
40+
insertionWithPhrase: swapKeyValue(spokenForms.insertionWithPhrase),
4441
wrapper: swapKeyValue(spokenForms.wrapper),
4542
};
4643

@@ -100,9 +97,17 @@ export function migrateLegacySnippet(
10097

10198
for (const snippetName of snippetNames) {
10299
const snippet = legacySnippetFile[snippetName];
103-
const phrase =
104-
spokenForms.insertion[snippetName] ??
105-
spokenForms.insertionWithPhrase[snippetName];
100+
let phrase = spokenForms.insertion[snippetName];
101+
102+
if (!phrase) {
103+
const key = Object.keys(spokenForms.insertionWithPhrase).find((key) =>
104+
key.startsWith(`${snippetName}.`),
105+
);
106+
if (key) {
107+
phrase = spokenForms.insertionWithPhrase[key];
108+
}
109+
}
110+
106111
const phrases = phrase ? [phrase] : undefined;
107112

108113
if (useHeader) {
@@ -116,6 +121,7 @@ export function migrateLegacySnippet(
116121
snippet.variables,
117122
undefined,
118123
true,
124+
false,
119125
),
120126
insertionScopes: snippet.insertionScopeTypes,
121127
};
@@ -141,6 +147,7 @@ export function migrateLegacySnippet(
141147
useHeader ? undefined : snippet.variables,
142148
def.variables,
143149
!useHeader,
150+
true,
144151
),
145152
// SKIP: def.scope?.scopeTypes
146153
// SKIP: def.scope?.excludeDescendantScopeTypes
@@ -158,6 +165,7 @@ function parseVariables(
158165
snippetVariables: Record<string, SnippetVariableLegacy> | undefined,
159166
defVariables: Record<string, SnippetVariableLegacy> | undefined,
160167
addMissingPhrases: boolean,
168+
addMissingInsertionFormatters: boolean,
161169
): SnippetVariable[] {
162170
const map: Record<string, SnippetVariable> = {};
163171

@@ -197,6 +205,20 @@ function parseVariables(
197205
}
198206
}
199207

208+
if (addMissingInsertionFormatters) {
209+
for (const key in spokenForms.insertionWithPhrase) {
210+
const [snipName, variableName] = key.split(".");
211+
if (snipName === snippetName) {
212+
if (!map[variableName]) {
213+
map[variableName] = { name: variableName };
214+
}
215+
if (!map[variableName].insertionFormatters) {
216+
map[variableName].insertionFormatters = ["NOOP"];
217+
}
218+
}
219+
}
220+
}
221+
200222
return Object.values(map);
201223
}
202224

@@ -313,11 +335,8 @@ async function writeCommunityFile(
313335
}
314336
}
315337

316-
function swapKeyValue(
317-
obj: Record<string, string>,
318-
map?: (value: string) => string,
319-
): Record<string, string> {
338+
function swapKeyValue(obj: Record<string, string>): Record<string, string> {
320339
return Object.fromEntries(
321-
Object.entries(obj).map(([key, value]) => [map?.(value) ?? value, key]),
340+
Object.entries(obj).map(([key, value]) => [value, key]),
322341
);
323342
}

0 commit comments

Comments
 (0)