How to handle LSPs producing undesirable indentations?

I am coding in R in nvim and having some difficulty with the way the indentations are turning out.

I have my indentation configured as:

opt.tabstop=2

opt.shiftwidth=2

opt.expandtab=true

And when I do =G, I get the following result (image), which is too many indents. Is this my R LSP messing things up, or do I not understand tabstop, shiftwidth and expandtab actually do?

How can I make it so that I don’t 8 indents when I only want two. What am I doing wrong?

The output of :verbose set shiftwidth is

shiftwidth=2

Last set from Lua

And

:verbose set indentexpr?

says

indentexpr=GetRIndent()
 Last set from /usr/share/nvim/runtime/indent/r.vim line 15

and :verbose set equalprg?

says

equalprg=

I think I have an idea of where my issues are. And there is a good chance I am wrong about this being the Nvim/vim R-LSP. The LSP itself is here : GitHub - REditorSupport/languageserver: An implementation of the Language Server Protocol for R.

  1. Would hacking the lsp config cause issues down the line? With something like updates from the upstream?

If yes,

  1. Can I use something else to make the indents uniform? Whenever I copy paste something from other places, nvim just prints them out of whack. If = is not the answer then I am happy to use something else.

In case you haven’t already resolved this, the issue is that the LSP’s indentation model is aligning parameters to the open paren in list(. This is a pretty common formatter operation, and has nothing to do with your nvim indent settings because the formatter’s behavior takes precedence. You’ll need to look at passing settings to the formatter in question to see if you can override function/paren alignment. This appears to be the relevant section of your LSPs documentation to start with.

Like the output from set indentexpr shows, the default R ftplugin is setting that indentation. To override, put settings in after/indent/R.lua. See this SO answer for more.