vim lint+format+lsp fixes

This commit is contained in:
Henrik Bakken
2023-09-01 16:11:33 +02:00
parent e24909ddb9
commit fbb0ea717b
+121 -85
View File
@@ -519,86 +519,108 @@ 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 map = vim.keymap.set
local opts = { silent = true, noremap = true }
map("n", "<leader>f", ":Format<cr>", opts)
map("n", "<leader>F", ":FormatWrite<cr>", opts)
local util = require("formatter.util") -- Provides the Format, FormatWrite, FormatLock, and FormatWriteLock commands
local map = vim.keymap.set require("formatter").setup({
local opts = { silent = true, noremap = true } logging = true,
map("n", "<leader>f", ":Format<cr>", opts) log_level = vim.log.levels.WARN,
map("n", "<leader>F", ":FormatWrite<cr>", opts) filetype = {
python = {
-- Provides the Format, FormatWrite, FormatLock, and FormatWriteLock commands require("formatter.filetypes.python").black,
require("formatter").setup({ -- require("formatter.filetypes.python").pyment,
logging = true, function()
log_level = vim.log.levels.WARN, return {
filetype = { exe = "isort",
python = { args = { "--quiet", "--profile black", "--force-single-line-import", "-" },
require("formatter.filetypes.python").black, stdin = true,
-- require("formatter.filetypes.python").pyment, }
function () end,
return { function()
exe = "isort", return {
args = { "--quiet", "--profile black", "--force-single-line-import", "-" }, exe = "black",
stdin = true, args = { "--quiet", "--preview", "-" },
} stdin = true,
end, }
function () end,
return { function()
exe = "black", return {
args = { "--quiet", "--preview", "-" }, exe = "blackdoc",
stdin = true, args = { "-q", "-t py311" },
} stdin = false,
end, }
function () end,
return {
exe = "blackdoc",
args = { "-q", "-t py311", },
stdin = false,
}
end,
},
lua = {
function ()
return {
exe = "stylua",
args = {
"--search-parent-directories",
"--indent-type Spaces",
"--stdin-filepath",
util.escape_path(util.get_current_buffer_file_path()),
"--",
"-",
}, },
stdin = true, go = { require("formatter.filetypes.go").gofumpt, require("formatter.filetypes.go").golines },
} lua = {
end, function()
}, return {
yaml = { exe = "stylua",
function () args = {
return { "--search-parent-directories",
exe = "yamlfmt", "--indent-type Spaces",
args = { "-formatter indentless_arrays=true,retain_line_breaks=true,line_ending=lf,max_line_length=100,pad_line_comments=2", "-in" }, "--stdin-filepath",
stdin = true, util.escape_path(util.get_current_buffer_file_path()),
} "--",
end, "-",
}, },
sh = { require("formatter.filetypes.sh").shfmt, }, stdin = true,
typescript = { require("formatter.filetypes.typescript").eslint_d, }, }
javascript = { require("formatter.filetypes.javascript").eslint_d, }, end,
html = { require("formatter.filetypes.html").prettierd, }, },
css = { yaml = {
function()
return {
exe = "yamlfmt",
args = {
"-formatter indentless_arrays=true,retain_line_breaks=true,line_ending=lf,max_line_length=100,pad_line_comments=2",
"-in",
},
stdin = true,
}
end,
},
sh = { require("formatter.filetypes.sh").shfmt },
typescript = { require("formatter.filetypes.typescript").eslint_d },
javascript = { require("formatter.filetypes.javascript").eslint_d },
html = {
-- require("formatter.filetypes.html").prettierd,
require("formatter.filetypes.html").tidy,
require("formatter.filetypes.javascript").eslint_d,
},
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,
},
}, },
}, },
} }
@@ -681,16 +716,15 @@ require("lazy").setup({
local mason_lspconfig = require("mason-lspconfig") local mason_lspconfig = require("mason-lspconfig")
mason_lspconfig.setup({ mason_lspconfig.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 "marksman", -- markdown
"marksman", -- markdown
"pyright", -- python "pyright", -- python
"tsserver", -- typescript "tsserver", -- typescript
"yamlls", -- yaml "yamlls", -- yaml
}, },
}) })
mason_lspconfig.setup_handlers({ mason_lspconfig.setup_handlers({
@@ -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]])