feat manage script
This commit is contained in:
98
config/linux-dev/nvim/lua/plugins/lsp.lua
Normal file
98
config/linux-dev/nvim/lua/plugins/lsp.lua
Normal file
@@ -0,0 +1,98 @@
|
||||
local remap = require("utils.remap")
|
||||
|
||||
vim.diagnostic.config({
|
||||
update_in_insert = false,
|
||||
virtual_text = {
|
||||
source = true,
|
||||
},
|
||||
float = {
|
||||
border = "rounded",
|
||||
},
|
||||
})
|
||||
|
||||
vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, {
|
||||
border = "rounded",
|
||||
})
|
||||
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, {
|
||||
border = "rounded",
|
||||
})
|
||||
|
||||
return {
|
||||
|
||||
"neovim/nvim-lspconfig",
|
||||
dependencies = {
|
||||
{ "williamboman/mason.nvim", config = true },
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
{ "j-hui/fidget.nvim", opts = {} }, -- side fidget showing status
|
||||
"hrsh7th/cmp-nvim-lsp", -- completion
|
||||
"b0o/schemastore.nvim",
|
||||
},
|
||||
config = function()
|
||||
require("mason").setup()
|
||||
require("mason-lspconfig").setup()
|
||||
|
||||
local lspconfig = require("lspconfig")
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||
|
||||
require("lspconfig.ui.windows").default_options = {
|
||||
border = "rounded",
|
||||
}
|
||||
|
||||
lspconfig.ts_ls.setup({
|
||||
capabilities = capabilities,
|
||||
init_options = {
|
||||
preferences = {
|
||||
includeCompletionsWithSnippetText = true,
|
||||
jsxAttributeCompletionStyle = "auto",
|
||||
},
|
||||
},
|
||||
on_attach = function(client, bufnr)
|
||||
-- Mappings
|
||||
local opts = { buffer = bufnr }
|
||||
remap.nmap("gd", vim.lsp.buf.definition, opts)
|
||||
remap.nmap("gr", vim.lsp.buf.references, opts)
|
||||
|
||||
remap.nmap("K", vim.lsp.buf.hover, opts)
|
||||
|
||||
remap.nmap("<leader>rn", vim.lsp.buf.rename, opts)
|
||||
remap.nmap("<leader>ca", vim.lsp.buf.code_action, opts)
|
||||
remap.nmap("<leader>ri", function()
|
||||
local diagnostics = vim.diagnostic.get(0)
|
||||
|
||||
-- Filter for TypeScript's unused import diagnostics (code 6133)
|
||||
local unused_imports_diagnostics = {}
|
||||
for _, diagnostic in ipairs(diagnostics) do
|
||||
if diagnostic.code == 6133 and diagnostic.source == "typescript" then
|
||||
table.insert(unused_imports_diagnostics, diagnostic)
|
||||
end
|
||||
end
|
||||
|
||||
vim.lsp.buf.code_action({
|
||||
context = {
|
||||
diagnostics = unused_imports_diagnostics,
|
||||
only = { "source.removeUnusedImports" },
|
||||
},
|
||||
})
|
||||
end, { desc = "Remove unused imports" })
|
||||
|
||||
remap.nmap("[d", vim.diagnostic.goto_prev, opts)
|
||||
remap.nmap("]d", vim.diagnostic.goto_next, opts)
|
||||
remap.nmap("<leader>d", vim.diagnostic.open_float, opts)
|
||||
end,
|
||||
})
|
||||
|
||||
lspconfig.eslint.setup({})
|
||||
lspconfig.html.setup({})
|
||||
lspconfig.cssls.setup({})
|
||||
lspconfig.jsonls.setup({
|
||||
capabilities = capabilities,
|
||||
settings = {
|
||||
json = {
|
||||
schemas = require("schemastore").json.schemas(),
|
||||
validate = { enable = true },
|
||||
allowComments = true,
|
||||
},
|
||||
},
|
||||
})
|
||||
end,
|
||||
}
|
||||
Reference in New Issue
Block a user