diff --git a/Makefile b/Makefile index 7a8e42a56..baa50f8c1 100644 --- a/Makefile +++ b/Makefile @@ -3,28 +3,23 @@ TEST_FILE?=$(realpath tests) NVIM_PATH=deps/nvim_multiversion # relative to ${NVIM_PATH} and relative to this makefile. NVIM_MASTER_PATH_REL=worktree_master -NVIM_0.7_PATH_REL=worktree_0.7 NVIM_0.9_PATH_REL=worktree_0.9 NVIM_MASTER_PATH=${NVIM_PATH}/${NVIM_MASTER_PATH_REL} -NVIM_0.7_PATH=${NVIM_PATH}/${NVIM_0.7_PATH_REL} NVIM_0.9_PATH=${NVIM_PATH}/${NVIM_0.9_PATH_REL} # directory as target. ${NVIM_PATH}: -# fetch current master and 0.7.0 (the minimum version we support) and 0.9.0 -# (the minimum version for treesitter-postfix to work). +# fetch current master and 0.9.0 (the minimum version for treesitter-postfix to +# work). git clone --bare --depth 1 https://github.com/neovim/neovim ${NVIM_PATH}; - git -C ${NVIM_PATH} fetch --depth 1 origin tag v0.7.0; git -C ${NVIM_PATH} fetch --depth 1 origin tag v0.9.0; -# create one worktree for master, and one for 0.7. -# The rationale behind this is that switching from 0.7 to master (and +# create one worktree for master, and one for 0.9. +# The rationale behind this is that switching from 0.9 to master (and # vice-versa) requires a `make distclean`, and full clean build, which takes # a lot of time. # The most straightforward solution seems to be too keep two worktrees, one -# for master, one for 0.7, and one for 0.9 which are used for the -# respective builds/tests. +# for master, and one for 0.9 which are used for the respective builds/tests. git -C ${NVIM_PATH} worktree add ${NVIM_MASTER_PATH_REL} master; - git -C ${NVIM_PATH} worktree add ${NVIM_0.7_PATH_REL} v0.7.0; git -C ${NVIM_PATH} worktree add ${NVIM_0.9_PATH_REL} v0.9.0; # |: don't update `nvim` if `${NVIM_PATH}` is changed. @@ -129,7 +124,6 @@ uninstall_jsregexp: rm -f "$(PROJECT_ROOT)/deps/luasnip-jsregexp.so"; rm -f "$(PROJECT_ROOT)/lua/luasnip-jsregexp.lua"; -TEST_07?=true TEST_09?=true TEST_MASTER?=true PREVENT_LUA_PATH_LEAK?=true @@ -148,13 +142,11 @@ test: nvim install_jsregexp export BUSTED_ARGS=--lpath=$(PROJECT_ROOT)/tests/?.lua; \ export LUASNIP_OVERRIDE_LOGPATH=$(PROJECT_ROOT); \ set -e; \ - if ${TEST_07}; then "$(MAKE)" -C ${NVIM_0.7_PATH} functionaltest DEPS_CMAKE_FLAGS=-DUSE_BUNDLED_GPERF=OFF -j; fi; \ if ${TEST_09}; then "$(MAKE)" -C ${NVIM_0.9_PATH} -j; "$(MAKE)" -C ${NVIM_0.9_PATH} functionaltest -j; fi; \ if ${TEST_MASTER}; then unset BUSTED_ARGS; "$(MAKE)" -C ${NVIM_MASTER_PATH} -j; ./tests/test_master.sh; fi; test_nix: nvim install_jsregexp set -e; \ - if ${TEST_07}; then nix develop .#test_nvim_07 -c make test; fi; \ if ${TEST_09}; then nix develop .#test_nvim_09 -c make test; fi; \ if ${TEST_MASTER}; then nix develop .#test_nvim_master -c make test; fi; @@ -180,7 +172,7 @@ doc: # solution because indentation is identical for lists. emmylua_doc_cli -f json -i lua/luasnip/ -o ./; luals-mdgen data/DOC-template.md DOC.md --width 80 --mode vimdoc; - panvimdoc --project-name luasnip --input-file DOC.md --vim-version "NeoVim 0.7-0.11" --doc-mapping true; + panvimdoc --project-name luasnip --input-file DOC.md --vim-version "NeoVim 0.9-0.11" --doc-mapping true; nvim --clean -es +"helptags doc | exit"; # again, this time without vimdoc, overwrite previous DOC.md. luals-mdgen data/DOC-template.md DOC.md --width 100; diff --git a/README.md b/README.md index 6e2943cfb..4c0f0de07 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ https://user-images.githubusercontent.com/41961280/122515860-5179fa00-d00e-11eb- - Snippets that make use of the entire functionality of this plugin have to be defined in Lua (but 95% of snippets can be written in LSP-syntax). # Requirements -Neovim >= 0.7 (extmarks) +Neovim >= 0.9 `jsregexp` for `lsp-snippet-transformations` (see [here](https://github.com/L3MON4D3/LuaSnip/blob/master/DOC.md#transformations) for some tips on installing it). # Setup diff --git a/doc/luasnip.txt b/doc/luasnip.txt index c994870ed..fc0239ff1 100644 --- a/doc/luasnip.txt +++ b/doc/luasnip.txt @@ -1,4 +1,4 @@ -*luasnip.txt* For NeoVim 0.7-0.11 Last change: 2026 May 19 +*luasnip.txt* For NeoVim 0.9-0.11 Last change: 2026 May 19 ============================================================================== Table of Contents *luasnip-table-of-contents* diff --git a/flake.lock b/flake.lock index 3a9bdd4c1..f76ab055a 100644 --- a/flake.lock +++ b/flake.lock @@ -168,21 +168,6 @@ } }, "flake-utils_4": { - "locked": { - "lastModified": 1644229661, - "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "flake-utils_5": { "locked": { "lastModified": 1667395993, "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", @@ -197,7 +182,7 @@ "type": "github" } }, - "flake-utils_6": { + "flake-utils_5": { "inputs": { "systems": "systems_4" }, @@ -416,22 +401,6 @@ } }, "nixpkgs_5": { - "locked": { - "lastModified": 1646254136, - "narHash": "sha256-8nQx02tTzgYO21BP/dy5BCRopE8OwE8Drsw98j+Qoaw=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "3e072546ea98db00c2364b81491b893673267827", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" - } - }, - "nixpkgs_6": { "locked": { "lastModified": 1671983799, "narHash": "sha256-Z2Ro6hFPZHkBqkVXY5/aBUzxi5xizQGvuHQ9+T5B/ks=", @@ -447,7 +416,7 @@ "type": "github" } }, - "nixpkgs_7": { + "nixpkgs_6": { "locked": { "lastModified": 1745377448, "narHash": "sha256-jhZDfXVKdD7TSEGgzFJQvEEZ2K65UMiqW5YJ2aIqxMA=", @@ -475,33 +444,11 @@ "url": "https://raw.githubusercontent.com/mfussenegger/nlua/8a2d76043d94ed4130ae703f13f393bb9132d259/nlua" } }, - "nvim_07": { + "nvim_09": { "inputs": { "flake-utils": "flake-utils_4", "nixpkgs": "nixpkgs_5" }, - "locked": { - "dir": "contrib", - "lastModified": 1650022724, - "narHash": "sha256-eYYaHpfSaYYrLkcD81Y4rsAMYDP1IJ7fLJJepkACkA8=", - "owner": "neovim", - "repo": "neovim", - "rev": "333ba6569d833e22c0d291547d740d4bbfa3fdab", - "type": "github" - }, - "original": { - "dir": "contrib", - "owner": "neovim", - "ref": "v0.7.0", - "repo": "neovim", - "type": "github" - } - }, - "nvim_09": { - "inputs": { - "flake-utils": "flake-utils_5", - "nixpkgs": "nixpkgs_6" - }, "locked": { "dir": "contrib", "lastModified": 1680866789, @@ -526,7 +473,7 @@ "git-hooks": "git-hooks", "hercules-ci-effects": "hercules-ci-effects", "neovim-src": "neovim-src", - "nixpkgs": "nixpkgs_7", + "nixpkgs": "nixpkgs_6", "treefmt-nix": "treefmt-nix" }, "locked": { @@ -545,7 +492,7 @@ }, "panvimdoc": { "inputs": { - "flake-utils": "flake-utils_6", + "flake-utils": "flake-utils_5", "nixpkgs-unstable": "nixpkgs-unstable" }, "locked": { @@ -568,7 +515,6 @@ "luals-mdgen": "luals-mdgen", "nixpkgs": "nixpkgs_4", "nixpkgs-treesitter": "nixpkgs-treesitter", - "nvim_07": "nvim_07", "nvim_09": "nvim_09", "nvim_master": "nvim_master", "panvimdoc": "panvimdoc" diff --git a/flake.nix b/flake.nix index 79f1415b9..f32ff9bae 100644 --- a/flake.nix +++ b/flake.nix @@ -6,8 +6,6 @@ # has tree-sitter 0.20.8, which is required for neovim 0.9.0. inputs.nixpkgs-treesitter.url = "github:nixos/nixpkgs/7a339d87931bba829f68e94621536cad9132971a"; - inputs.nvim_07.url = "github:neovim/neovim/v0.7.0?dir=contrib"; - inputs.nvim_09.url = "github:neovim/neovim/v0.9.0?dir=contrib"; # this only has to be updated sporadically, basically whenever the source in @@ -21,7 +19,6 @@ self, nixpkgs, nixpkgs-treesitter, - nvim_07, nvim_09, nvim_master, luals-mdgen, @@ -34,7 +31,6 @@ pkgs = import nixpkgs { inherit system; }; pkgs-treesitter = import nixpkgs-treesitter { inherit system; }; pkgs-nvim_09 = import nvim_09.inputs.nixpkgs { inherit system; }; - pkgs-nvim_07 = import nvim_07.inputs.nixpkgs { inherit system; }; pkg-luals-mdgen = luals-mdgen.outputs.packages.${system}.default; pkg-emmylua-doc = emmylua-analyzer-rust.outputs.packages.${system}.emmylua_doc_cli; pkg-panvimdoc = panvimdoc.outputs.packages.${system}.default; @@ -45,7 +41,6 @@ pkgs, pkgs-treesitter, pkgs-nvim_09, - pkgs-nvim_07, pkg-luals-mdgen, pkg-emmylua-doc, pkg-panvimdoc @@ -71,34 +66,9 @@ pkgs.neovim ]; }; - # clang stdenv does not build, and it's used by de. - test_nvim_07 = (nvim_07.outputs.devShell.${pkgs.system}.override { stdenv = pkgs-nvim_07.gccStdenv; }).overrideAttrs(attrs: { - TEST_07=true_bin; - TEST_09=false_bin; - TEST_MASTER=false_bin; - - # when using bundled dependencies, there are issues with luarocks :/ - # don't need to build treesitter-parsers, so we can just set this. - USE_BUNDLED="OFF"; - - LUA_PATH=""; - LUA_CPATH=""; - PREVENT_LUA_PATH_LEAK=false_bin; - # ASAN does not work with gcc stdenv. - cmakeFlags = builtins.filter (x: x != "-DCLANG_ASAN_UBSAN=ON") attrs.cmakeFlags; - - # adjust some paths. - # We're not running the devshell from the directory it expects. - shellHook = '' - cd ./deps/nvim_multiversion/worktree_0.7 - cmakeConfigurePhase - cd ../../../../ - ''; - }); # override default tree-sitter, it has the wrong version (0.20.7 vs required 0.20.8). test_nvim_09 = default_09_devshell.overrideAttrs(attrs: { - TEST_07=false_bin; TEST_09=true_bin; TEST_MASTER=false_bin; @@ -124,7 +94,6 @@ }); test_nvim_master = nvim_master.outputs.devShells.${pkgs.system}.default.overrideAttrs(attrs: { - TEST_07=false_bin; TEST_09=false_bin; TEST_MASTER=true_bin; diff --git a/lua/luasnip/extras/_treesitter.lua b/lua/luasnip/extras/_treesitter.lua index ac735566d..b43769997 100644 --- a/lua/luasnip/extras/_treesitter.lua +++ b/lua/luasnip/extras/_treesitter.lua @@ -2,7 +2,7 @@ local util = require("luasnip.util.util") local tbl = require("luasnip.util.table") local function get_lang(bufnr) - local ft = vim.api.nvim_buf_get_option(bufnr, "ft") + local ft = vim.api.nvim_get_option_value("ft", { buf = bufnr }) local lang = vim.treesitter.language.get_lang(ft) or ft return lang end @@ -317,7 +317,7 @@ end ---@param pos { [1]: number, [2]: number }? ---@return TSNode? function TSParser:get_node_at_pos(pos) - pos = vim.F.if_nil(pos, util.get_cursor_0ind()) + pos = util.if_nil(pos, util.get_cursor_0ind()) local row, col = pos[1], pos[2] assert( row >= 0 and col >= 0, @@ -436,7 +436,7 @@ local function find_topmost_parent(root, matcher) if matcher == nil or matcher(node) then current = node end - return vim.F.if_nil(_impl(node:parent()), current) + return util.if_nil(_impl(node:parent()), current) end return _impl(root) diff --git a/lua/luasnip/extras/filetype_functions.lua b/lua/luasnip/extras/filetype_functions.lua index 0ebcbb932..dd47096c8 100644 --- a/lua/luasnip/extras/filetype_functions.lua +++ b/lua/luasnip/extras/filetype_functions.lua @@ -47,7 +47,11 @@ local function from_pos_or_filetype() end local function from_filetype_load(bufnr) - return vim.split(vim.api.nvim_buf_get_option(bufnr, "filetype"), ".", true) + return vim.split( + vim.api.nvim_get_option_value("filetype", { buf = bufnr }), + ".", + true + ) end local function extend_load_ft(extend_fts) @@ -67,8 +71,11 @@ local function extend_load_ft(extend_fts) end return function(bufnr) - local fts = - vim.split(vim.api.nvim_buf_get_option(bufnr, "filetype"), ".", true) + local fts = vim.split( + vim.api.nvim_get_option_value("filetype", { buf = bufnr }), + ".", + true + ) local res = {} for _, ft in ipairs(fts) do diff --git a/lua/luasnip/extras/snippet_list.lua b/lua/luasnip/extras/snippet_list.lua index 818714bc6..6985af240 100644 --- a/lua/luasnip/extras/snippet_list.lua +++ b/lua/luasnip/extras/snippet_list.lua @@ -20,13 +20,13 @@ local buf_opts = { filetype = "lua" } local function set_win_opts(win, opts) for opt, val in pairs(opts) do - vim.api.nvim_win_set_option(win, opt, val) + vim.api.nvim_set_option_value(opt, val, { win = win }) end end local function set_buf_opts(buf, opts) for opt, val in pairs(opts) do - vim.api.nvim_buf_set_option(buf, opt, val) + vim.api.nvim_set_option_value(opt, val, { buf = buf }) end end @@ -73,7 +73,7 @@ local function display_split(opts) vim.api.nvim_buf_set_lines(buf, 0, 0, false, replacement) -- make it unmodifiable at this point - vim.api.nvim_buf_set_option(buf, "modifiable", false) + vim.api.nvim_set_option_value("modifiable", false, { buf = buf }) end end diff --git a/lua/luasnip/init.lua b/lua/luasnip/init.lua index 734c84b51..2d1d13285 100644 --- a/lua/luasnip/init.lua +++ b/lua/luasnip/init.lua @@ -2,7 +2,6 @@ local util = require("luasnip.util.util") local lazy_table = require("luasnip.util.lazy_table") local types = require("luasnip.util.types") local node_util = require("luasnip.nodes.util") -local tbl_util = require("luasnip.util.table") local feedkeys = require("luasnip.util.feedkeys") local session = require("luasnip.session") @@ -598,7 +597,7 @@ local function _snip_expand(snippet, opts) -- override with current position if none given. opts.pos = opts.pos or util.get_cursor_0ind() opts.jump_into_func = opts.jump_into_func or _jump_into_default - opts.indent = vim.F.if_nil(opts.indent, true) + opts.indent = util.if_nil(opts.indent, true) snip.trigger = opts.expand_params.trigger or snip.trigger snip.captures = opts.expand_params.captures or {} @@ -1309,8 +1308,8 @@ end function API.activate_node(opts) opts = opts or {} local pos = opts.pos or util.get_cursor_0ind() - local strict = vim.F.if_nil(opts.strict, false) - local select = vim.F.if_nil(opts.select, true) + local strict = util.if_nil(opts.strict, false) + local select = util.if_nil(opts.select, true) -- find tree-node the snippet should be inserted at (could be before another node). local _, _, _, node = node_util.snippettree_find_undamaged_node(pos, { diff --git a/lua/luasnip/loaders/from_vscode.lua b/lua/luasnip/loaders/from_vscode.lua index 8d85c0b1a..4a25bd362 100644 --- a/lua/luasnip/loaders/from_vscode.lua +++ b/lua/luasnip/loaders/from_vscode.lua @@ -598,10 +598,10 @@ end function M.load_standalone(opts) opts = opts or {} - local lazy = vim.F.if_nil(opts.lazy, false) + local lazy = util.if_nil(opts.lazy, false) local add_opts = loader_util.make_add_opts(opts) local fs_event_providers = - vim.F.if_nil(opts.fs_event_providers, { autocmd = true, libuv = false }) + util.if_nil(opts.fs_event_providers, { autocmd = true, libuv = false }) local path if not lazy then diff --git a/lua/luasnip/loaders/fs_watchers.lua b/lua/luasnip/loaders/fs_watchers.lua index dca63dddc..b949020b3 100644 --- a/lua/luasnip/loaders/fs_watchers.lua +++ b/lua/luasnip/loaders/fs_watchers.lua @@ -49,9 +49,9 @@ local callback_mt = { local function get_opts(opts) opts = opts or {} - local lazy = vim.F.if_nil(opts.lazy, false) + local lazy = util.if_nil(opts.lazy, false) local fs_event_providers = - vim.F.if_nil(opts.fs_event_providers, { autocmd = true, libuv = false }) + util.if_nil(opts.fs_event_providers, { autocmd = true, libuv = false }) return lazy, fs_event_providers end diff --git a/lua/luasnip/loaders/util.lua b/lua/luasnip/loaders/util.lua index 4c0156071..415a383bb 100644 --- a/lua/luasnip/loaders/util.lua +++ b/lua/luasnip/loaders/util.lua @@ -274,7 +274,7 @@ local function normalize_opts(opts) end local fs_event_providers = - vim.F.if_nil(opts.fs_event_providers, { autocmd = true, libuv = false }) + util.if_nil(opts.fs_event_providers, { autocmd = true, libuv = false }) return { paths = paths, diff --git a/lua/luasnip/nodes/snippet.lua b/lua/luasnip/nodes/snippet.lua index b293eafd8..8bffaa2ba 100644 --- a/lua/luasnip/nodes/snippet.lua +++ b/lua/luasnip/nodes/snippet.lua @@ -1212,7 +1212,7 @@ function Snippet:event(event, event_args) modeline = false, }) - return vim.F.if_nil(cb_res, m1_cb_res, parent_cb_res) + return util.if_nil(cb_res, m1_cb_res, parent_cb_res) end local function nodes_from_pattern(pattern) diff --git a/lua/luasnip/util/auto_table.lua b/lua/luasnip/util/auto_table.lua index 3a9858c0c..94dd5c90b 100644 --- a/lua/luasnip/util/auto_table.lua +++ b/lua/luasnip/util/auto_table.lua @@ -35,9 +35,10 @@ end local M = {} +local if_nil = vim.nonnil or vim.F.if_nil --todo(clason): remove when dropping Nvim 0.12 support function M.autotable(max_depth, opts) opts = opts or {} - local warn = vim.F.if_nil(opts.warn, false) + local warn = if_nil(opts.warn, false) local auto_table_func = warn and auto_creating_tables_warn_depth or auto_creating_tables diff --git a/lua/luasnip/util/functions.lua b/lua/luasnip/util/functions.lua index 3fc1ad7db..540561aab 100644 --- a/lua/luasnip/util/functions.lua +++ b/lua/luasnip/util/functions.lua @@ -36,7 +36,10 @@ return { return sn(nil, { t( vim.split( - vim.api.nvim_exec("echo " .. vimstring, true), + vim.api.nvim_exec2( + "echo " .. vimstring, + { output = true } + ).output, "\n" ) ), diff --git a/lua/luasnip/util/log.lua b/lua/luasnip/util/log.lua index 5692d8f83..a648be068 100644 --- a/lua/luasnip/util/log.lua +++ b/lua/luasnip/util/log.lua @@ -1,11 +1,7 @@ local util = require("luasnip.util.util") local tbl = require("luasnip.util.table") --- older neovim-versions (even 0.7.2) do not have stdpath("log"). -local logpath_ok, logpath = pcall(vim.fn.stdpath, "log") -if not logpath_ok then - logpath = vim.fn.stdpath("cache") -end +logpath = vim.fn.stdpath("log") local override_logpath = os.getenv("LUASNIP_OVERRIDE_LOGPATH") if override_logpath then diff --git a/lua/luasnip/util/util.lua b/lua/luasnip/util/util.lua index 7f4d20bd5..8cdd6f3f5 100644 --- a/lua/luasnip/util/util.lua +++ b/lua/luasnip/util/util.lua @@ -516,4 +516,5 @@ return { pos_from_offset = pos_from_offset, shallow_copy = shallow_copy, copy3 = copy3, + if_nil = vim.nonnil or vim.F.if_nil, --todo(clason): remove when dropping Nvim 0.12 support } diff --git a/tests/integration/session_spec.lua b/tests/integration/session_spec.lua index 3a73474ac..a9ec7a2d4 100644 --- a/tests/integration/session_spec.lua +++ b/tests/integration/session_spec.lua @@ -381,15 +381,8 @@ describe("session", function() -- delete whole buffer. feed("ggVGd") -- another jump should not cause an error. - -- for some reason this hangs indefinitely on nvim0.7, but not 0.9 or master. - -- I assume that something is just weird in the test-suite (why would - -- this fail only here specifically (IIRC there are enough tests that - -- do something similar)), and since it's fine on 0.9 and master (which - -- matter much more) there shouldn't be an issue in practice. exec_lua([[ - if require("luasnip.util.vimversion").ge(0,8,0) then - ls.jump(1) - end + ls.jump(1) ]]) end) it("Deleting nested snippet only removes it.", function()