diff --git a/flake.lock b/flake.lock index e312e49..dbf3f12 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "flake-compat": { "flake": false, "locked": { - "lastModified": 1696426674, - "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "lastModified": 1733328505, + "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", "owner": "edolstra", "repo": "flake-compat", - "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", "type": "github" }, "original": { @@ -35,11 +35,11 @@ "flake-compat_3": { "flake": false, "locked": { - "lastModified": 1696426674, - "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "lastModified": 1733328505, + "narHash": "sha256-NeCCThCEP3eCl2l/+27kNNK7QrwZB1IJCrXfrbv5oqU=", "owner": "edolstra", "repo": "flake-compat", - "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "rev": "ff81ac966bb2cae68946d5ed5fc4994f96d0ffec", "type": "github" }, "original": { @@ -103,11 +103,11 @@ "nixpkgs-lib": "nixpkgs-lib_2" }, "locked": { - "lastModified": 1722555600, - "narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=", + "lastModified": 1738453229, + "narHash": "sha256-7H9XgNiGLKN1G1CgRh0vUL4AheZSYzPm+zmZ7vxbJdo=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "8471fe90ad337a8074e957b69ca4d0089218391d", + "rev": "32ea77a06711b758da0ad9bd6a844c5740a87abd", "type": "github" }, "original": { @@ -125,11 +125,11 @@ ] }, "locked": { - "lastModified": 1722555600, - "narHash": "sha256-XOQkdLafnb/p9ij77byFQjDf5m5QYl9b2REiVClC+x4=", + "lastModified": 1738453229, + "narHash": "sha256-7H9XgNiGLKN1G1CgRh0vUL4AheZSYzPm+zmZ7vxbJdo=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "8471fe90ad337a8074e957b69ca4d0089218391d", + "rev": "32ea77a06711b758da0ad9bd6a844c5740a87abd", "type": "github" }, "original": { @@ -148,11 +148,11 @@ ] }, "locked": { - "lastModified": 1712014858, - "narHash": "sha256-sB4SWl2lX95bExY2gMFG5HIzvva5AVMJd4Igm+GpZNw=", + "lastModified": 1736143030, + "narHash": "sha256-+hu54pAoLDEZT9pjHlqL9DNzWz0NbUn8NEAHP7PQPzU=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "9126214d0a59633752a136528f5f3b9aa8565b7d", + "rev": "b905f6fc23a9051a6e1b741e1438dbfc0634c6de", "type": "github" }, "original": { @@ -182,15 +182,14 @@ "inputs": { "flake-compat": "flake-compat_2", "gitignore": "gitignore", - "nixpkgs": "nixpkgs", - "nixpkgs-stable": "nixpkgs-stable" + "nixpkgs": "nixpkgs" }, "locked": { - "lastModified": 1723803910, - "narHash": "sha256-yezvUuFiEnCFbGuwj/bQcqg7RykIEqudOy/RBrId0pc=", + "lastModified": 1737465171, + "narHash": "sha256-R10v2hoJRLq8jcL4syVFag7nIGE7m13qO48wRIukWNg=", "owner": "cachix", "repo": "git-hooks.nix", - "rev": "bfef0ada09e2c8ac55bbcd0831bd0c9d42e651ba", + "rev": "9364dc02281ce2d37a1f55b6e51f7c0f65a75f17", "type": "github" }, "original": { @@ -207,19 +206,14 @@ "neorocks", "neovim-nightly", "nixpkgs" - ], - "nixpkgs-stable": [ - "neorocks", - "neovim-nightly", - "nixpkgs" ] }, "locked": { - "lastModified": 1723803910, - "narHash": "sha256-yezvUuFiEnCFbGuwj/bQcqg7RykIEqudOy/RBrId0pc=", + "lastModified": 1737465171, + "narHash": "sha256-R10v2hoJRLq8jcL4syVFag7nIGE7m13qO48wRIukWNg=", "owner": "cachix", "repo": "git-hooks.nix", - "rev": "bfef0ada09e2c8ac55bbcd0831bd0c9d42e651ba", + "rev": "9364dc02281ce2d37a1f55b6e51f7c0f65a75f17", "type": "github" }, "original": { @@ -236,7 +230,7 @@ "vimcats", "nixpkgs" ], - "nixpkgs-stable": "nixpkgs-stable_2" + "nixpkgs-stable": "nixpkgs-stable" }, "locked": { "lastModified": 1725438226, @@ -330,11 +324,11 @@ ] }, "locked": { - "lastModified": 1719226092, - "narHash": "sha256-YNkUMcCUCpnULp40g+svYsaH1RbSEj6s4WdZY/SHe38=", + "lastModified": 1738237977, + "narHash": "sha256-oJN/yvRL7G0WlR/hTkQIjFbPkzCV+sFnNB/38Tb9RL4=", "owner": "hercules-ci", "repo": "hercules-ci-effects", - "rev": "11e4b8dc112e2f485d7c97e1cee77f9958f498f5", + "rev": "6d1b6d5d59758b4f5f05745f774fc13cdc59da43", "type": "github" }, "original": { @@ -352,11 +346,11 @@ "nixpkgs": "nixpkgs_3" }, "locked": { - "lastModified": 1724045136, - "narHash": "sha256-wAjB2G+aOVF94xD+RSKCddaLnmQXEpKumoWYPDC7NWk=", + "lastModified": 1739251652, + "narHash": "sha256-dUMF7GXb+LRRjXTRdYmOZvRnroTKyymf4pUou1XwamI=", "owner": "nvim-neorocks", "repo": "neorocks", - "rev": "8b18af8ac0449a590949ae431de3f32ad2e1174c", + "rev": "c8165828eb398b6496b5913745c33ed5ae598d18", "type": "github" }, "original": { @@ -372,14 +366,15 @@ "git-hooks": "git-hooks_2", "hercules-ci-effects": "hercules-ci-effects", "neovim-src": "neovim-src", - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs_2", + "treefmt-nix": "treefmt-nix" }, "locked": { - "lastModified": 1723969597, - "narHash": "sha256-nNSmyoR8k2gEw9LZ+nFcBQm+bquflzw2R44BeJ4gmKk=", + "lastModified": 1739232942, + "narHash": "sha256-BB67RIHP2SYVocjoFaJ6OUmHItF42sNcLO/330DHWn8=", "owner": "nix-community", "repo": "neovim-nightly-overlay", - "rev": "ec3ee3674c80882ac54d93b5575426c66e3f430d", + "rev": "705e07d87df327c6e74add1be99c65cfee21cacf", "type": "github" }, "original": { @@ -391,11 +386,11 @@ "neovim-src": { "flake": false, "locked": { - "lastModified": 1723936741, - "narHash": "sha256-x/0wYCshhLSA9zW4fvPK+W6g3gTqE8fMJQZrIucDyXg=", + "lastModified": 1739211707, + "narHash": "sha256-nxQ0sMFIqSTuD8C+AsS6DcMYQbmi4ZWmkGyrqJh/D1Y=", "owner": "neovim", "repo": "neovim", - "rev": "d1bdeacb00186ba72fa61f3c7f2951fd018ae21d", + "rev": "c7d13f2895fa657ff3d9d45741f9abec25072b56", "type": "github" }, "original": { @@ -406,11 +401,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1719082008, - "narHash": "sha256-jHJSUH619zBQ6WdC21fFAlDxHErKVDJ5fpN0Hgx4sjs=", + "lastModified": 1730768919, + "narHash": "sha256-8AKquNnnSaJRXZxc5YmF/WfmxiHX6MMZZasRP6RRQkE=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9693852a2070b398ee123a329e68f0dab5526681", + "rev": "a04d33c0c3f1a59a2c1cb0c6e34cd24500e5a1dc", "type": "github" }, "original": { @@ -434,14 +429,14 @@ }, "nixpkgs-lib_2": { "locked": { - "lastModified": 1722555339, - "narHash": "sha256-uFf2QeW7eAHlYXuDktm9c25OxOyCoUOQmh5SZ9amE5Q=", + "lastModified": 1738452942, + "narHash": "sha256-vJzFZGaCpnmo7I6i416HaBLpC+hvcURh/BQwROcGIp8=", "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/a5d394176e64ab29c852d03346c1fc9b0b7d33eb.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/072a6db25e947df2f31aab9eccd0ab75d5b2da11.tar.gz" }, "original": { "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/a5d394176e64ab29c852d03346c1fc9b0b7d33eb.tar.gz" + "url": "https://github.com/NixOS/nixpkgs/archive/072a6db25e947df2f31aab9eccd0ab75d5b2da11.tar.gz" } }, "nixpkgs-lib_3": { @@ -472,29 +467,13 @@ "type": "github" } }, - "nixpkgs-stable_2": { - "locked": { - "lastModified": 1720386169, - "narHash": "sha256-NGKVY4PjzwAa4upkGtAMz1npHGoRzWotlSnVlqI40mo=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "194846768975b7ad2c4988bdb82572c00222c0d7", - "type": "github" - }, - "original": { - "owner": "NixOS", - "ref": "nixos-24.05", - "repo": "nixpkgs", - "type": "github" - } - }, "nixpkgs_2": { "locked": { - "lastModified": 1723856861, - "narHash": "sha256-OTDg91+Zzs2SpU3csK4xVdSQFoG8cK1lNUwKmTqERyE=", + "lastModified": 1739019272, + "narHash": "sha256-7Fu7oazPoYCbDzb9k8D/DdbKrC3aU1zlnc39Y8jy/s8=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "cd7b95ee3725af7113bacbce91dd6549cee58ca5", + "rev": "fa35a3c8e17a3de613240fea68f876e5b4896aec", "type": "github" }, "original": { @@ -506,11 +485,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1723985069, - "narHash": "sha256-MGtXhZHLZGKhtZT/MYXBJEuMkZB5DLYjY679EYNL7Es=", + "lastModified": 1739019272, + "narHash": "sha256-7Fu7oazPoYCbDzb9k8D/DdbKrC3aU1zlnc39Y8jy/s8=", "owner": "nixos", "repo": "nixpkgs", - "rev": "ff1c2669bbb4d0dd9e62cc94f0968cfa652ceec1", + "rev": "fa35a3c8e17a3de613240fea68f876e5b4896aec", "type": "github" }, "original": { @@ -522,11 +501,11 @@ }, "nixpkgs_4": { "locked": { - "lastModified": 1723637854, - "narHash": "sha256-med8+5DSWa2UnOqtdICndjDAEjxr5D7zaIiK4pn0Q7c=", + "lastModified": 1739020877, + "narHash": "sha256-mIvECo/NNdJJ/bXjNqIh8yeoSjVLAuDuTUzAo7dzs8Y=", "owner": "nixos", "repo": "nixpkgs", - "rev": "c3aa7b8938b17aebd2deecf7be0636000d62a2b9", + "rev": "a79cfe0ebd24952b580b1cf08cd906354996d547", "type": "github" }, "original": { @@ -560,6 +539,28 @@ "vimcats": "vimcats" } }, + "treefmt-nix": { + "inputs": { + "nixpkgs": [ + "neorocks", + "neovim-nightly", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1738953846, + "narHash": "sha256-yrK3Hjcr8F7qS/j2F+r7C7o010eVWWlm4T1PrbKBOxQ=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "4f09b473c936d41582dd744e19f34ec27592c5fd", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + }, "vimcats": { "inputs": { "flake-parts": "flake-parts_5", diff --git a/flake.nix b/flake.nix index 0f69169..3b0fcad 100644 --- a/flake.nix +++ b/flake.nix @@ -16,6 +16,10 @@ flake-parts, ... }: let + name = "rest.nvim"; + plugin-overlay = import ./nix/plugin-overlay.nix { + inherit self; + }; test-overlay = import ./nix/test-overlay.nix { inherit self inputs; }; @@ -31,6 +35,7 @@ overlays = [ neorocks.overlays.default test-overlay + plugin-overlay ]; }; in { @@ -40,6 +45,7 @@ inherit (pkgs) docgen + sync-readme ; }; devShells.default = pkgs.mkShell { @@ -47,22 +53,25 @@ shellHook = '' export LUA_PATH="$(luarocks path --lr-path --lua-version 5.1 --local)" export LUA_CPATH="$(luarocks path --lr-cpath --lua-version 5.1 --local)" + export TREE_SITTER_HTTP_PLUGIN_DIR=${pkgs.tree-sitter-http-plugin} + export REST_NVIM_PLUGIN_DIR=${pkgs.rest-nvim-dev} ''; buildInputs = [ pkgs.sumneko-lua-language-server pkgs.stylua pkgs.docgen + pkgs.sync-readme (pkgs.lua5_1.withPackages (ps: with ps; [luarocks luacheck])) ]; }; - # checks = { - # inherit - # (pkgs) - # # integration-stable - # integration-nightly - # ; - # }; + checks = { + inherit + (pkgs) + integration-stable + integration-nightly + ; + }; }; }; } diff --git a/nix/plugin-overlay.nix b/nix/plugin-overlay.nix new file mode 100644 index 0000000..7a44abb --- /dev/null +++ b/nix/plugin-overlay.nix @@ -0,0 +1,39 @@ +{ self }: final: prev: let + luaPackages-override = luaself: luaprev: { + tree-sitter-http = luaself.callPackage ./tree-sitter-http.nix {}; + rest-nvim = luaself.callPackage ({ + buildLuarocksPackage, + fetchurl, + fetchzip, + luaOlder, + }: + buildLuarocksPackage { + pname = "rest.nvim"; + version = "scm-1"; + knownRockspec = "${self}/rest.nvim-scm-1.rockspec"; + src = self; + + disabled = luaOlder "5.1"; + propagatedBuildInputs = with luaself; [ + nvim-nio + mimetypes + xml2lua + fidget-nvim + tree-sitter-http + ]; + }) {}; + }; + tree-sitter-http-plugin = final.neovimUtils.buildNeovimPlugin { + luaAttr = final.lua51Packages.tree-sitter-http; + }; + rest-nvim-dev = final.neovimUtils.buildNeovimPlugin { + luaAttr = final.lua51Packages.rest-nvim; + }; +in { + lua5_1 = prev.lua5_1.override { + packageOverrides = luaPackages-override; + }; + lua51Packages = prev.lua51Packages // final.lua5_1.pkgs; + inherit tree-sitter-http-plugin; + inherit rest-nvim-dev; +} diff --git a/nix/test-overlay.nix b/nix/test-overlay.nix index fdd0a5d..d47726a 100644 --- a/nix/test-overlay.nix +++ b/nix/test-overlay.nix @@ -1,7 +1,33 @@ { self, inputs, -}: final: prev: { +}: final: prev: let + mkNeorocksTest = name: nvim: + with final; neorocksTest { + inherit name; + pname = "rest.nvim"; + src = self; + neovim = nvim; + luaPackages = ps: + with ps; [ + nvim-nio + mimetypes + xml2lua + fidget-nvim + final.lua51Packages.tree-sitter-http + ]; + extraPackages = [ + jq + ]; + + preCheck = '' + # Neovim expects to be able to create log files, etc. + export HOME=$(realpath .) + export TREE_SITTER_HTTP_PLUGIN_DIR=${final.tree-sitter-http-plugin} + export REST_NVIM_PLUGIN_DIR=${final.rest-nvim-dev} + ''; + }; +in { docgen = final.writeShellApplication { name = "docgen"; runtimeInputs = [ @@ -14,5 +40,47 @@ vimcats lua/rest-nvim/client/curl/{cli,utils}.lua > doc/rest-nvim-client-curl.txt ''; }; - # TODO: add tests with tree-sitter-http packaged in nix + sync-readme = final.writeShellApplication { + name = "sync-readme"; + text = /* bash */ '' + set -e + + default=lua/rest-nvim/config/default.lua + + # Create a temporary file for the copied snippet + snippet=$(mktemp) + echo "1. Extract the config snippet from $default" + sed -n '/default-config:start/,/default-config:end/ { + /default-config:start/d + /default-config:end/d + p + }' "$default" > "$snippet" + + echo '2. Build new README content' + # Create a temporary file for the updated README. + tmpfile=$(mktemp) + + echo '2-1. Print all lines up to the starting marker' + sed '/default-config:start/q' README.md > "$tmpfile" + + echo '2-2. Append the new code block' + { + echo '```lua' + cat "$snippet" + echo '```' + } >> "$tmpfile" + + echo '2-3. Append the rest of the README starting from the ending marker' + sed -n '/default-config:end/,$p' README.md >> "$tmpfile" + + echo '3. Replace the old README with the new version' + mv "$tmpfile" README.md + + rm "$snippet" + + echo "README.md updated successfully." + ''; + }; + integration-stable = mkNeorocksTest "integration-stable" final.neovim; + integration-nightly = mkNeorocksTest "integration-nightly" final.neovim-nightly; } diff --git a/nix/tree-sitter-http.nix b/nix/tree-sitter-http.nix new file mode 100644 index 0000000..048b51c --- /dev/null +++ b/nix/tree-sitter-http.nix @@ -0,0 +1,33 @@ +# generated with `nix run nixpkgs#luarocks-nix -- nix tree-sitter-http` command +# NOTE: added `tree-sitter` as input +{ buildLuarocksPackage, fetchurl, fetchzip, luaOlder, luarocks-build-treesitter-parser, tree-sitter }: +buildLuarocksPackage { + pname = "tree-sitter-http"; + version = "0.0.35-1"; + knownRockspec = (fetchurl { + url = "mirror://luarocks/tree-sitter-http-0.0.35-1.rockspec"; + sha256 = "0zhirssh356lj20fyzp058iqs0ss8b39spwd12mf4n2c1h91rzh2"; + }).outPath; + src = fetchzip { + url = "https://github.com/rest-nvim/tree-sitter-http/archive/77ecf6385f1b5d422e0bbd12204374d287d61ad2.zip"; + sha256 = "018wzazajc1ma9lbd61sd6vkq11nmkhqwxjhrm7pmsf3g6sycg7x"; + }; + + disabled = luaOlder "5.1"; + nativeBuildInputs = [ luarocks-build-treesitter-parser ]; + + meta = { + homepage = "https://github.com/rest-nvim/tree-sitter-http"; + description = "tree-sitter parser for http"; + license.fullName = "UNKNOWN"; + }; + # NOTE: properties below are copied from neotest-haskell repository. + # required to successfully build tree-sitter parser + preBuild = '' + export HOME=$(mktemp -d) + ''; + buildInputs = [ + tree-sitter + ]; + propagatedBuildInputs = [luarocks-build-treesitter-parser]; +} diff --git a/rest.nvim-scm-1.rockspec b/rest.nvim-scm-1.rockspec index 8edb477..ef29fc2 100644 --- a/rest.nvim-scm-1.rockspec +++ b/rest.nvim-scm-1.rockspec @@ -25,7 +25,7 @@ dependencies = { "mimetypes", "xml2lua", "fidget.nvim", - "tree-sitter-http == 0.0.33", + "tree-sitter-http == 0.0.35", } test_dependencies = { diff --git a/spec/minimal_init.lua b/spec/minimal_init.lua index 0fc5c2a..4e5ca87 100644 --- a/spec/minimal_init.lua +++ b/spec/minimal_init.lua @@ -1,15 +1,27 @@ -local test_dir = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h") -local rest_nvim_dir = vim.fn.fnamemodify(test_dir, ":h") - --- TODO: find `LUA_LIBDIR` -vim.treesitter.language.add("http", { path = vim.fs.normalize("~/.luarocks/lib/lua/5.1/parser/http.so") }) -vim.treesitter.language.register("http", "http") -vim.treesitter.language.register("http", "rest_nvim_result") -vim.opt.runtimepath:append(rest_nvim_dir) +vim.opt.runtimepath:append(vim.env.TREE_SITTER_HTTP_PLUGIN_DIR) +vim.opt.runtimepath:append(vim.env.REST_NVIM_PLUGIN_DIR) vim.cmd("runtime! ftplugin.vim") vim.cmd("runtime! ftdetect/*.{vim,lua}") vim.cmd("runtime! filetype.lua") vim.cmd("runtime! plugin/**/*.{vim,lua}") +local clipboard = {} +local function copy(lines) + clipboard = lines +end +local function paste() + return clipboard +end +vim.g.clipboard = { + name = "bolt", + copy = { + ["+"] = copy, + ["*"] = copy, + }, + paste = { + ["+"] = paste, + ["*"] = paste, + }, +} vim.g.rest_nvim = { _log_level = vim.log.levels.INFO, request = { @@ -18,7 +30,7 @@ vim.g.rest_nvim = { }, }, cookies = { - path = "/tmp/rest-nvim.cookies", + path = vim.fn.tempname(), }, } ---@diagnostic disable-next-line: undefined-field