diff --git a/pkgs/by-name/ph/phpantom-lsp/package.nix b/pkgs/by-name/ph/phpantom-lsp/package.nix new file mode 100644 index 000000000000..d3196b088358 --- /dev/null +++ b/pkgs/by-name/ph/phpantom-lsp/package.nix @@ -0,0 +1,67 @@ +{ + lib, + rustPlatform, + fetchFromGitHub, + versionCheckHook, + _experimental-update-script-combinators, + nix-update-script, +}: + +let + stubsSrc = fetchFromGitHub { + owner = "JetBrains"; + repo = "phpstorm-stubs"; + rev = "3327932472f512d2eb9e122b19702b335083fd9d"; + hash = "sha256-WN5DAvaw4FfHBl2AqSo1OcEthUm3lOpikdB78qy3cyY="; + }; +in + +rustPlatform.buildRustPackage (finalAttrs: { + pname = "phpantom-lsp"; + version = "0.7.0"; + + __structuredAttrs = true; + + src = fetchFromGitHub { + owner = "AJenbo"; + repo = "phpantom_lsp"; + tag = finalAttrs.version; + hash = "sha256-ZmtOdoxXkwn2IDg7RyQ9KG0RNz5mrGDMcESfcOSR3Ig="; + }; + + postPatch = '' + mkdir -p stubs/jetbrains + cp -a ${finalAttrs.passthru.stubsSrc} stubs/jetbrains/phpstorm-stubs + chmod u+wx stubs/jetbrains/phpstorm-stubs + + echo "${finalAttrs.passthru.stubsSrc.rev}" \ + > stubs/jetbrains/phpstorm-stubs/.commit + ''; + + cargoHash = "sha256-pXP4qItYgmUXVx9XwMdS6WLVc5lP7P4VX9+0TbhYrUc="; + + checkFlags = [ + "--test" + "completion_inheritance" + ]; + + nativeInstallCheckInputs = [ versionCheckHook ]; + doInstallCheck = true; + + passthru = { + inherit stubsSrc; + updateScript = _experimental-update-script-combinators.sequence [ + (nix-update-script { }) + ./update-php-stubs.sh + ]; + }; + + meta = { + changelog = "https://github.com/AJenbo/phpantom_lsp/releases/tag/${finalAttrs.src.tag}"; + description = "Fast, lightweight PHP language server written in Rust"; + homepage = "https://github.com/AJenbo/phpantom_lsp"; + license = lib.licenses.mit; + mainProgram = "phpantom_lsp"; + maintainers = with lib.maintainers; [ nanoyaki ]; + }; +}) diff --git a/pkgs/by-name/ph/phpantom-lsp/update-php-stubs.sh b/pkgs/by-name/ph/phpantom-lsp/update-php-stubs.sh new file mode 100755 index 000000000000..613aef6b972e --- /dev/null +++ b/pkgs/by-name/ph/phpantom-lsp/update-php-stubs.sh @@ -0,0 +1,18 @@ +#! /usr/bin/env nix-shell +#! nix-shell -i bash -p bash curl gnused gnugrep nix-prefetch-github jq + +file="./pkgs/by-name/ph/phpantom-lsp/package.nix" + +version="$(grep -oP 'version = "\K[\d\.]+' "$file")" +curl -O "https://raw.githubusercontent.com/AJenbo/phpantom_lsp/refs/tags/$version/stubs.lock" +stubsVersion="$(grep -oP 'commit = "\K[^"]+' ./stubs.lock)" +rm stubs.lock + +stubsHash="$( + nix-prefetch-github --rev "$stubsVersion" "JetBrains" "phpstorm-stubs" --json \ + 2> /dev/null \ + | jq -r '.hash' +)" + +sed -i 's/\(rev = "\)[^"]*/\1'"$stubsVersion"'/' "$file" +sed -i '/stubsSrc/,/}/ s#\(hash = "\)[^"]*#\1'"$stubsHash"'#' "$file"