mirror of
https://github.com/ivuorinen/dotfiles.git
synced 2026-02-12 22:52:37 +00:00
chore(config): tweaks to nvim config, autogroups
This commit is contained in:
@@ -1,49 +1,45 @@
|
|||||||
-- ── Formatting ──────────────────────────────────────────────────────
|
-- ── Formatting ──────────────────────────────────────────────────────
|
||||||
-- Lightweight yet powerful formatter plugin for Neovim
|
-- Lightweight yet powerful formatter plugin for Neovim
|
||||||
-- https://github.com/stevearc/conform.nvim
|
-- https://github.com/stevearc/conform.nvim
|
||||||
return {
|
|
||||||
'stevearc/conform.nvim',
|
|
||||||
event = { 'BufWritePre' },
|
|
||||||
cmd = { 'ConformInfo' },
|
|
||||||
config = function()
|
|
||||||
-- Select first conform formatter that is available
|
|
||||||
---@param bufnr integer
|
|
||||||
---@param ... string
|
|
||||||
---@return string
|
|
||||||
local function first(bufnr, ...)
|
|
||||||
local conform = require 'conform'
|
|
||||||
for i = 1, select('#', ...) do
|
|
||||||
local formatter = select(i, ...)
|
|
||||||
if conform.get_formatter_info(formatter, bufnr).available then
|
|
||||||
return formatter
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return select(1, ...)
|
|
||||||
end
|
|
||||||
|
|
||||||
require('conform').setup {
|
return {
|
||||||
|
{
|
||||||
|
'stevearc/conform.nvim',
|
||||||
|
event = { 'BufWritePre' },
|
||||||
|
cmd = { 'ConformInfo' },
|
||||||
|
opts = {
|
||||||
-- Enable or disable logging
|
-- Enable or disable logging
|
||||||
notify_on_error = true,
|
notify_on_error = false,
|
||||||
-- Set the default formatter for all filetypes
|
-- Set the default formatter for all filetypes
|
||||||
default_formatter = 'injected',
|
default_formatter = 'injected',
|
||||||
-- Set the default formatter for all filetypes
|
-- Set the default formatter for all filetypes
|
||||||
default_formatter_opts = {
|
default_formatter_opts = {
|
||||||
lsp_format = 'fallback',
|
lsp_format = 'fallback',
|
||||||
-- Set the default formatter for all filetypes
|
-- Set the default formatter for all filetypes
|
||||||
-- formatter = 'injected',
|
formatter = 'injected',
|
||||||
-- Set the default formatter for all filetypes
|
-- Set the default formatter for all filetypes
|
||||||
-- formatter_opts = {},
|
-- formatter_opts = {},
|
||||||
},
|
},
|
||||||
|
-- The options you set here will be merged with the builtin formatters.
|
||||||
|
-- You can also define any custom formatters here.
|
||||||
|
formatters = {
|
||||||
|
injected = { options = { ignore_errors = true } },
|
||||||
|
-- # Example of using dprint only when a dprint.json file is present
|
||||||
|
-- dprint = {
|
||||||
|
-- condition = function(ctx)
|
||||||
|
-- return vim.fs.find({ "dprint.json" }, { path = ctx.filename, upward = true })[1]
|
||||||
|
-- end,
|
||||||
|
-- },
|
||||||
|
--
|
||||||
|
-- # Example of using shfmt with extra args
|
||||||
|
-- shfmt = {
|
||||||
|
-- prepend_args = { "-i", "2", "-ci" },
|
||||||
|
-- },
|
||||||
|
},
|
||||||
formatters_by_ft = {
|
formatters_by_ft = {
|
||||||
markdown = function(bufnr)
|
|
||||||
return { first(bufnr, 'prettierd', 'prettier'), 'injected' }
|
|
||||||
end,
|
|
||||||
javascript = function(bufnr)
|
|
||||||
return { first(bufnr, 'prettier', 'eslint'), 'injected' }
|
|
||||||
end,
|
|
||||||
lua = { 'stylua' },
|
lua = { 'stylua' },
|
||||||
-- Conform will run multiple formatters sequentially
|
-- Conform will run multiple formatters sequentially
|
||||||
-- python = { 'isort', 'black', lsp_format = 'fallback' },
|
go = { 'goimports', 'gofmt' },
|
||||||
-- You can customize some of the format options for the filetype (:help conform.format)
|
-- You can customize some of the format options for the filetype (:help conform.format)
|
||||||
-- rust = { 'rustfmt', lsp_format = 'fallback' },
|
-- rust = { 'rustfmt', lsp_format = 'fallback' },
|
||||||
},
|
},
|
||||||
@@ -59,9 +55,7 @@ return {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- Disable with a global or buffer-local variable
|
-- Disable with a global or buffer-local variable
|
||||||
if
|
if vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat then
|
||||||
vim.g.disable_autoformat or vim.b[bufnr].disable_autoformat
|
|
||||||
then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- Disable autoformat for files in a certain path
|
-- Disable autoformat for files in a certain path
|
||||||
@@ -73,12 +67,20 @@ return {
|
|||||||
|
|
||||||
return { timeout_ms = 500, lsp_format = 'fallback' }
|
return { timeout_ms = 500, lsp_format = 'fallback' }
|
||||||
end,
|
end,
|
||||||
}
|
},
|
||||||
end,
|
init = function()
|
||||||
init = function()
|
-- If you want the formatexpr, here is the place to set it
|
||||||
-- If you want the formatexpr, here is the place to set it
|
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
|
||||||
vim.o.formatexpr = "v:lua.require'conform'.formatexpr()"
|
end,
|
||||||
end,
|
},
|
||||||
|
-- Automatically install formatters registered with conform.nvim via mason.nvim
|
||||||
|
-- https://github.com/zapling/mason-conform.nvim
|
||||||
|
{
|
||||||
|
'zapling/mason-conform.nvim',
|
||||||
|
depends = {
|
||||||
|
'stevearc/conform.nvim',
|
||||||
|
'williamboman/mason.nvim',
|
||||||
|
},
|
||||||
|
opts = {},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ return {
|
|||||||
config = function()
|
config = function()
|
||||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
capabilities.textDocument.foldingRange = {
|
capabilities.textDocument.foldingRange = {
|
||||||
dynamicRegistration = false,
|
dynamicRegistration = true,
|
||||||
lineFoldingOnly = true,
|
lineFoldingOnly = true,
|
||||||
}
|
}
|
||||||
local language_servers = require('lspconfig').util.available_servers() -- or list servers manually like {'gopls', 'clangd'}
|
local language_servers = require('lspconfig').util.available_servers() -- or list servers manually like {'gopls', 'clangd'}
|
||||||
@@ -84,7 +84,13 @@ return {
|
|||||||
---@param width number The width of the window.
|
---@param width number The width of the window.
|
||||||
---@param truncate function Truncate function
|
---@param truncate function Truncate function
|
||||||
---@return table
|
---@return table
|
||||||
fold_virt_text_handler = function(virtText, lnum, endLnum, width, truncate)
|
fold_virt_text_handler = function(
|
||||||
|
virtText,
|
||||||
|
lnum,
|
||||||
|
endLnum,
|
||||||
|
width,
|
||||||
|
truncate
|
||||||
|
)
|
||||||
local newVirtText = {}
|
local newVirtText = {}
|
||||||
local suffix = (' %d '):format(endLnum - lnum)
|
local suffix = (' %d '):format(endLnum - lnum)
|
||||||
local sufWidth = vim.fn.strdisplaywidth(suffix)
|
local sufWidth = vim.fn.strdisplaywidth(suffix)
|
||||||
|
|||||||
Reference in New Issue
Block a user