Darazaki / indent-o-matic

Dumb automatic fast indentation detection for Neovim written in Lua
MIT License
176 stars 13 forks source link

Piped Neovim returning `nil` for `line` in `detect()` #22

Closed thehunmonkgroup closed 1 year ago

thehunmonkgroup commented 1 year ago

https://github.com/Darazaki/indent-o-matic/blob/master/lua/indent-o-matic.lua#L172 assumes that line is a table.

However, I'm seeing instances when Neovim is opened via a pipe (in my case via vipe) that https://github.com/Darazaki/indent-o-matic/blob/master/lua/indent-o-matic.lua#L31-L33 returns true, nil, and in this case it's throwing an index error at https://github.com/Darazaki/indent-o-matic/blob/master/lua/indent-o-matic.lua#L172

I'm not sure if this is a bug in vim.api.nvim_buf_get_lines() or something peculiar to running Neovim through pipes, but changing https://github.com/Darazaki/indent-o-matic/blob/master/lua/indent-o-matic.lua#L172 to this:

if not line or #line == 0 then

Fixes the issue for me.

This change will not affect the existing logic, and seems reasonable defensive programming, especially given the issue I'm addressing.

zackproser commented 1 year ago

@thehunmonkgroup thanks for leaving this breadcrumb - can confirm I had the same issue and that your proposed fix also appears to have resolved the issue for me.