Skip to content

Commit

Permalink
Use getwininfo() instead of FFI to get gutter width in Nvim 0.6
Browse files Browse the repository at this point in the history
It is no longer necessary to rely on an Nvim internal C function.
  • Loading branch information
zeertzjq committed Dec 4, 2021
1 parent e1f54e1 commit e8f8266
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lua/treesitter-context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@ local defaultConfig = {

local config = {}

local ffi = require("ffi")
ffi.cdef'int curwin_col_off(void);'
local has_textoff = vim.fn.has('nvim-0.6')

local ffi = nil
if not has_textoff then
ffi = require("ffi")
ffi.cdef'int curwin_col_off(void);'
end

-- Constants

Expand Down Expand Up @@ -189,7 +194,11 @@ local get_indents = function(lines)
end

local get_gutter_width = function()
return ffi.C.curwin_col_off();
if not has_textoff then
return ffi.C.curwin_col_off();
else
return vim.fn.getwininfo(vim.api.nvim_get_current_win())[1].textoff
end
end

local nvim_augroup = function(group_name, definitions)
Expand Down

0 comments on commit e8f8266

Please sign in to comment.