vim lint+format+lsp fixes

This commit is contained in:
Henrik Bakken
2023-09-01 16:11:33 +02:00
parent e24909ddb9
commit fbb0ea717b
+58 -22
View File
@@ -519,11 +519,25 @@ require("lazy").setup({
require("mason").setup() require("mason").setup()
end, end,
}, },
{
"mfussenegger/nvim-lint",
config = function()
require("lint").linters_by_ft = {
javascript = { "eslint_d" },
typescript = { "eslint_d" },
html = { "tidy", "eslint_d" },
}
vim.api.nvim_create_autocmd({ "BufWritePost" }, {
callback = function()
require("lint").try_lint()
end,
})
end,
},
{ {
"mhartington/formatter.nvim", "mhartington/formatter.nvim",
-- Utilities for creating configurations -- Utilities for creating configurations
config = function () config = function()
local util = require("formatter.util") local util = require("formatter.util")
local map = vim.keymap.set local map = vim.keymap.set
local opts = { silent = true, noremap = true } local opts = { silent = true, noremap = true }
@@ -538,30 +552,31 @@ require("lazy").setup({
python = { python = {
require("formatter.filetypes.python").black, require("formatter.filetypes.python").black,
-- require("formatter.filetypes.python").pyment, -- require("formatter.filetypes.python").pyment,
function () function()
return { return {
exe = "isort", exe = "isort",
args = { "--quiet", "--profile black", "--force-single-line-import", "-" }, args = { "--quiet", "--profile black", "--force-single-line-import", "-" },
stdin = true, stdin = true,
} }
end, end,
function () function()
return { return {
exe = "black", exe = "black",
args = { "--quiet", "--preview", "-" }, args = { "--quiet", "--preview", "-" },
stdin = true, stdin = true,
} }
end, end,
function () function()
return { return {
exe = "blackdoc", exe = "blackdoc",
args = { "-q", "-t py311", }, args = { "-q", "-t py311" },
stdin = false, stdin = false,
} }
end, end,
}, },
go = { require("formatter.filetypes.go").gofumpt, require("formatter.filetypes.go").golines },
lua = { lua = {
function () function()
return { return {
exe = "stylua", exe = "stylua",
args = { args = {
@@ -577,28 +592,35 @@ require("lazy").setup({
end, end,
}, },
yaml = { yaml = {
function () function()
return { return {
exe = "yamlfmt", exe = "yamlfmt",
args = { "-formatter indentless_arrays=true,retain_line_breaks=true,line_ending=lf,max_line_length=100,pad_line_comments=2", "-in" }, args = {
"-formatter indentless_arrays=true,retain_line_breaks=true,line_ending=lf,max_line_length=100,pad_line_comments=2",
"-in",
},
stdin = true, stdin = true,
} }
end, end,
}, },
sh = { require("formatter.filetypes.sh").shfmt, }, sh = { require("formatter.filetypes.sh").shfmt },
typescript = { require("formatter.filetypes.typescript").eslint_d, }, typescript = { require("formatter.filetypes.typescript").eslint_d },
javascript = { require("formatter.filetypes.javascript").eslint_d, }, javascript = { require("formatter.filetypes.javascript").eslint_d },
html = { require("formatter.filetypes.html").prettierd, }, html = {
-- require("formatter.filetypes.html").prettierd,
require("formatter.filetypes.html").tidy,
require("formatter.filetypes.javascript").eslint_d,
},
css = { css = {
require("formatter.filetypes.css").prettierd, require("formatter.filetypes.css").prettierd,
require("formatter.filetypes.css").eslint_d, require("formatter.filetypes.css").eslint_d,
}, },
markdown = { require("formatter.filetypes.markdown").prettierd, }, markdown = { require("formatter.filetypes.markdown").prettierd },
json = {require("formatter.filetypes.json").jq, }, json = { require("formatter.filetypes.json").jq },
["*"] = { require("formatter.filetypes.any").remove_trailing_whitespace }, ["*"] = { require("formatter.filetypes.any").remove_trailing_whitespace },
} },
}) })
end end,
}, },
{ {
"neovim/nvim-lspconfig", "neovim/nvim-lspconfig",
@@ -625,10 +647,10 @@ require("lazy").setup({
vim.diagnostic.open_float({ source = true }) vim.diagnostic.open_float({ source = true })
end) end)
bmap("n", "<M-n>", function() bmap("n", "<M-n>", function()
vim.diagnostic.goto_next({ severity = { min = vim.diagnostic.severity.INFO } }) vim.diagnostic.goto_next({ severity = { min = vim.diagnostic.severity.HINT } })
end) end)
bmap("n", "<M-p>", function() bmap("n", "<M-p>", function()
vim.diagnostic.goto_prev({ severity = { min = vim.diagnostic.severity.INFO } }) vim.diagnostic.goto_prev({ severity = { min = vim.diagnostic.severity.HINT } })
end) end)
bmap("n", "gd", vim.lsp.buf.definition) bmap("n", "gd", vim.lsp.buf.definition)
bmap("n", "gD", vim.lsp.buf.type_definition) bmap("n", "gD", vim.lsp.buf.type_definition)
@@ -669,7 +691,20 @@ require("lazy").setup({
-- Get the language server to recognize the `vim` global in init.lua -- Get the language server to recognize the `vim` global in init.lua
globals = { "vim" }, globals = { "vim" },
}, },
format = {enable = false}, format = { enable = false },
},
},
html = {
html = {
format = {
templating = true,
wrapLineLength = 120,
wrapAttributes = "auto",
},
hover = {
documentation = true,
references = true,
},
}, },
}, },
} }
@@ -683,7 +718,6 @@ require("lazy").setup({
ensure_installed = { ensure_installed = {
"bashls", -- bash "bashls", -- bash
"cssls", -- css "cssls", -- css
"eslint", -- javascript
"html", -- html "html", -- html
"jsonls", -- json "jsonls", -- json
"lua_ls", -- lua "lua_ls", -- lua
@@ -768,6 +802,8 @@ vim.o.expandtab = true -- Use spaces instead of tabs
vim.o.shiftround = true -- Round indent vim.o.shiftround = true -- Round indent
vim.o.tabstop = 4 -- Number of spaces tabs count for vim.o.tabstop = 4 -- Number of spaces tabs count for
vim.o.shiftwidth = 4 -- Size of an indent vim.o.shiftwidth = 4 -- Size of an indent
vim.o.listchars = "tab:→ ,trail:·,extends:↷,precedes:↶,nbsp:+,eol:↵"
vim.o.list = true -- Show listchars
-- search -- search
vim.opt.wildmode = { "full" } -- Command-line completion mode vim.opt.wildmode = { "full" } -- Command-line completion mode
@@ -794,7 +830,7 @@ vim.o.foldenable = false
vim.o.foldmethod = "expr" vim.o.foldmethod = "expr"
vim.o.completeopt = "menu,menuone,noinsert" vim.o.completeopt = "menu,menuone,noinsert"
vim.opt.formatoptions = vim.opt.formatoptions - {"c", "r", "o"} vim.opt.formatoptions = vim.opt.formatoptions - { "c", "r", "o" }
-- press enter in quickfix list to goto -- press enter in quickfix list to goto
vim.api.nvim_command([[augroup MYAU]]) vim.api.nvim_command([[augroup MYAU]])