feat: add support for even more languages

scrape zed-industries/extensions
This commit is contained in:
Jozef Steinhübl 2024-07-24 23:55:36 +02:00
parent 7c693dcab4
commit 5277297f19
No known key found for this signature in database
GPG key ID: E6BC90C91973B08F
2 changed files with 188 additions and 68 deletions

View file

@ -1,6 +1,6 @@
id = "discord_presence" id = "discord_presence"
name = "Discord Presence" name = "Discord Presence"
version = "0.1.0" version = "0.2.0"
schema_version = 1 schema_version = 1
authors = ["Jozef Steinhübl <contact@xhyrom.dev>"] authors = ["Jozef Steinhübl <contact@xhyrom.dev>"]
description = "Presence for your beautiful discord account :)" description = "Presence for your beautiful discord account :)"
@ -10,55 +10,141 @@ repository = "https://git.sr.ht/~hyro/zed-discord-presence"
name = "Discord Presence LSP" name = "Discord Presence LSP"
# Generated by scripts/get_languages.sh # Generated by scripts/get_languages.sh
languages = [ languages = [
"Shell Script", "AsciiDoc",
"C", "Assembly",
"C++", "Shell Script",
"CSS", "Beancount",
"Go", "Bend",
"Go Mod", "Blade",
"Go Work", "BQN",
"JavaScript", "Brainfuck",
"JSDoc", "Cadence",
"JSON", "Cairo",
"JSONC", "Cap'n Proto",
"Markdown", "Cedar",
"proto", "CFEngine",
"Python", "CSV",
"Regex", "Gherkin",
"Rust", "CUE",
"TSX", "D",
"TypeScript", "DBML",
"YAML", "Earthfile",
"Astro", "Elisp",
"Clojure", "Handlebars",
"CSharp", "Exograph",
"Dart", "Fish",
"Elixir", "FSharp",
"HEEX", "GDScript",
"Elm", "Godot Resource",
"Erlang", "Gemini",
"Gleam", "Diff",
"GLSL", "Git Attributes",
"Haskell", "Git Commit",
"HTML", "Git Config",
"Lua", "Git Ignore",
"OCaml Interface", "Git Rebase",
"OCaml", "GraphQL",
"PHP", "Groovy",
"PHPDoc", "GROQ",
"Prisma", "ini",
"PureScript", "Jsonnet",
"Racket", "Julia",
"ERB", "Just",
"Ruby", "LaTeX",
"Scheme", "Ledger",
"Svelte", "LESS",
"HCL", "LilyPond",
"Terraform Vars", "LilyPond Scheme",
"Terraform", "Liquid",
"TOML", "Lox",
"Uiua", "Luau",
"Vue.js", "Make",
"Zig", "MATLAB",
"Meson",
"Navi",
"Navi Stream",
"Nim",
"Noir",
"Nu",
"Odin",
"Pact",
"Pest",
"pica200",
"Pkl",
"QML",
"R",
"Rainbow CSV",
"Rainbow TSV",
"rego",
"ReScript",
"Roc",
"RON",
"Scala",
"SCSS",
"Smithy",
"Solidity",
"bazelrc",
"Starlark",
"Templ",
"Twig",
"Typst",
"Unison",
"V",
"Vala",
"Verilog",
"VHS",
"Wgsl",
"WIT",
"XML",
"C",
"C++",
"CSS",
"Go",
"Go Mod",
"Go Work",
"JavaScript",
"JSDoc",
"JSON",
"JSONC",
"Markdown-Inline",
"Markdown",
"proto",
"Python",
"Regex",
"Rust",
"TSX",
"TypeScript",
"YAML",
"Astro",
"Clojure",
"CSharp",
"Dart",
"Elixir",
"HEEX",
"Elm",
"Erlang",
"Gleam",
"GLSL",
"Haskell",
"HTML",
"Lua",
"OCaml Interface",
"OCaml",
"PHP",
"PHPDoc",
"Prisma",
"PureScript",
"Racket",
"ERB",
"Ruby",
"Scheme",
"Svelte",
"HCL",
"Terraform Vars",
"Terraform",
"TOML",
"Uiua",
"Vue.js",
"Zig",
] ]
language_ids = { "Shell Script" = "bash", "C" = "c", "C++" = "cpp", "CSS" = "css", "Go" = "go", "Go Mod" = "gomod", "Go Work" = "gowork", "JavaScript" = "javascript", "JSDoc" = "jsdoc", "JSON" = "json", "JSONC" = "jsonc", "Markdown" = "markdown", "proto" = "proto", "Python" = "python", "Regex" = "regex", "Rust" = "rust", "TSX" = "tsx", "TypeScript" = "typescript", "YAML" = "yaml", "Astro" = "astro", "Clojure" = "clojure", "CSharp" = "csharp", "Dart" = "dart", "Elixir" = "elixir", "HEEX" = "heex", "Elm" = "elm", "Erlang" = "erlang", "Gleam" = "gleam", "GLSL" = "glsl", "Haskell" = "haskell", "HTML" = "html", "Lua" = "lua", "OCaml Interface" = "ocaml-interface", "OCaml" = "ocaml", "PHP" = "php", "PHPDoc" = "phpdoc", "Prisma" = "prisma", "PureScript" = "purescript", "Racket" = "racket", "ERB" = "erb", "Ruby" = "ruby", "Scheme" = "scheme", "Svelte" = "svelte", "HCL" = "hcl", "Terraform Vars" = "terraform-vars", "Terraform" = "terraform", "TOML" = "toml", "Uiua" = "uiua", "Vue.js" = "vue", "Zig" = "zig"} language_ids = { "AsciiDoc" = "asciidoc", "Assembly" = "asm", "Shell Script" = "bash", "Beancount" = "beancount", "Bend" = "bend", "Blade" = "blade", "BQN" = "BQN", "Brainfuck" = "brainfuck", "Cadence" = "cadence", "Cairo" = "cairo", "Cap'n Proto" = "capnp", "Cedar" = "cedar", "CFEngine" = "cfengine", "CSV" = "csv", "Gherkin" = "gherkin", "CUE" = "cue", "D" = "d", "DBML" = "dbml", "Earthfile" = "earthfile", "Elisp" = "elisp", "Handlebars" = "glimmer", "Exograph" = "exograph", "Fish" = "fish", "FSharp" = "fsharp", "GDScript" = "gdscript", "Godot Resource" = "godot_resource", "Gemini" = "gemini", "Diff" = "diff", "Git Attributes" = "gitattributes", "Git Commit" = "gitcommit", "Git Config" = "gitconfig", "Git Ignore" = "gitignore", "Git Rebase" = "gitrebase", "GraphQL" = "graphql", "Groovy" = "groovy", "GROQ" = "groq", "ini" = "ini", "Jsonnet" = "jsonnet", "Julia" = "julia", "Just" = "just", "LaTeX" = "latex", "Ledger" = "ledger", "LESS" = "less", "LilyPond" = "lilypond", "LilyPond Scheme" = "lilypond_scheme", "Liquid" = "liquid", "Lox" = "lox", "Luau" = "luau", "Make" = "make", "MATLAB" = "matlab", "Meson" = "meson", "Navi" = "navi", "Navi Stream" = "navi_stream", "Nim" = "nim", "Noir" = "noir", "Nu" = "nu", "Odin" = "odin", "Pact" = "pact", "Pest" = "pest", "pica200" = "pica200", "Pkl" = "pkl", "QML" = "qml", "R" = "r", "Rainbow CSV" = "csv", "Rainbow TSV" = "tsv", "rego" = "rego", "ReScript" = "rescript", "Roc" = "roc", "RON" = "ron", "Scala" = "scala", "SCSS" = "scss", "Smithy" = "smithy", "Solidity" = "solidity", "bazelrc" = "bazelrc", "Starlark" = "starlark", "Templ" = "templ", "Twig" = "twig", "Typst" = "typst", "Unison" = "unison", "V" = "v", "Vala" = "vala", "Verilog" = "verilog", "VHS" = "vhs", "Wgsl" = "wgsl", "WIT" = "wit", "XML" = "xml", "C" = "c", "C++" = "cpp", "CSS" = "css", "Go" = "go", "Go Mod" = "gomod", "Go Work" = "gowork", "JavaScript" = "javascript", "JSDoc" = "jsdoc", "JSON" = "json", "JSONC" = "jsonc", "Markdown-Inline" = "markdown-inline", "Markdown" = "markdown", "proto" = "proto", "Python" = "python", "Regex" = "regex", "Rust" = "rust", "TSX" = "tsx", "TypeScript" = "typescript", "YAML" = "yaml", "Astro" = "astro", "Clojure" = "clojure", "CSharp" = "csharp", "Dart" = "dart", "Elixir" = "elixir", "HEEX" = "heex", "Elm" = "elm", "Erlang" = "erlang", "Gleam" = "gleam", "GLSL" = "glsl", "Haskell" = "haskell", "HTML" = "html", "Lua" = "lua", "OCaml Interface" = "ocaml-interface", "OCaml" = "ocaml", "PHP" = "php", "PHPDoc" = "phpdoc", "Prisma" = "prisma", "PureScript" = "purescript", "Racket" = "racket", "ERB" = "erb", "Ruby" = "ruby", "Scheme" = "scheme", "Svelte" = "svelte", "HCL" = "hcl", "Terraform Vars" = "terraform-vars", "Terraform" = "terraform", "TOML" = "toml", "Uiua" = "uiua", "Vue.js" = "vue", "Zig" = "zig" }

View file

@ -1,30 +1,64 @@
#!/bin/bash #!/bin/bash
fetch_files() {
local repo_owner=$1
local repo_name=$2
curl -s "https://api.github.com/repos/$repo_owner/$repo_name/git/trees/main?recursive=1" -H "Authorization: Bearer ${GITHUB_TOKEN}" | jq -c -r '.tree[] | .path'
}
process_language_files() {
local files=$1
local repo_owner=$2
local repo_name=$3
local file_patterns=("${@:4}")
for file in $files; do
local match=false
for pattern in "${file_patterns[@]}"; do
if [[ $file == $pattern ]]; then
match=true
break
fi
done
if ! $match; then
continue
fi
name=$(curl -s "https://raw.githubusercontent.com/$repo_owner/$repo_name/main/${file}" | grep -oP '^name = "\K[^"]*')
id="${file%/config.toml}"
id="${id##*/}"
if [[ $LANGUAGES == *"$name\","* && $LANGUAGE_IDS == *"$name\" = \"$id\","* ]]; then
echo "Skipping language $name with id $id (already added)"
else
echo "Adding language $name with id $id"
LANGUAGES+=" \"$name\",\n"
LANGUAGE_IDS+=" \"$name\" = \"$id\","
fi
done
}
RESPONSE=$(curl -s "https://api.github.com/repos/zed-industries/zed/git/trees/main?recursive=1" -H "Authorization: Bearer ${GITHUB_TOKEN}") RESPONSE=$(curl -s "https://api.github.com/repos/zed-industries/zed/git/trees/main?recursive=1" -H "Authorization: Bearer ${GITHUB_TOKEN}")
EXTENSIONS_RESPONSE=$(curl -s "https://raw.githubusercontent.com/zed-industries/extensions/main/.gitmodules")
REPOSITORIES=($(echo "$EXTENSIONS_RESPONSE" | grep -oP 'url = \K.*'))
FILES=$(echo "$RESPONSE" | jq -c -r '.tree[] | .path') FILES=$(echo "$RESPONSE" | jq -c -r '.tree[] | .path')
LANGUAGES="languages = [\n" LANGUAGES="languages = [\n"
LANGUAGE_IDS="language_ids = {" LANGUAGE_IDS="language_ids = {"
for file in $FILES; do for repository in "${REPOSITORIES[@]}"; do
if ! [[ $file == crates/languages/src/**/config.toml || $file == extensions/**/languages/**/config.toml ]]; then repo_owner=$(echo "$repository" | cut -d'/' -f4)
continue repo_name=$(echo "$repository" | cut -d'/' -f5 | sed 's/.git$//')
fi
if [[ $file == extensions/test-extension/* ]]; then echo "Checking $repository ($repo_owner/$repo_name)"
continue files=$(fetch_files "$repo_owner" "$repo_name")
fi process_language_files "$files" "$repo_owner" "$repo_name" "languages/**/config.toml"
name=$(curl -s "https://raw.githubusercontent.com/zed-industries/zed/main/${file}" | head -n 1 | sed 's/^name = "\(.*\)"$/\1/')
id="${file%/config.toml}"
id="${id##*/}"
echo "Adding language $name with id $id"
LANGUAGES+=" \"$name\",\n"
LANGUAGE_IDS+=" \"$name\" = \"$id\","
done done
echo "Processing zed-industries/zed"
process_language_files "$FILES" "zed-industries" "zed" "crates/languages/src/**/config.toml" "extensions/**/languages/**/config.toml"
LANGUAGES+="]" LANGUAGES+="]"
LANGUAGE_IDS+="}" LANGUAGE_IDS+="}"