( files: ImportFile[], )
| 106 | } |
| 107 | |
| 108 | export function parseVSCodeSnippetFiles( |
| 109 | files: ImportFile[], |
| 110 | ): SnippetImportParseResult { |
| 111 | const snippets: SnippetImportCandidate[] = [] |
| 112 | const warnings: SnippetImportParseResult['warnings'] = [] |
| 113 | |
| 114 | for (const file of files) { |
| 115 | const parsed = parseJsonFile(file) |
| 116 | if (!parsed) { |
| 117 | warnings.push({ |
| 118 | code: 'vscode.invalidJson', |
| 119 | source: file.name, |
| 120 | }) |
| 121 | continue |
| 122 | } |
| 123 | |
| 124 | Object.entries(parsed).forEach(([key, value]) => { |
| 125 | if (!value || typeof value !== 'object' || Array.isArray(value)) { |
| 126 | warnings.push({ |
| 127 | code: 'vscode.entryNotObject', |
| 128 | source: `${file.name}/${key}`, |
| 129 | }) |
| 130 | return |
| 131 | } |
| 132 | |
| 133 | const snippet = value as VSCodeSnippetValue |
| 134 | const body = getSnippetBody(snippet.body) |
| 135 | if (body === null) { |
| 136 | warnings.push({ |
| 137 | code: 'vscode.invalidBody', |
| 138 | source: `${file.name}/${key}`, |
| 139 | }) |
| 140 | return |
| 141 | } |
| 142 | |
| 143 | snippets.push({ |
| 144 | contents: [ |
| 145 | { |
| 146 | label: 'Fragment 1', |
| 147 | language: inferLanguage(file.name, snippet), |
| 148 | value: body, |
| 149 | }, |
| 150 | ], |
| 151 | description: |
| 152 | typeof snippet.description === 'string' ? snippet.description : null, |
| 153 | name: normalizeImportEntryName(key, 'Untitled snippet'), |
| 154 | sourceId: `${file.name}:${key}`, |
| 155 | tags: getPrefixTags(snippet.prefix), |
| 156 | }) |
| 157 | }) |
| 158 | } |
| 159 | |
| 160 | return { snippets, warnings } |
| 161 | } |
no test coverage detected