added conform

This commit is contained in:
Oliver Hartmann 2025-04-04 13:36:50 +00:00
parent e1ade38e04
commit 8966af7289
3 changed files with 27 additions and 50 deletions

27
lua/plugins/conform.lua Normal file
View File

@ -0,0 +1,27 @@
return {
'stevearc/conform.nvim',
cmd = { 'ConformInfo' },
opts = {
default_format_opts = {
lsp_format = 'fallback',
},
log_level = vim.log.levels.ERROR,
formatters_by_ft = {
lua = { 'stylua' },
python = { 'ruff_format' },
yaml = { 'yamlfmt' },
cmake = { 'gersemi' },
markdown = { 'prettier' },
},
},
keys = {
{
'<space>f',
mode = { 'n', 'x', 'v' },
function()
require('conform').format()
end,
desc = 'Format with Conform',
},
},
}

View File

@ -1,43 +1,5 @@
local M = {} local M = {}
local efm_setup = function(lspconfig, capabilities, on_attach)
local prettier = require('efmls-configs.formatters.prettier')
local gersemi = require('efmls-configs.formatters.gersemi')
local black = require('efmls-configs.formatters.black')
local isort = require('efmls-configs.formatters.isort')
local cmake_lint = require('efmls-configs.linters.cmake_lint')
local flake8 = require('efmls-configs.linters.flake8')
local yamlfmt = {
command = require('mason-core.path').bin_prefix('yamlfmt') .. ' -',
formatStdin = true,
rootMarkers = { '.yamlfmt' },
prefix = 'yamlfmt'
}
local languages = {
markdown = { prettier },
cmake = { gersemi, cmake_lint },
yaml = {
prettier,
-- yamlfmt
}
}
local efmls_config = {
filetypes = vim.tbl_keys(languages),
capabilities = capabilities,
on_attach = on_attach,
cmd = { require('mason-core.path').bin_prefix('efm-langserver') },
settings = {
rootMarkers = { '.git/' },
languages = languages,
},
init_options = {
documentFormatting = true,
documentRangeFormatting = true,
},
}
lspconfig.efm.setup(efmls_config)
end
M.setup_server = function(lspconfig, capabilities, on_attach) M.setup_server = function(lspconfig, capabilities, on_attach)
-- lspconfig['pyright'].setup { -- lspconfig['pyright'].setup {
@ -176,7 +138,6 @@ M.setup_server = function(lspconfig, capabilities, on_attach)
lspconfig.neocmake.setup({}) lspconfig.neocmake.setup({})
end end
efm_setup(lspconfig, capabilities, on_attach)
end end
return M return M

View File

@ -27,17 +27,6 @@ local lspKeys = function(client, bufnr)
vim.keymap.set('n', '<A-o>', '<cmd>ClangdSwitchSourceHeader<CR>', vim.keymap.set('n', '<A-o>', '<cmd>ClangdSwitchSourceHeader<CR>',
vim.tbl_extend('error', options, { desc = 'Switch Source/Header' })) vim.tbl_extend('error', options, { desc = 'Switch Source/Header' }))
-- Set some keybinds conditional on server capabilities
if client.server_capabilities.documentFormattingProvider then
vim.keymap.set('n', '<space>f', function()
vim.lsp.buf.format({ timeout_ms = 10000 })
end, { noremap = true, silent = false, desc = 'Format file', buffer = bufnr })
end
if client.server_capabilities.documentRangeFormattingProvider then
vim.keymap.set('x', '<space>f', function()
vim.lsp.buf.format({ timeout_ms = 10000 })
end, { noremap = true, silent = false, desc = 'Format visual', buffer = bufnr })
end
if client.supports_method('inlayHintProvider') then if client.supports_method('inlayHintProvider') then
vim.keymap.set('n', '<space>i', function() vim.keymap.set('n', '<space>i', function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr }) vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr })