Skip to content

Commit

Permalink
Switch to conform for formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
krmbzds committed Sep 30, 2023
1 parent c2de93f commit fba3bf2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lua/config/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ end

-- Commands

-- Format
api.nvim_create_user_command("Format", function(args)
local range = nil
if args.count ~= -1 then
local end_line = vim.api.nvim_buf_get_lines(0, args.line2 - 1, args.line2, true)[1]
range = {
start = { args.line1, 0 },
["end"] = { args.line2, end_line:len() },
}
end
require("conform").format({ async = true, lsp_fallback = true, range = range })
end, { range = true })

-- Search cursor line
api.nvim_create_user_command("GrepAppCursorLine", function()
grep_app(cursorline(), "Cursor line empty")
Expand Down
20 changes: 20 additions & 0 deletions lua/config/plugins/conform.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
local M = {
"stevearc/conform.nvim",
opts = {},
}

function M.config()
local status_ok, conform = pcall(require, "conform")
if not status_ok then
return
end

conform.setup({
formatters_by_ft = {
lua = { "stylua" },
ruby = { "standardrb" },
},
})
end

return M
2 changes: 1 addition & 1 deletion lua/config/plugins/which-key.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ function M.config()
A = { "<cmd>lua vim.lsp.codelens.run()<cr>", "CodeLens Action" },
d = { "<cmd>Telescope diagnostics bufnr=0 theme=ivy<cr>", "Buffer Diagnostics" },
D = { "<cmd>Telescope diagnostics<cr>", "Diagnostics" },
f = { "<cmd>lua vim.lsp.buf.format { async = true }<cr>", "Format" },
f = { "<cmd>Format<cr>", "Format" },
q = { "<cmd>lua vim.diagnostic.setloclist()<cr>", "Quickfix" },
r = { "<cmd>lua vim.lsp.buf.rename()<cr>", "Rename" },
s = { "<cmd>Telescope lsp_document_symbols<cr>", "Document Symbols" },
Expand Down

0 comments on commit fba3bf2

Please sign in to comment.