chore(nvim): fixed mason formatters, config

This commit is contained in:
2024-12-16 05:04:01 +02:00
parent 8e84c3aef7
commit 8a52c9a97e
3 changed files with 279 additions and 130 deletions

View File

@@ -104,15 +104,4 @@ autocmd({ 'BufRead', 'BufNewFile' }, {
command = 'set filetype=sshconfig', command = 'set filetype=sshconfig',
}) })
-- Format on save, unless disabled
autocmd('BufWritePre', {
group = augroup('Format', { clear = true }),
pattern = '*', -- All files
callback = function()
if not vim.g.disable_autoformat then
vim.lsp.buf.format({ async = false })
end
end,
})
-- vim: ts=2 sts=2 sw=2 et -- vim: ts=2 sts=2 sw=2 et

View File

@@ -20,8 +20,16 @@ K.n('<C-w>+', ':resize +10<CR>', { desc = 'H Resize +' })
K.n('<C-w>=', '<C-w>=', { desc = 'Equal Size Splits' }) K.n('<C-w>=', '<C-w>=', { desc = 'Equal Size Splits' })
-- ── Deal with word wrap ───────────────────────────────────────────── -- ── Deal with word wrap ─────────────────────────────────────────────
K.n('k', "v:count == 0 ? 'gk' : 'k'", { desc = 'Move up', noremap = true, expr = true }) K.n(
K.n('j', "v:count == 0 ? 'gj' : 'j'", { desc = 'Move down', noremap = true, expr = true }) 'k',
"v:count == 0 ? 'gk' : 'k'",
{ desc = 'Move up', noremap = true, expr = true }
)
K.n(
'j',
"v:count == 0 ? 'gj' : 'j'",
{ desc = 'Move down', noremap = true, expr = true }
)
-- ── Text manipulation ─────────────────────────────────────────────── -- ── Text manipulation ───────────────────────────────────────────────
K.d('<', { 'n', 'v' }, '<gv', 'Indent Left') K.d('<', { 'n', 'v' }, '<gv', 'Indent Left')
@@ -55,7 +63,7 @@ K.ld('ca', 'n', ':Lspsaga code_action<cr>', 'Code Action')
K.ld('cci', 'n', ':Lspsaga incoming_calls<cr>', 'Incoming Calls') K.ld('cci', 'n', ':Lspsaga incoming_calls<cr>', 'Incoming Calls')
K.ld('cco', 'n', ':Lspsaga outgoing_calls<cr>', 'Outgoing Calls') K.ld('cco', 'n', ':Lspsaga outgoing_calls<cr>', 'Outgoing Calls')
K.ld('cd', 'n', ':Lspsaga show_line_diagnostics<cr>', 'Line Diagnostics') K.ld('cd', 'n', ':Lspsaga show_line_diagnostics<cr>', 'Line Diagnostics')
K.ld('cf', { 'n', 'x' }, ':lua vim.lsp.buf.format()<CR>', 'Format') -- K.ld('cf', { 'n', 'x' }, ':lua vim.lsp.buf.format()<CR>', 'Format')
K.ld('cg', 'n', ':lua require("neogen").generate()<CR>', 'Generate annotations') K.ld('cg', 'n', ':lua require("neogen").generate()<CR>', 'Generate annotations')
K.ld('ci', 'n', ':Lspsaga implement<cr>', 'Implementations') K.ld('ci', 'n', ':Lspsaga implement<cr>', 'Implementations')
K.ld('cl', 'n', ':Lspsaga show_cursor_diagnostics<cr>', 'Cursor Diagnostics') K.ld('cl', 'n', ':Lspsaga show_cursor_diagnostics<cr>', 'Cursor Diagnostics')
@@ -84,14 +92,18 @@ K.nl('cbt', '<Cmd>CBllline<CR>', 'CB: Titled Line')
-- unless it's a generic operation like searching or finding buffers -- unless it's a generic operation like searching or finding buffers
K.nl('f', ':Telescope find_files<cr>', 'Find Files') K.nl('f', ':Telescope find_files<cr>', 'Find Files')
K.nl(',', ':Telescope buffers<cr>', 'Find existing buffers') K.nl(',', ':Telescope buffers<cr>', 'Find existing buffers')
K.nl('/', function() K.nl(
'/',
function()
require('telescope.builtin').current_buffer_fuzzy_find( require('telescope.builtin').current_buffer_fuzzy_find(
require('telescope.themes').get_dropdown { require('telescope.themes').get_dropdown {
winblend = 20, winblend = 20,
previewer = true, previewer = true,
} }
) )
end, 'Fuzzily search in current buffer') end,
'Fuzzily search in current buffer'
)
K.nl('sc', ':Telescope commands<cr>', 'Commands') K.nl('sc', ':Telescope commands<cr>', 'Commands')
K.nl('sd', ':Telescope diagnostics<cr>', 'Search Diagnostics') K.nl('sd', ':Telescope diagnostics<cr>', 'Search Diagnostics')
@@ -100,7 +112,11 @@ K.nl('sh', ':Telescope help_tags<cr>', 'Help tags')
K.nl('sk', ':Telescope keymaps<cr>', 'Search Keymaps') K.nl('sk', ':Telescope keymaps<cr>', 'Search Keymaps')
K.nl('sl', ':Telescope luasnip<CR>', 'Search LuaSnip') K.nl('sl', ':Telescope luasnip<CR>', 'Search LuaSnip')
K.nl('so', ':Telescope oldfiles<CR>', 'Old Files') K.nl('so', ':Telescope oldfiles<CR>', 'Old Files')
K.nl('sp', ':lua require("telescope").extensions.lazy_plugins.lazy_plugins()<cr>', 'Lazy Plugins') K.nl(
'sp',
':lua require("telescope").extensions.lazy_plugins.lazy_plugins()<cr>',
'Lazy Plugins'
)
K.nl('sq', ':Telescope quickfix<cr>', 'Quickfix') K.nl('sq', ':Telescope quickfix<cr>', 'Quickfix')
K.nl('ss', ':Telescope treesitter<cr>', 'Treesitter') K.nl('ss', ':Telescope treesitter<cr>', 'Treesitter')
K.nl('st', ':TodoTelescope<cr>', 'Search Todos') K.nl('st', ':TodoTelescope<cr>', 'Search Todos')

View File

@@ -1,57 +1,12 @@
return { -- ╭─────────────────────────────────────────────────────────╮
-- improve neovim lsp experience -- │ LSP Setup and configuration │
-- https://github.com/nvimdev/lspsaga.nvim -- ╰─────────────────────────────────────────────────────────╯
-- https://nvimdev.github.io/lspsaga/
{ -- LSP Servers are installed and configured by lsp-setup.nvim
'nvimdev/lspsaga.nvim', -- Mason formatters Conform uses to format files
event = 'LspAttach', -- These are automatically configured by zapling/mason-conform.nvim
dependencies = {
'nvim-treesitter/nvim-treesitter', local lsp_servers = {
'nvim-tree/nvim-web-devicons',
},
---@type LspsagaConfig
opts = {
code_action = {
show_server_name = true,
keys = {
quit = { 'q', '<ESC>' },
},
},
diagnostic = {
keys = {
quit = { 'q', '<ESC>' },
},
},
},
},
-- A simple wrapper for nvim-lspconfig and mason-lspconfig
-- to easily setup LSP servers.
-- https://github.com/junnplus/lsp-setup.nvim
{
'junnplus/lsp-setup.nvim',
dependencies = {
{ 'neovim/nvim-lspconfig' },
{
'williamboman/mason.nvim',
cmd = 'Mason',
run = ':MasonUpdate'
},
{ 'williamboman/mason-lspconfig.nvim' },
{ 'folke/neodev.nvim' },
{ 'b0o/schemastore.nvim' },
{ 'saghen/blink.cmp' },
},
opts = {
default_mappings = false,
mappings = {
gd = 'lua require"telescope.builtin".lsp_definitions()',
gi = 'lua require"telescope.builtin".lsp_implementations()',
gr = 'lua require"telescope.builtin".lsp_references()',
},
inlay_hints = {
enabled = true,
},
servers = {
bashls = {}, bashls = {},
-- csharp_ls = {}, -- csharp_ls = {},
diagnosticls = {}, diagnosticls = {},
@@ -76,8 +31,19 @@ return {
lua_ls = { lua_ls = {
settings = { settings = {
Lua = { Lua = {
completion = {
callSnippet = 'Replace',
},
diagnostics = { diagnostics = {
globals = { 'vim' }, globals = {
'vim',
-- busted
'describe',
'it',
'before_each',
'after_each',
'assert',
},
disable = { disable = {
-- Ignore lua_ls noisy `missing-fields` warnings -- Ignore lua_ls noisy `missing-fields` warnings
'missing-fields', 'missing-fields',
@@ -137,39 +103,168 @@ return {
}, },
}, },
}, },
}
return {
-- `lazydev` configures Lua LSP for your Neovim config, runtime and plugins
-- used for completion, annotations and signatures of Neovim apis
-- https://github.com/folke/lazydev.nvim
{
'folke/lazydev.nvim',
ft = 'lua',
opts = {
library = {
-- Load luvit types when the `vim.uv` word is found
{ path = 'luvit-meta/library', words = { 'vim%.uv' } },
}, },
}, },
},
-- Meta type definitions for the Lua platform Luvit.
-- https://github.com/Bilal2453/luvit-meta
{ 'Bilal2453/luvit-meta', lazy = true },
-- improve neovim lsp experience
-- https://github.com/nvimdev/lspsaga.nvim
-- https://nvimdev.github.io/lspsaga/
{
'nvimdev/lspsaga.nvim',
event = 'LspAttach',
dependencies = {
'nvim-treesitter/nvim-treesitter',
'nvim-tree/nvim-web-devicons',
},
---@type LspsagaConfig
opts = {
code_action = {
show_server_name = true,
keys = {
quit = { 'q', '<ESC>' },
},
},
diagnostic = {
keys = {
quit = { 'q', '<ESC>' },
},
},
},
},
-- A simple wrapper for nvim-lspconfig and mason-lspconfig
-- to easily setup LSP servers.
-- https://github.com/junnplus/lsp-setup.nvim
{
'junnplus/lsp-setup.nvim',
dependencies = {
-- Quickstart configs for Nvim LSP
-- https://github.com/neovim/nvim-lspconfig
{ 'neovim/nvim-lspconfig' },
-- Portable package manager for Neovim that runs everywhere Neovim runs.
-- Easily install and manage LSP servers, DAP servers, linters, and formatters.
-- https://github.com/williamboman/mason.nvim
{
'williamboman/mason.nvim',
version = '*',
cmd = 'Mason',
run = ':MasonUpdate',
opts = {},
},
-- Extensible UI for Neovim notifications and LSP progress messages.
-- https://github.com/j-hui/fidget.nvim
{
'j-hui/fidget.nvim',
version = '*',
opts = {},
},
-- Extension to mason.nvim that makes it easier to use lspconfig with mason.nvim.
-- https://github.com/williamboman/mason-lspconfig.nvim
{ 'williamboman/mason-lspconfig.nvim' },
-- Install and upgrade third party tools automatically
-- https://github.com/WhoIsSethDaniel/mason-tool-installer.nvim
{
'WhoIsSethDaniel/mason-tool-installer.nvim',
version = '*',
opts = {
auto_install = true,
auto_update = true,
ensure_installed = {
'editorconfig-checker',
'goimports',
'gotests',
'phpcbf',
'pint',
'prettierd',
'shellcheck',
'shfmt',
'staticcheck',
'stylua',
'vint',
'yamlfmt',
},
},
},
-- JSON schemas for Neovim
-- https://github.com/b0o/SchemaStore.nvim
{ 'b0o/schemastore.nvim' },
-- Performant, batteries-included completion plugin for Neovim
-- https://github.com/saghen/blink.cmp
-- See lua/plugins/blink.lua for configs
{ 'saghen/blink.cmp' },
},
opts = {
default_mappings = false,
mappings = {
gd = 'lua require"telescope.builtin".lsp_definitions()',
gi = 'lua require"telescope.builtin".lsp_implementations()',
gr = 'lua require"telescope.builtin".lsp_references()',
},
inlay_hints = {
enabled = true,
},
servers = lsp_servers,
},
config = function(_, opts) config = function(_, opts)
require('neodev').setup() require('lazydev').setup()
require('lsp-setup').setup(opts) require('lsp-setup').setup(opts)
local lspconfig = require('lspconfig') local lspconfig = require 'lspconfig'
for server, config in pairs(opts.servers) do for server, config in pairs(opts.servers) do
-- passing config.capabilities to blink.cmp merges with the capabilities in your -- passing config.capabilities to blink.cmp merges with the capabilities in your
-- `opts[server].capabilities, if you've defined it -- `opts[server].capabilities, if you've defined it
config.capabilities = require('blink.cmp').get_lsp_capabilities(config.capabilities) config.capabilities =
require('blink.cmp').get_lsp_capabilities(config.capabilities)
lspconfig[server].setup(config) lspconfig[server].setup(config)
end end
lspconfig.lua_ls.on_init = function(client) lspconfig.lua_ls.on_init = function(client)
if client.workspace_folders then if client.workspace_folders then
local path = client.workspace_folders[1].name local path = client.workspace_folders[1].name
if vim.loop.fs_stat(path .. '/.luarc.json') or vim.loop.fs_stat(path .. '/.luarc.jsonc') then if
vim.loop.fs_stat(path .. '/.luarc.json')
or vim.loop.fs_stat(path .. '/.luarc.jsonc')
then
return return
end end
end end
client.config.settings.Lua = vim.tbl_deep_extend('force', client.config.settings.Lua, { client.config.settings.Lua =
vim.tbl_deep_extend('force', client.config.settings.Lua, {
runtime = { runtime = {
-- Tell the language server which version of Lua you're using -- Tell the language server which version of Lua you're using
-- (most likely LuaJIT in the case of Neovim) -- (most likely LuaJIT in the case of Neovim)
version = 'LuaJIT' version = 'LuaJIT',
}, },
-- Make the server aware of Neovim runtime files -- Make the server aware of Neovim runtime files
workspace = { workspace = {
checkThirdParty = false, checkThirdParty = false,
library = { library = {
vim.env.VIMRUNTIME vim.env.VIMRUNTIME,
} },
} },
}) })
end end
lspconfig.jsonls.settings = { lspconfig.jsonls.settings = {
@@ -191,4 +286,53 @@ return {
} }
end, end,
}, },
-- Lightweight yet powerful formatter plugin for Neovim
-- https://github.com/stevearc/conform.nvim
{
'stevearc/conform.nvim',
event = { 'BufWritePre' },
cmd = { 'ConformInfo' },
keys = {
{
'<leader>cf',
function()
require('conform').format { async = true, lsp_format = 'fallback' }
end,
mode = '',
desc = 'Format buffer',
},
},
opts = {
notify_on_error = false,
---@type nil|conform.FormatOpts|fun(bufnr: integer): nil|conform.FormatOpts
format_on_save = function(bufnr)
-- Disable "format_on_save lsp_fallback" for languages that don't
-- have a well standardized coding style. You can add additional
-- languages here or re-enable it for the disabled ones.
local disable_filetypes = { c = true, cpp = true }
local lsp_format_opt
if disable_filetypes[vim.bo[bufnr].filetype] then
lsp_format_opt = 'never'
else
lsp_format_opt = 'fallback'
end
return {
timeout_ms = 500,
lsp_format = lsp_format_opt,
}
end,
formatters_by_ft = {
lua = { 'stylua' },
-- Conform can also run multiple formatters sequentially
-- python = { "isort", "black" },
--
-- You can use 'stop_after_first' to run the first available formatter from the list
-- javascript = { "prettierd", "prettier", stop_after_first = true },
},
},
},
-- Automatically install formatters registered with conform.nvim via mason.nvim
-- https://github.com/zapling/mason-conform.nvim
{ 'zapling/mason-conform.nvim', opts = {} },
} }