From af427dedf663b1987fa54c5f885409ad51824a20 Mon Sep 17 00:00:00 2001 From: Tim Pope Date: Sun, 20 Mar 2022 13:41:46 -0400 Subject: fix(lsp): set tabSize from 'shiftwidth', not 'softtabstop' (#17787) The use of 'softtabstop' to set tabSize was introduced in 5d5b068, replacing 'tabstop'. If we look past the name tabSize and at the actual purpose of the field, it's the indentation width used when formatting. This corresponds to the Vim option 'shiftwidth', not 'softtabstop'. The latter has the comparatively mundane purpose of controlling what happens when you hit the tab key (and even this is incomplete, as it fails to account for 'smarttab'). --- runtime/lua/vim/lsp/util.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'runtime/lua') diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 59ab3d7e1f..cec3891418 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -1894,16 +1894,16 @@ end function M.make_workspace_params(added, removed) return { event = { added = added; removed = removed; } } end ---- Returns visual width of tabstop. +--- Returns indentation size. --- ----@see |softtabstop| +---@see |shiftwidth| ---@param bufnr (optional, number): Buffer handle, defaults to current ----@returns (number) tabstop visual width +---@returns (number) indentation size function M.get_effective_tabstop(bufnr) validate { bufnr = {bufnr, 'n', true} } local bo = bufnr and vim.bo[bufnr] or vim.bo - local sts = bo.softtabstop - return (sts > 0 and sts) or (sts < 0 and bo.shiftwidth) or bo.tabstop + local sw = bo.shiftwidth + return (sw == 0 and bo.tabstop) or sw end --- Creates a `DocumentFormattingParams` object for the current buffer and cursor position. -- cgit