Neovim indentation bug with more than one |> on a line (keeps wrongly adding another indentation)

I’m using Neovim with an nvim-treesitter plugin for elixir configured as follows:

      build = ":TSUpdate",
      config = function () 
        local configs = require("nvim-treesitter.configs")

            ensure_installed = { "python", "c", "lua", "vim", "vimdoc", 
              "query", "erlang", "heex", "eex", "elixir", "javascript", "html" },
            sync_install = false,
            highlight = { enable = true },
            indent = { enable = true },  

So basically elixir is in there. But as you can see from this short asciinema quite often when I add another pipe |> on a line where it already exists, the whole line gets indented more, which obviously I don’t want.

There are some other “bugs” (?) where it will indent a pipe sometimes wrongly by two places under a variable, or will sometimes completely unindent a line with pipes in it.

Has anyone experienced this and is there a fix? Any ideas on which neovim plugin combinations work best? For guide my whole init.lua is here

I admit I’m not the most familiar with the vim ecosystem but shouldn’t it just be relying on the official formatter for this sort of thing?

I use both. The Elixir formatter is too slow to run in real time but it drives me nuts if stuff doesn’t look at least somewhat properly formatted as I type. So the editor does a decent job formatting on the go and the formatter brings it home. After a past convo on this board, though, I realized that there are very different types of people when it comes to how much they care about this :slight_smile:

I do manual formatting now with lexical and it sucks, if it does something else the formatter always times out. Honestly I wished I had the knowledge and patience to configure this properly.

With AstroNvim it’s more or less 2-3 Lua lines btw. And with many more VIM variants you kind of just have to put the right config at the right place and it just works.

I noticed a bunch of indentation issues when I briefly tested it out, esp around case → indenting and multi-line list construction. I’ve mostly been sucking into configuring Neovim, rather than using it, to date.

I did try playing around with a Treesitter query at one stage and while I know little about this, it seemed like Treesitter just didn’t have enough information to correctly indent code in all situations.

FWIW, I’m also noticing issues with Treesitter based Lua indenting, even on basic indenting situations.

I haven’t yet had a chance to come back to investigate this further (ref my comment about config :).

I have these notes in my Treesitter config:

      highlight = {
        enable = true,
        -- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules.
        -- If you are experiencing weird indenting issues, add the language to
        -- the list of additional_vim_regex_highlighting and disabled languages for indent.
        additional_vim_regex_highlighting = { "ruby", "elixir" },
      indent = {
        enable = true,
        disable = { "ruby", "elixir" },

This came from kickstart.nvim. I added the elixir entries, but haven’t tried it out yet, so don’t know if this helps or makes things worse. I suspect it will makes things worse, since I don’t see any built in Elixir syntax file.

I will also add that I’m not using the elixir-tools plugin. A quick scan of that doesn’t suggest it would help with indentation.

Finally, I will add make sure you’re using 0.10.0. There were changes to the Elixir ftplugin between 0.9.0 and 0.10.0 that do help. If you can’t upgrade, you can try patching your local file. Check here for the latest file content.

What I was doing when I briefly tested Elixir code, was to just periodically run vim.lsp.buf.format({ async = true }). It wasn’t ideal, but worked.

1 Like

@vegabook can you share the output of set indentkeys in nvim?