MCPcopy Create free account
hub / github.com/diillson/chatcli / detectLanguages

Function detectLanguages

operator/controllers/source_controller.go:361–418  ·  view source on GitHub ↗

detectLanguages identifies programming languages used in the repository.

(localPath string)

Source from the content-addressed store, hash-verified

359
360// detectLanguages identifies programming languages used in the repository.
361func detectLanguages(localPath string) []string {
362 extensions := map[string]string{
363 ".go": "Go",
364 ".java": "Java",
365 ".py": "Python",
366 ".js": "JavaScript",
367 ".ts": "TypeScript",
368 ".rs": "Rust",
369 ".rb": "Ruby",
370 ".php": "PHP",
371 ".cs": "C#",
372 ".cpp": "C++",
373 ".c": "C",
374 ".swift": "Swift",
375 ".kt": "Kotlin",
376 ".scala": "Scala",
377 }
378
379 langCount := make(map[string]int)
380 // Walk errors mean a partially indexed tree — acceptable for language
381 // detection, which is advisory.
382 _ = filepath.Walk(localPath, func(path string, info os.FileInfo, err error) error {
383 if err != nil || info.IsDir() {
384 // Skip hidden directories and vendor/node_modules
385 if info != nil && info.IsDir() {
386 base := filepath.Base(path)
387 if strings.HasPrefix(base, ".") || base == "vendor" || base == "node_modules" {
388 return filepath.SkipDir
389 }
390 }
391 return nil
392 }
393 ext := filepath.Ext(path)
394 if lang, ok := extensions[ext]; ok {
395 langCount[lang]++
396 }
397 return nil
398 })
399
400 type langEntry struct {
401 name string
402 count int
403 }
404 sorted := make([]langEntry, 0, len(langCount))
405 for name, count := range langCount {
406 sorted = append(sorted, langEntry{name, count})
407 }
408 sort.Slice(sorted, func(i, j int) bool { return sorted[i].count > sorted[j].count })
409
410 result := make([]string, 0, 5)
411 for i, e := range sorted {
412 if i >= 5 {
413 break
414 }
415 result = append(result, e.name)
416 }
417 return result
418}

Callers 2

TestDetectLanguagesFunction · 0.85
indexRepoMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestDetectLanguagesFunction · 0.68