diff options
author | David Lukes <dafydd.lukes@gmail.com> | 2020-05-05 17:23:45 +0200 |
---|---|---|
committer | David Lukes <dafydd.lukes@gmail.com> | 2020-06-22 09:48:41 +0200 |
commit | ebee9ebe2be2bd584efefc4064a8b3a07e0505e0 (patch) | |
tree | 54fe1520a078341c073c20c8c5b4e28404cbac59 /runtime/lua/vim/lsp/util.lua | |
parent | 4496628c181e456d57e9257e14d8582d8dc548eb (diff) | |
download | rneovim-ebee9ebe2be2bd584efefc4064a8b3a07e0505e0.tar.gz rneovim-ebee9ebe2be2bd584efefc4064a8b3a07e0505e0.tar.bz2 rneovim-ebee9ebe2be2bd584efefc4064a8b3a07e0505e0.zip |
lsp: Add sync variant of LSP formatting
Also, factor out a `vim.lsp.util.get_effective_tabstop()` helper and add
tests for it.
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index 71ca1048e1..2b9b4d8c7e 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -1259,6 +1259,30 @@ function M.make_text_document_params() return { uri = vim.uri_from_bufnr(0) } end +--- Get visual width of tabstop. +--- +--@see |softtabstop| +--@param bufnr (optional, number): Buffer handle, defaults to current +--@returns (number) tabstop visual width +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 +end + +function M.make_formatting_params(options) + validate { options = {options, 't', true} } + options = vim.tbl_extend('keep', options or {}, { + tabSize = M.get_effective_tabstop(); + insertSpaces = vim.bo.expandtab; + }) + return { + textDocument = { uri = vim.uri_from_bufnr(0) }; + options = options; + } +end + -- @param buf buffer handle or 0 for current. -- @param row 0-indexed line -- @param col 0-indexed byte offset in line |