MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / createLanguageConfig

Function createLanguageConfig

packages/code-map/src/languages.ts:256–291  ·  view source on GitHub ↗
(
  filePath: string,
  runtimeLoader: RuntimeLanguageLoader,
)

Source from the content-addressed store, hash-verified

254/* 10. Language configuration loader */
255/* ------------------------------------------------------------------ */
256export async function createLanguageConfig(
257 filePath: string,
258 runtimeLoader: RuntimeLanguageLoader,
259): Promise<LanguageConfig | undefined> {
260 const cfg = findLanguageConfigByExtension(filePath)
261 if (!cfg) {
262 return undefined
263 }
264
265 if (!cfg.parser) {
266 try {
267 await runtimeLoader.initParser()
268
269 // Load the language using the runtime-specific loader
270 const lang = await runtimeLoader.loadLanguage(cfg.wasmFile)
271
272 // Create parser and query
273 const parser = new Parser()
274 parser.setLanguage(lang)
275
276 // When loaded with bun, the queryText is a path to the file, not the content of the file.
277 const queryContent = path.isAbsolute(cfg.queryPathOrContent)
278 ? fs.readFileSync(cfg.queryPathOrContent, 'utf8')
279 : cfg.queryPathOrContent
280
281 cfg.language = lang
282 cfg.parser = parser
283 cfg.query = new Query(lang, queryContent)
284 } catch (err) {
285 // Let the runtime-specific implementation handle error logging
286 throw err
287 }
288 }
289
290 return cfg
291}
292
293/* ------------------------------------------------------------------ */
294/* 11. Public API */

Callers 2

languages.test.tsFile · 0.90
getLanguageConfigFunction · 0.85

Calls 3

initParserMethod · 0.65
loadLanguageMethod · 0.65

Tested by

no test coverage detected