#766 - Fix snippet placeholder retrieval

This commit is contained in:
Elio Struyf
2024-02-28 21:11:24 +01:00
parent 2e35da3d91
commit 07fbf8bdb9
2 changed files with 20 additions and 6 deletions

View File

@@ -42,6 +42,10 @@ const SnippetForm: React.ForwardRefRenderFunction<SnippetFormHandle, ISnippetFor
const insertPlaceholderValues = useCallback(
async (value: SnippetSpecialPlaceholders) => {
if (!value) {
return '';
}
if (value === 'FM_SELECTED_TEXT') {
return selection || '';
}
@@ -141,13 +145,23 @@ ${snippetBody}
const snippetFields = snippet.fields || [];
// Loop over all fields to check if they are present in the snippet
for (const field of snippetFields) {
console.log('placeholders', placeholders);
console.log('snippetFields', snippetFields);
for await (const field of snippetFields) {
console.log('field', field);
const idx = placeholders.findIndex((fieldName) => fieldName === field.name);
if (idx > -1) {
allFields.push({
...field,
value: await insertPlaceholderValues(field.default || '')
});
try {
const value = await insertPlaceholderValues(field.default || '');
console.log('value', value);
allFields.push({
...field,
value
});
} catch (e) {
console.log('Error', (e as Error).message)
}
}
}

View File

@@ -140,7 +140,7 @@ export class SnippetListener extends BaseListener {
data: { value: string; filePath: string },
requestId?: string
) {
if (!data.value || !command || !requestId) {
if (!command || !requestId) {
return;
}