aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/lsp/util.lua
diff options
context:
space:
mode:
authorHirokazu Hata <h.hata.ai.t@gmail.com>2020-06-27 11:27:51 +0900
committerGitHub <noreply@github.com>2020-06-27 11:27:51 +0900
commit7efb302d26abd863e2cbbf4d2d6f7bb4aa31cc29 (patch)
tree249ccd0759e4d61bdaea99f27e4e1c4ae965bbdc /runtime/lua/vim/lsp/util.lua
parent225f0bcd98dd8ff8cab964f13816dfdf327038ae (diff)
parentebee9ebe2be2bd584efefc4064a8b3a07e0505e0 (diff)
downloadrneovim-7efb302d26abd863e2cbbf4d2d6f7bb4aa31cc29.tar.gz
rneovim-7efb302d26abd863e2cbbf4d2d6f7bb4aa31cc29.tar.bz2
rneovim-7efb302d26abd863e2cbbf4d2d6f7bb4aa31cc29.zip
Merge pull request #12252 from dlukes/formatting-sync
Diffstat (limited to 'runtime/lua/vim/lsp/util.lua')
-rw-r--r--runtime/lua/vim/lsp/util.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 0f366c2b57..4176255eb6 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -1260,6 +1260,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