From 5277297f195812d2004026a9d8306b4113cdacff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jozef=20Steinh=C3=BCbl?= Date: Wed, 24 Jul 2024 23:55:36 +0200 Subject: [PATCH] feat: add support for even more languages scrape zed-industries/extensions --- extension.toml | 190 ++++++++++++++++++++++++++++----------- scripts/get_languages.sh | 66 ++++++++++---- 2 files changed, 188 insertions(+), 68 deletions(-) diff --git a/extension.toml b/extension.toml index b3edb8d..0db9388 100644 --- a/extension.toml +++ b/extension.toml @@ -1,6 +1,6 @@ id = "discord_presence" name = "Discord Presence" -version = "0.1.0" +version = "0.2.0" schema_version = 1 authors = ["Jozef Steinhübl "] description = "Presence for your beautiful discord account :)" @@ -10,55 +10,141 @@ repository = "https://git.sr.ht/~hyro/zed-discord-presence" name = "Discord Presence LSP" # Generated by scripts/get_languages.sh languages = [ - "Shell Script", - "C", - "C++", - "CSS", - "Go", - "Go Mod", - "Go Work", - "JavaScript", - "JSDoc", - "JSON", - "JSONC", - "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", + "AsciiDoc", + "Assembly", + "Shell Script", + "Beancount", + "Bend", + "Blade", + "BQN", + "Brainfuck", + "Cadence", + "Cairo", + "Cap'n Proto", + "Cedar", + "CFEngine", + "CSV", + "Gherkin", + "CUE", + "D", + "DBML", + "Earthfile", + "Elisp", + "Handlebars", + "Exograph", + "Fish", + "FSharp", + "GDScript", + "Godot Resource", + "Gemini", + "Diff", + "Git Attributes", + "Git Commit", + "Git Config", + "Git Ignore", + "Git Rebase", + "GraphQL", + "Groovy", + "GROQ", + "ini", + "Jsonnet", + "Julia", + "Just", + "LaTeX", + "Ledger", + "LESS", + "LilyPond", + "LilyPond Scheme", + "Liquid", + "Lox", + "Luau", + "Make", + "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" } diff --git a/scripts/get_languages.sh b/scripts/get_languages.sh index 5c8a70c..4d701dc 100755 --- a/scripts/get_languages.sh +++ b/scripts/get_languages.sh @@ -1,30 +1,64 @@ #!/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}") +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') LANGUAGES="languages = [\n" LANGUAGE_IDS="language_ids = {" -for file in $FILES; do - if ! [[ $file == crates/languages/src/**/config.toml || $file == extensions/**/languages/**/config.toml ]]; then - continue - fi +for repository in "${REPOSITORIES[@]}"; do + repo_owner=$(echo "$repository" | cut -d'/' -f4) + repo_name=$(echo "$repository" | cut -d'/' -f5 | sed 's/.git$//') - if [[ $file == extensions/test-extension/* ]]; then - continue - fi - - 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\"," + echo "Checking $repository ($repo_owner/$repo_name)" + files=$(fetch_files "$repo_owner" "$repo_name") + process_language_files "$files" "$repo_owner" "$repo_name" "languages/**/config.toml" done +echo "Processing zed-industries/zed" +process_language_files "$FILES" "zed-industries" "zed" "crates/languages/src/**/config.toml" "extensions/**/languages/**/config.toml" + LANGUAGES+="]" LANGUAGE_IDS+="}"