diff --git a/lua/plugins/conform.lua b/lua/plugins/conform.lua new file mode 100644 index 0000000..7a58228 --- /dev/null +++ b/lua/plugins/conform.lua @@ -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 = { + { + 'f', + mode = { 'n', 'x', 'v' }, + function() + require('conform').format() + end, + desc = 'Format with Conform', + }, + }, +} diff --git a/lua/plugins/lsp/server.lua b/lua/plugins/lsp/server.lua index 65fdf4b..7c5e0e2 100644 --- a/lua/plugins/lsp/server.lua +++ b/lua/plugins/lsp/server.lua @@ -1,43 +1,5 @@ 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) -- lspconfig['pyright'].setup { @@ -176,7 +138,6 @@ M.setup_server = function(lspconfig, capabilities, on_attach) lspconfig.neocmake.setup({}) end - efm_setup(lspconfig, capabilities, on_attach) end return M diff --git a/lua/plugins/lspconfig.lua b/lua/plugins/lspconfig.lua index ada11b2..142723c 100644 --- a/lua/plugins/lspconfig.lua +++ b/lua/plugins/lspconfig.lua @@ -27,17 +27,6 @@ local lspKeys = function(client, bufnr) vim.keymap.set('n', '', 'ClangdSwitchSourceHeader', 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', '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', '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 vim.keymap.set('n', 'i', function() vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = bufnr }), { bufnr = bufnr })