MCPcopy Create free account
hub / github.com/massCodeIO/massCode / parseVSCodeSnippetFiles

Function parseVSCodeSnippetFiles

src/main/import/snippets/vscode.ts:108–161  ·  view source on GitHub ↗
(
  files: ImportFile[],
)

Source from the content-addressed store, hash-verified

106}
107
108export 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}

Callers 3

detectSnippetSourceFunction · 0.90
parsers.test.tsFile · 0.90

Calls 5

normalizeImportEntryNameFunction · 0.90
getSnippetBodyFunction · 0.85
inferLanguageFunction · 0.85
getPrefixTagsFunction · 0.85
parseJsonFileFunction · 0.70

Tested by

no test coverage detected