MCPcopy Create free account
hub / github.com/JordanCoin/codemap / detectLanguagesFromFiles

Function detectLanguagesFromFiles

cmd/context.go:255–319  ·  view source on GitHub ↗

detectLanguagesFromFiles does a quick scan for language signals. Checks manifest files first (fast), then scans source files recursively.

(root string)

Source from the content-addressed store, hash-verified

253// detectLanguagesFromFiles does a quick scan for language signals.
254// Checks manifest files first (fast), then scans source files recursively.
255func detectLanguagesFromFiles(root string) map[string]bool {
256 langs := make(map[string]bool)
257 addLang := func(lang string) {
258 if lang != "" {
259 langs[lang] = true
260 }
261 }
262
263 // Manifest files → definitive language signal
264 manifests := map[string][]string{
265 "go.mod": {"go"},
266 "package.json": {"javascript"},
267 "Cargo.toml": {"rust"},
268 "pyproject.toml": {"python"},
269 "setup.py": {"python"},
270 "requirements.txt": {"python"},
271 "Gemfile": {"ruby"},
272 "build.gradle": {"java"},
273 "build.gradle.kts": {"kotlin", "java"},
274 "pom.xml": {"java"},
275 "Package.swift": {"swift"},
276 "Podfile": {"swift"},
277 "mix.exs": {"elixir"},
278 "composer.json": {"php"},
279 "build.sbt": {"scala"},
280 "tsconfig.json": {"typescript"},
281 }
282 for file, signalLangs := range manifests {
283 if _, err := os.Stat(filepath.Join(root, file)); err == nil {
284 for _, lang := range signalLangs {
285 addLang(lang)
286 }
287 }
288 }
289
290 // C# project files can have arbitrary names; detect by glob at repo root.
291 for _, pattern := range []string{"*.csproj", "*.sln"} {
292 matches, _ := filepath.Glob(filepath.Join(root, pattern))
293 if len(matches) > 0 {
294 addLang("csharp")
295 }
296 }
297
298 // JS/TS monorepo signal: packages/*/package.json.
299 if matches, _ := filepath.Glob(filepath.Join(root, "packages", "*", "package.json")); len(matches) > 0 {
300 addLang("javascript")
301 }
302
303 // Makefile heuristics for C/C++ projects — check directly, no sentinel.
304 if _, err := os.Stat(filepath.Join(root, "Makefile")); err == nil {
305 applyMakefileHeuristics(filepath.Join(root, "Makefile"), addLang)
306 }
307
308 // Include subdirectory source files. Reuse the scan result for countSourceFiles too.
309 gitCache := scanner.NewGitIgnoreCache(root)
310 if files, err := scanner.ScanFiles(root, gitCache, nil, nil); err == nil {
311 for _, f := range files {
312 addLang(scanner.DetectLanguage(f.Path))

Calls 4

NewGitIgnoreCacheFunction · 0.92
ScanFilesFunction · 0.92
DetectLanguageFunction · 0.92
applyMakefileHeuristicsFunction · 0.85