From 67438c478b00199e85ba9e7c19dd585f4a3c8cdf Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Mar 2026 16:26:59 +0000 Subject: [PATCH 1/2] Initial plan From e8a6696d8561947cfa3ac439d5c402dbf5fab6a1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Mar 2026 16:32:42 +0000 Subject: [PATCH 2/2] Add tree-sitter devcontainer feature Agent-Logs-Url: https://github.com/devcontainer-community/devcontainer-features/sessions/4006bd65-790f-437b-8f8b-e264412ec356 Co-authored-by: sebst <592313+sebst@users.noreply.github.com> --- README.md | 1 + src/tree-sitter/devcontainer-feature.json | 15 +++ src/tree-sitter/install.sh | 151 ++++++++++++++++++++++ test/tree-sitter/test.sh | 17 +++ 4 files changed, 184 insertions(+) create mode 100644 src/tree-sitter/devcontainer-feature.json create mode 100755 src/tree-sitter/install.sh create mode 100755 test/tree-sitter/test.sh diff --git a/README.md b/README.md index 3f3a3ff..6a3914f 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,7 @@ | [sxyazi/yazi](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/sxyazi-yazi) | `yazi` — blazing fast terminal file manager | gh release | 1.0.0 | | [tailscale.com](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/tailscale.com) | `tailscale` — zero-config mesh VPN | curl | 1.0.0 | | [taskwarrior.org](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/taskwarrior.org) | `task` — command-line task manager | apt | 1.0.0 | +| [tree-sitter](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/tree-sitter) | `tree-sitter` — incremental parsing toolkit for building syntax trees | gh release | 1.0.0 | | [turso.tech](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/turso.tech) | `tursodb` — in-process SQL database compatible with SQLite | gh release | 1.0.0 | | [webinstall.dev](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/webinstall.dev) | `webi` — install packages without sudo | curl | 1.0.1 | | [yakitrak/notesmd-cli](https://github.com/devcontainer-community/devcontainer-features/tree/main/src/yakitrak-notesmd-cli) | `notesmd-cli` — manage Obsidian vaults from the terminal | gh release | 1.0.0 | diff --git a/src/tree-sitter/devcontainer-feature.json b/src/tree-sitter/devcontainer-feature.json new file mode 100644 index 0000000..79c1b56 --- /dev/null +++ b/src/tree-sitter/devcontainer-feature.json @@ -0,0 +1,15 @@ +{ + "name": "tree-sitter", + "id": "tree-sitter", + "version": "1.0.0", + "description": "Install \"tree-sitter\" binary", + "documentationURL": "https://github.com/devcontainer-community/devcontainer-features/tree/main/src/tree-sitter", + "options": { + "version": { + "type": "string", + "default": "latest", + "proposals": ["latest"], + "description": "Version of \"tree-sitter\" to install." + } + } +} diff --git a/src/tree-sitter/install.sh b/src/tree-sitter/install.sh new file mode 100755 index 0000000..36647f8 --- /dev/null +++ b/src/tree-sitter/install.sh @@ -0,0 +1,151 @@ +#!/bin/bash +set -o errexit +set -o pipefail +set -o noclobber +set -o nounset +set -o allexport +readonly githubRepository='tree-sitter/tree-sitter' +readonly binaryName='tree-sitter' +readonly versionArgument='--version' +readonly downloadUrlTemplate='https://github.com/${githubRepository}/releases/download/${releaseTag}/tree-sitter-cli-linux-${architecture}.zip' +readonly binaryPathInArchiveTemplate='${binaryName}' +readonly binaryTargetFolder='/usr/local/bin' +readonly name="${githubRepository##*/}" +apt_get_update() { + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi +} +apt_get_checkinstall() { + if ! dpkg -s "$@" >/dev/null 2>&1; then + apt_get_update + DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends --no-install-suggests --option 'Debug::pkgProblemResolver=true' --option 'Debug::pkgAcquire::Worker=1' "$@" + fi +} +apt_get_cleanup() { + apt-get clean + rm -rf /var/lib/apt/lists/* +} +check_curl_envsubst_unzip_installed() { + declare -a requiredAptPackagesMissing=() + if ! [ -r '/etc/ssl/certs/ca-certificates.crt' ]; then + requiredAptPackagesMissing+=('ca-certificates') + fi + if ! command -v curl >/dev/null 2>&1; then + requiredAptPackagesMissing+=('curl') + fi + if ! command -v envsubst >/dev/null 2>&1; then + requiredAptPackagesMissing+=('gettext-base') + fi + if ! command -v unzip >/dev/null 2>&1; then + requiredAptPackagesMissing+=('unzip') + fi + declare -i requiredAptPackagesMissingCount=${#requiredAptPackagesMissing[@]} + if [ $requiredAptPackagesMissingCount -gt 0 ]; then + apt_get_update + apt_get_checkinstall "${requiredAptPackagesMissing[@]}" + apt_get_cleanup + fi +} +curl_check_url() { + local url=$1 + local status_code + status_code=$(curl -s -o /dev/null -w '%{http_code}' "$url") + if [ "$status_code" -ne 200 ] && [ "$status_code" -ne 302 ]; then + echo "Failed to download '$url'. Status code: $status_code." + return 1 + fi +} +curl_download_unzip() { + local url=$1 + local target=$2 + local bin_path=$3 + local tmpdir + tmpdir=$(mktemp -d) + curl \ + --silent \ + --location \ + --connect-timeout 5 \ + --output "$tmpdir/download.zip" \ + "$url" + unzip -p "$tmpdir/download.zip" "$bin_path" > "$target/$binaryName" + rm -rf "$tmpdir" +} +debian_get_arch() { + echo "$(dpkg --print-architecture)" +} +debian_get_target_arch() { + case $(debian_get_arch) in + amd64) echo 'x64' ;; + arm64) echo 'arm64' ;; + armhf) echo 'arm' ;; + i386) echo 'x86' ;; + *) echo 'unknown' ;; + esac +} +echo_banner() { + local text="$1" + echo -e "\e[1m\e[97m\e[41m$text\e[0m" +} +github_list_releases() { + if [ -z "$1" ]; then + echo "Usage: list_github_releases " + return 1 + fi + local repo="$1" + local url="https://api.github.com/repos/$repo/releases" + curl -s "$url" | grep -Po '"tag_name": "\K.*?(?=")' | grep -E '^v?[0-9]+\.[0-9]+\.[0-9]+$' | sed 's/^v//' +} +github_get_latest_release() { + if [ -z "$1" ]; then + echo "Usage: get_latest_github_release " + return 1 + fi + github_list_releases "$1" | head -n 1 +} +github_get_tag_for_version() { + if [ -z "$1" ] || [ -z "$2" ]; then + echo "Usage: github_get_tag_for_version " + return 1 + fi + local repo="$1" + local _version="$2" + local url="https://api.github.com/repos/$repo/releases" + local escaped_version + escaped_version="$(printf '%s' "$_version" | sed 's/\./\\./g')" + curl -s "$url" | grep -Po '"tag_name": "\K.*?(?=")' | grep -E "^v?${escaped_version}$" | head -n 1 +} +utils_check_version() { + local version=$1 + if ! [[ "${version:-}" =~ ^(latest|[0-9]+\.[0-9]+\.[0-9]+)$ ]]; then + printf >&2 '=== [ERROR] Option "version" (value: "%s") is not "latest" or valid semantic version format "X.Y.Z" !\n' \ + "$version" + exit 1 + fi +} +install() { + utils_check_version "$VERSION" + check_curl_envsubst_unzip_installed + readonly architecture="$(debian_get_target_arch)" + readonly binaryTargetPath="${binaryTargetFolder}/${binaryName}" + if [ "$VERSION" == 'latest' ] || [ -z "$VERSION" ]; then + VERSION=$(github_get_latest_release "$githubRepository") + fi + readonly version="${VERSION:?}" + readonly releaseTag="$(github_get_tag_for_version "$githubRepository" "$version")" + if [ -z "$releaseTag" ]; then + printf >&2 '=== [ERROR] Could not find release tag for version "%s" in "%s"!\n' "$version" "$githubRepository" + exit 1 + fi + readonly downloadUrl="$(echo -n "$downloadUrlTemplate" | envsubst)" + curl_check_url "$downloadUrl" + readonly binaryPathInArchive="$(echo -n "$binaryPathInArchiveTemplate" | envsubst)" + curl_download_unzip "$downloadUrl" "$binaryTargetFolder" "$binaryPathInArchive" + chmod 755 "$binaryTargetPath" + apt_get_cleanup +} +echo_banner "devcontainer.community" +echo "Installing $name..." +install "$@" +echo "(*) Done!" diff --git a/test/tree-sitter/test.sh b/test/tree-sitter/test.sh new file mode 100755 index 0000000..32fc52e --- /dev/null +++ b/test/tree-sitter/test.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +# See https://github.com/devcontainers/cli/blob/HEAD/docs/features/test.md#dev-container-features-test-lib +# Provides the 'check' and 'reportResults' commands. +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. Syntax is... +# check