diff options
author | Jesse-Bakker <jessebakker00@gmail.com> | 2020-02-11 07:53:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-10 22:53:14 -0800 |
commit | 5d5b068d5bdd2fe3787eb619097a5af08ef929e2 (patch) | |
tree | 11fba89bae180607e0742b99028154c1a57e73e4 | |
parent | 2572c5d0936ab632733c08030237967252f632af (diff) | |
download | rneovim-5d5b068d5bdd2fe3787eb619097a5af08ef929e2.tar.gz rneovim-5d5b068d5bdd2fe3787eb619097a5af08ef929e2.tar.bz2 rneovim-5d5b068d5bdd2fe3787eb619097a5af08ef929e2.zip |
LSP: Refine formatting tabSize #11834
Use the logic explained in the softtabstop help section for defining
the tabSize parameter in formatting requests. This means that:
- if softtabstop is 0, tabstop is used
- if softtabstop < 0, shiftwidth is used
- if softtabstop > 0, softtabstop is used
When inserting spaces instead of tabs, softtabstop is used in vim.
Therefor it would be more logical to use it when formatting instead
of the current tabstop.
-rw-r--r-- | runtime/lua/vim/lsp/buf.lua | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua index a6a05fb095..19deb5df45 100644 --- a/runtime/lua/vim/lsp/buf.lua +++ b/runtime/lua/vim/lsp/buf.lua @@ -68,8 +68,9 @@ end function M.formatting(options) validate { options = {options, 't', true} } + local sts = vim.bo.softtabstop; options = vim.tbl_extend('keep', options or {}, { - tabSize = vim.bo.tabstop; + tabSize = (sts > 0 and sts) or (sts < 0 and vim.bo.shiftwidth) or vim.bo.tabstop; insertSpaces = vim.bo.expandtab; }) local params = { @@ -85,8 +86,9 @@ function M.range_formatting(options, start_pos, end_pos) start_pos = {start_pos, 't', true}; end_pos = {end_pos, 't', true}; } + local sts = vim.bo.softtabstop; options = vim.tbl_extend('keep', options or {}, { - tabSize = vim.bo.tabstop; + tabSize = (sts > 0 and sts) or (sts < 0 and vim.bo.shiftwidth) or vim.bo.tabstop; insertSpaces = vim.bo.expandtab; }) local A = list_extend({}, start_pos or api.nvim_buf_get_mark(0, '<')) |