feat(languages): register tier-1 languages and chroma routing

This commit is contained in:
2026-07-02 09:20:06 -05:00
parent 22e2c2d169
commit 2f37640302
3 changed files with 66 additions and 2 deletions
+7 -2
View File
@@ -27,9 +27,14 @@ type LineChange struct {
func resolveLexer(filename string) chroma.Lexer { func resolveLexer(filename string) chroma.Lexer {
ext := strings.TrimPrefix(strings.ToLower(filepath.Ext(filename)), ".") ext := strings.TrimPrefix(strings.ToLower(filepath.Ext(filename)), ".")
var l chroma.Lexer var l chroma.Lexer
if ext == "less" || ext == "sass" { switch ext {
case "less", "sass":
l = lexers.Get("SCSS") l = lexers.Get("SCSS")
} else { case "tfvars":
l = lexers.Get("Terraform")
case "cljs", "cljc":
l = lexers.Get("Clojure")
default:
l = lexers.Match("f." + ext) l = lexers.Match("f." + ext)
} }
if l == nil { if l == nil {
+18
View File
@@ -21,6 +21,24 @@ func TestResolveLexer(t *testing.T) {
{"a.less", "SCSS"}, {"a.less", "SCSS"},
{"a.sass", "SCSS"}, {"a.sass", "SCSS"},
{"a.conf", ""}, {"a.conf", ""},
{"a.tf", "Terraform"},
{"a.hcl", "HCL"},
{"a.tfvars", "Terraform"},
{"a.sol", "Solidity"},
{"a.zig", "Zig"},
{"a.ex", "Elixir"},
{"a.exs", "Elixir"},
{"a.nix", "Nix"},
{"a.proto", "Protocol Buffer"},
{"a.graphql", "GraphQL"},
{"a.graphqls", "GraphQL"},
{"a.ml", "OCaml"},
{"a.mli", "OCaml"},
{"a.hs", "Haskell"},
{"a.clj", "Clojure"},
{"a.edn", "Clojure"},
{"a.cljs", "Clojure"},
{"a.cljc", "Clojure"},
} }
for _, c := range cases { for _, c := range cases {
l := resolveLexer(c.file) l := resolveLexer(c.file)
+41
View File
@@ -63,6 +63,28 @@ var languageMap = map[string]types.Language{
"dockerfile": {LineComment: "#"}, "dockerfile": {LineComment: "#"},
"makefile": {LineComment: "#"}, "makefile": {LineComment: "#"},
"tf": {LineComment: "#", AlternateLineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"hcl": {LineComment: "#", AlternateLineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"tfvars": {LineComment: "#", AlternateLineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"sol": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"zig": {LineComment: "//"},
"ex": {LineComment: "#"},
"exs": {LineComment: "#"},
"nix": {LineComment: "#", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"proto": {LineComment: "//", BlockComment: &types.BlockComment{Start: "/*", End: "*/"}},
"graphql": {LineComment: "#"},
"graphqls": {LineComment: "#"},
"ml": {BlockComment: &types.BlockComment{Start: "(*", End: "*)"}},
"mli": {BlockComment: &types.BlockComment{Start: "(*", End: "*)"}},
"hs": {LineComment: "--", BlockComment: &types.BlockComment{Start: "{-", End: "-}"}},
"clj": {LineComment: ";"},
"cljs": {LineComment: ";"},
"cljc": {LineComment: ";"},
"edn": {LineComment: ";"},
} }
func DetectLanguage(filename string) (types.Language, error) { func DetectLanguage(filename string) (types.Language, error) {
@@ -138,6 +160,25 @@ func GetLanguageName(filename string) string {
"dockerfile": "Dockerfile", "dockerfile": "Dockerfile",
"makefile": "Makefile", "makefile": "Makefile",
"tf": "Terraform",
"hcl": "HCL",
"tfvars": "Terraform",
"sol": "Solidity",
"zig": "Zig",
"ex": "Elixir",
"exs": "Elixir",
"nix": "Nix",
"proto": "Protocol Buffer",
"graphql": "GraphQL",
"graphqls": "GraphQL",
"ml": "OCaml",
"mli": "OCaml",
"hs": "Haskell",
"clj": "Clojure",
"cljs": "ClojureScript",
"cljc": "Clojure",
"edn": "EDN",
} }
if name, ok := names[ext]; ok { if name, ok := names[ext]; ok {