MCPcopy Index your code
hub / github.com/massCodeIO/massCode / parseSnippetsLabFiles

Function parseSnippetsLabFiles

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

Source from the content-addressed store, hash-verified

159}
160
161export function parseSnippetsLabFiles(
162 files: ImportFile[],
163): SnippetImportParseResult {
164 const snippets: SnippetImportCandidate[] = []
165 const warnings: SnippetImportParseResult['warnings'] = []
166
167 for (const file of files) {
168 const parsed = parseJsonFile(file)
169 const contents = getContents(parsed)
170
171 if (!contents) {
172 warnings.push({
173 code: 'snippetslab.invalidExport',
174 source: file.name,
175 })
176 continue
177 }
178
179 const folderPathMap = buildFolderPathMap(
180 getRecordArray(contents, 'folders'),
181 )
182 const tagMap = buildTagMap(getRecordArray(contents, 'tags'))
183 const smartGroups = getRecordArray(contents, 'smartGroups')
184
185 if (smartGroups.length) {
186 warnings.push({
187 code: 'snippetslab.smartGroupsSkipped',
188 source: file.name,
189 })
190 }
191
192 getRecordArray(contents, 'snippets').forEach((record, index) => {
193 const sourceId
194 = readString(record, 'uuid') ?? `${file.name}:${index + 1}`
195 const fragments = getRecordArray(record, 'fragments')
196 const contents = fragments
197 .map((fragment, fragmentIndex) => {
198 const value = readString(fragment, 'content')
199 if (!value) {
200 return null
201 }
202
203 const attachments = fragment.attachments
204 if (Array.isArray(attachments) && attachments.length) {
205 warnings.push({
206 code: 'snippetslab.attachmentsSkipped',
207 source: `${file.name}/${sourceId}`,
208 })
209 }
210
211 return {
212 label: normalizeImportEntryName(
213 readString(fragment, 'title'),
214 `Fragment ${fragmentIndex + 1}`,
215 ),
216 language: normalizeLexer(fragment.language),
217 value,
218 }

Callers 3

detectSnippetSourceFunction · 0.90
parsers.test.tsFile · 0.90

Calls 11

normalizeImportEntryNameFunction · 0.90
getContentsFunction · 0.85
getRecordArrayFunction · 0.85
buildTagMapFunction · 0.85
normalizeLexerFunction · 0.85
parseJsonFileFunction · 0.70
buildFolderPathMapFunction · 0.70
readStringFunction · 0.70
getDescriptionFunction · 0.70
getTagsFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected