MCPcopy Index your code
hub / github.com/Acode-Foundation/Acode / getLanguageParser

Function getLanguageParser

src/utils/codeHighlight.js:133–151  ·  view source on GitHub ↗

* Gets the language parser for a given URI using the modelist

(uri)

Source from the content-addressed store, hash-verified

131 * Gets the language parser for a given URI using the modelist
132 */
133async function getLanguageParser(uri) {
134 const mode = getModeForPath(uri);
135 if (!mode?.languageExtension) return null;
136
137 try {
138 const langExt = await mode.languageExtension();
139 if (!langExt) return null;
140
141 const langArray = Array.isArray(langExt) ? langExt : [langExt];
142 for (const ext of langArray) {
143 if (ext && typeof ext === "object" && "language" in ext) {
144 return ext.language.parser;
145 }
146 }
147 } catch (e) {
148 console.warn("Failed to get language parser for", uri, e);
149 }
150 return null;
151}
152
153/**
154 * Gets language parser by language name (e.g., "javascript", "python")

Callers 2

getParserForLanguageFunction · 0.85
highlightLineFunction · 0.85

Calls 1

getModeForPathFunction · 0.90

Tested by

no test coverage detected