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.
This commit is contained in:
parent
2572c5d093
commit
5d5b068d5b
|
@ -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, '<'))
|
||||
|
|
Loading…
Reference in New Issue