Update lint and lsp configs for ts
This commit is contained in:
parent
56ccea6a7b
commit
3902f3e598
@ -3,14 +3,48 @@ return {
|
|||||||
config = function()
|
config = function()
|
||||||
local conform = require("conform")
|
local conform = require("conform")
|
||||||
|
|
||||||
|
local function file_exists(name)
|
||||||
|
local f = io.open(name, "r")
|
||||||
|
if f ~= nil then
|
||||||
|
io.close(f)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local function decide_js_formatter()
|
||||||
|
local cwd = vim.fn.getcwd()
|
||||||
|
if file_exists(cwd .. "/biome.json") then
|
||||||
|
return "biome"
|
||||||
|
else
|
||||||
|
return "prettier"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local function decide_json_formatter()
|
||||||
|
local cwd = vim.fn.getcwd()
|
||||||
|
if file_exists(cwd .. "/biome.json") then
|
||||||
|
return "biome"
|
||||||
|
elseif file_exists(cwd .. "/.prettierrc") then
|
||||||
|
return "prettier"
|
||||||
|
else
|
||||||
|
return "jq"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
conform.setup({
|
conform.setup({
|
||||||
formatters_by_ft = {
|
formatters_by_ft = {
|
||||||
|
javascript = { decide_js_formatter() },
|
||||||
|
javascriptreact = { decide_js_formatter() },
|
||||||
|
json = { decide_json_formatter() },
|
||||||
lua = { "stylua" },
|
lua = { "stylua" },
|
||||||
|
markdown = { "mdformat" },
|
||||||
nginx = { "nginxfmt" },
|
nginx = { "nginxfmt" },
|
||||||
python = { "black", "flake8" },
|
python = { "isort", "black" },
|
||||||
|
sh = { "shfmt" },
|
||||||
|
typescript = { decide_js_formatter() },
|
||||||
|
typescriptreact = { decide_js_formatter() },
|
||||||
yaml = { "yamlfix" },
|
yaml = { "yamlfix" },
|
||||||
-- Use the "*" filetype to run formatters on all filetypes.
|
["*"] = { "codespell" },
|
||||||
-- ["*"] = { "codespell" },
|
|
||||||
},
|
},
|
||||||
|
|
||||||
default_format_opts = {
|
default_format_opts = {
|
||||||
|
|||||||
48
.config/nvim/lua/plugins/language_support/nvim-lint.lua
Normal file
48
.config/nvim/lua/plugins/language_support/nvim-lint.lua
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
return {
|
||||||
|
"mfussenegger/nvim-lint",
|
||||||
|
config = function()
|
||||||
|
local function file_exists(name)
|
||||||
|
local f = io.open(name, "r")
|
||||||
|
if f ~= nil then
|
||||||
|
io.close(f)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local function decide_linter()
|
||||||
|
local cwd = vim.fn.getcwd()
|
||||||
|
if file_exists(cwd .. "/biome.json") then
|
||||||
|
return "biome"
|
||||||
|
else
|
||||||
|
return "eslint_d"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local lint = require("lint")
|
||||||
|
|
||||||
|
lint.linters_by_ft = {
|
||||||
|
javascript = { "eslint_d" },
|
||||||
|
javascriptreact = { "eslint_d" },
|
||||||
|
markdown = { "markdownlint" },
|
||||||
|
python = { "flake8" },
|
||||||
|
sh = { "shellcheck" },
|
||||||
|
typescript = { "eslint_d" },
|
||||||
|
typescriptreact = { "eslint_d" },
|
||||||
|
yaml = { "yamllint" },
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
|
||||||
|
vim.keymap.set("n", "<leader>l", function()
|
||||||
|
lint.try_lint()
|
||||||
|
end, { desc = "Trigger linting for current file" })
|
||||||
|
end,
|
||||||
|
}
|
||||||
@ -18,9 +18,11 @@ return {
|
|||||||
|
|
||||||
require("mason-lspconfig").setup({
|
require("mason-lspconfig").setup({
|
||||||
ensure_installed = {
|
ensure_installed = {
|
||||||
|
"bashls",
|
||||||
"cssls",
|
"cssls",
|
||||||
"dockerls",
|
"dockerls",
|
||||||
"emmet_ls",
|
"emmet_ls",
|
||||||
|
"eslint",
|
||||||
"html",
|
"html",
|
||||||
"jdtls",
|
"jdtls",
|
||||||
"jsonls",
|
"jsonls",
|
||||||
@ -43,10 +45,15 @@ return {
|
|||||||
"eslint_d",
|
"eslint_d",
|
||||||
"firefox-debug-adapter",
|
"firefox-debug-adapter",
|
||||||
"flake8",
|
"flake8",
|
||||||
|
"isort",
|
||||||
"java-debug-adapter",
|
"java-debug-adapter",
|
||||||
"jq",
|
"jq",
|
||||||
|
"markdownlint",
|
||||||
|
"mdformat",
|
||||||
"nginx-config-formatter",
|
"nginx-config-formatter",
|
||||||
"prettierd",
|
"prettier",
|
||||||
|
"shellcheck",
|
||||||
|
"shfmt",
|
||||||
"stylua",
|
"stylua",
|
||||||
"yamlfix",
|
"yamlfix",
|
||||||
"yamllint",
|
"yamllint",
|
||||||
|
|||||||
@ -134,6 +134,17 @@ return {
|
|||||||
root_markers = { "tsconfig.json", "jsconfig.json", "package.json" },
|
root_markers = { "tsconfig.json", "jsconfig.json", "package.json" },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
vim.lsp.config("jsonls", {
|
||||||
|
on_attach = function(client)
|
||||||
|
-- Disable formatting capability for tsserver
|
||||||
|
client.server_capabilities.documentFormattingProvider = false
|
||||||
|
client.server_capabilities.documentRangeFormattingProvider = false
|
||||||
|
end,
|
||||||
|
filetypes = {
|
||||||
|
"json",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
vim.lsp.config("pylsp", {
|
vim.lsp.config("pylsp", {
|
||||||
on_attach = function(client)
|
on_attach = function(client)
|
||||||
client.server_capabilities.documentFormattingProvider = false
|
client.server_capabilities.documentFormattingProvider = false
|
||||||
@ -144,5 +155,15 @@ return {
|
|||||||
},
|
},
|
||||||
root_markers = { "requirements.txt" },
|
root_markers = { "requirements.txt" },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
vim.lsp.config("bashls", {
|
||||||
|
on_attach = function(client)
|
||||||
|
client.server_capabilities.documentFormattingProvider = false
|
||||||
|
client.server_capabilities.documentRangeFormattingProvider = false
|
||||||
|
end,
|
||||||
|
filetypes = {
|
||||||
|
"sh",
|
||||||
|
},
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user