Skip to content

Commit 5daed6c

Browse files
authored
format: Use current settings for formatting (#59)
Instead of hard-coding default values, use the current settings to determine the options to pass the language server for the textDocument/formatting call. Also pass values for `trimTrailingWhitespace` and `insertFinalNewline` because micro has settings for those too.
1 parent eca75da commit 5daed6c

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

main.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,9 +768,10 @@ function formatAction(bp, callback)
768768
if cmd[filetype] == nil then return; end
769769
local send = withSend(filetype)
770770
local file = bp.Buf.AbsPath
771+
local cfg = bp.Buf.Settings
771772

772773
currentAction[filetype] = { method = "textDocument/formatting", response = formatActionResponse(callback) }
773-
send(currentAction[filetype].method, fmt.Sprintf('{"textDocument": {"uri": "file://%s"}, "options": {"tabSize": 4, "insertSpaces": true}}', file))
774+
send(currentAction[filetype].method, fmt.Sprintf('{"textDocument": {"uri": "file://%s"}, "options": {"tabSize": %.0f, "insertSpaces": %t, "trimTrailingWhitespace": %t, "insertFinalNewline": %t}}', file, cfg["tabsize"], cfg["tabstospaces"], cfg["rmtrailingws"], cfg["eofnewline"]))
774775
end
775776

776777
function formatActionResponse(callback)

0 commit comments

Comments
 (0)