From 99ef854322d0de9269044ee197b6c9ca14911d96 Mon Sep 17 00:00:00 2001 From: AF <33097027+f3fora@users.noreply.github.com> Date: Tue, 11 Oct 2022 02:16:58 +0200 Subject: [PATCH] fix(context): compatibility with nvim<0.8 (#1224) `get_captures_at_position` has been renamed to `get_captures_at_pos`: neovim/neovim#20331. Fallback to `get_captures_at_position` in case `get_captures_at_pos` is `nil`. --- lua/cmp/config/context.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lua/cmp/config/context.lua b/lua/cmp/config/context.lua index 0af271a..f7a1ac4 100644 --- a/lua/cmp/config/context.lua +++ b/lua/cmp/config/context.lua @@ -33,9 +33,13 @@ context.in_treesitter_capture = function(capture) col = col - 1 end + local get_captures_at_pos = -- See neovim/neovim#20331 + require('vim.treesitter').get_captures_at_pos -- for neovim >= 0.8 + or require('vim.treesitter').get_captures_at_position -- for neovim < 0.8 + local captures_at_cursor = vim.tbl_map(function(x) return x.capture - end, require('vim.treesitter').get_captures_at_pos(buf, row, col)) + end, get_captures_at_pos(buf, row, col)) if vim.tbl_isempty(captures_at_cursor) then return false