feat: modify LSPs to prefer conform for formatting
Add eslint LSP feat: Add linter support with 'nvim-lint' Add linting to JavaScript / TypeScript and Go files
This commit is contained in:
parent
4c989092b4
commit
6efd8a3873
9 changed files with 90 additions and 13 deletions
|
|
@ -58,3 +58,6 @@ opt.listchars = "tab: ,extends:›,precedes:‹,nbsp:·,trail:·"
|
|||
|
||||
-- System wide clipboard
|
||||
opt.clipboard = "unnamedplus"
|
||||
|
||||
-- Use .editorconfig files
|
||||
vim.g.editorconfig = true
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ return {
|
|||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
vim.lsp.buf.format()
|
||||
require("conform").format({ async = true, lsp_fallback = true })
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
|
|
|||
11
lua/custom/lsp/config/eslint.lua
Normal file
11
lua/custom/lsp/config/eslint.lua
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
return {
|
||||
on_attach = function(_, bufnr)
|
||||
-- Format document on save
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
require("conform").format({ async = true, lsp_fallback = true })
|
||||
end,
|
||||
})
|
||||
end
|
||||
}
|
||||
|
|
@ -4,7 +4,7 @@ return {
|
|||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
vim.lsp.buf.format()
|
||||
require("conform").format({ async = true, lsp_fallback = true })
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1 +1,17 @@
|
|||
return {}
|
||||
return {
|
||||
on_attach = function(_, bufnr)
|
||||
-- Format document on save
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
-- check that biome lsp is running
|
||||
local biome = vim.lsp.get_clients({ buffer = bufnr, name = "biome" })
|
||||
if #biome == 0 then
|
||||
vim.lsp.buf.format()
|
||||
else
|
||||
vim.lsp.buf.format({ filter = function(client) return client.name == "biome" end })
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1,11 @@
|
|||
return {}
|
||||
return {
|
||||
on_attach = function(_, bufnr)
|
||||
-- Format document on save
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
buffer = bufnr,
|
||||
callback = function()
|
||||
require("conform").format({ async = true, lsp_fallback = true })
|
||||
end,
|
||||
})
|
||||
end
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ return {
|
|||
},
|
||||
},
|
||||
init = function()
|
||||
-- vim.cmd("colorscheme lackluster-night")
|
||||
-- vim.cmd("colorscheme lackluster-mint")
|
||||
end
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ return {
|
|||
config = function()
|
||||
require("conform").setup({
|
||||
formatters_by_ft = {
|
||||
go = { "go" },
|
||||
html = { "biome", "html-lsp" },
|
||||
json = { "biome" },
|
||||
yaml = { "yamlls" },
|
||||
yaml = { "prettier" },
|
||||
javascript = { "biome" },
|
||||
javascriptreact = { "biome" },
|
||||
markdown = { "biome" },
|
||||
|
|
@ -13,15 +13,25 @@ return {
|
|||
typescriptreact = { "biome" },
|
||||
["*"] = { "trim_whitespace" },
|
||||
},
|
||||
format_on_save = {
|
||||
timeout_ms = 500,
|
||||
lsp_fallback = true,
|
||||
},
|
||||
formatters = {
|
||||
biome = {
|
||||
condition = function()
|
||||
return vim.uv.fs_realpath("biome.json") ~= nil end,
|
||||
},
|
||||
return vim.uv.fs_realpath("biome.json") ~= nil
|
||||
end,
|
||||
command = "biome",
|
||||
args = {
|
||||
"check",
|
||||
"--fix",
|
||||
"--unsafe",
|
||||
"$FILENAME",
|
||||
},
|
||||
stdin = false,
|
||||
}
|
||||
},
|
||||
format_on_save = {
|
||||
lsp_fallback = true,
|
||||
async = false,
|
||||
timeout_ms = 500,
|
||||
},
|
||||
})
|
||||
end,
|
||||
|
|
|
|||
27
lua/custom/plugins/nvim-lint.lua
Normal file
27
lua/custom/plugins/nvim-lint.lua
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
return {
|
||||
"mfussenegger/nvim-lint",
|
||||
event = {
|
||||
"BufReadPre",
|
||||
"BufNewFile",
|
||||
},
|
||||
config = function()
|
||||
local lint = require("lint")
|
||||
|
||||
lint.linters_by_ft = {
|
||||
go = { "golangcilint" },
|
||||
javascript = { "biomejs", "eslint_d" },
|
||||
typescript = { "biomejs", "eslint_d" },
|
||||
javascriptreact = { "biomejs", "eslint_d" },
|
||||
typescriptreact = { "biomejs", "eslint_d" },
|
||||
}
|
||||
|
||||
local lint_augroup = vim.api.nvim_create_augroup("lint", { clear = true })
|
||||
|
||||
vim.api.nvim_create_autocmd({ "BufEnter", "BufWritePost", "InsertLeave" }, {
|
||||
group = lint_augroup,
|
||||
callback = function()
|
||||
lint.try_lint()
|
||||
end,
|
||||
})
|
||||
end,
|
||||
}
|
||||
Loading…
Reference in a new issue