fix lsp
This commit is contained in:
@@ -2,9 +2,10 @@ local M = {}
|
||||
|
||||
function M.setup()
|
||||
require("409.set")
|
||||
require("409.remap")
|
||||
require("409.remap")
|
||||
require("409.lazy")
|
||||
require("409.autocmd")
|
||||
require("409.lsp")
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
188
lua/409/lsp.lua
Normal file
188
lua/409/lsp.lua
Normal file
@@ -0,0 +1,188 @@
|
||||
vim.diagnostic.config({
|
||||
virtual_text = true,
|
||||
update_in_insert = true,
|
||||
float = {
|
||||
border = "single",
|
||||
},
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
callback = function(event)
|
||||
local bufnr = event.buf
|
||||
local client = vim.lsp.get_client_by_id(event.data.client_id)
|
||||
|
||||
if not client then
|
||||
return
|
||||
end
|
||||
|
||||
if vim.bo[bufnr].filetype == "markdown" then
|
||||
return
|
||||
end
|
||||
|
||||
vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, {
|
||||
pattern = { "*.hl", "hypr*.conf" },
|
||||
callback = function(e)
|
||||
vim.lsp.start({
|
||||
name = "hyprlang",
|
||||
cmd = { "hyprls" },
|
||||
root_dir = vim.fn.getcwd(),
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
||||
local lsp_opts = { buffer = bufnr, remap = false }
|
||||
|
||||
vim.keymap.set("n", "gd", function()
|
||||
vim.lsp.buf.definition({
|
||||
on_list = function(list)
|
||||
vim.lsp.util.show_document(list.items[1].user_data, "utf-8", { focus = true })
|
||||
end,
|
||||
})
|
||||
end, { buffer = bufnr, remap = false, nowait = true })
|
||||
vim.keymap.set("n", "gi", function()
|
||||
vim.lsp.buf.implementation({
|
||||
on_list = function(list)
|
||||
vim.lsp.util.show_document(list.items[1].user_data, "utf-8", { focus = true })
|
||||
end,
|
||||
})
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("n", "K", function()
|
||||
vim.lsp.buf.hover()
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("n", "<leader>vws", function()
|
||||
vim.lsp.buf.workspace_symbol()
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("n", "<leader>vd", function()
|
||||
vim.diagnostic.open_float()
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("n", "[d", function()
|
||||
vim.diagnostic.jump({ count = 1 })
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("n", "]d", function()
|
||||
vim.diagnostic.jump({ count = -1 })
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("n", "<leader>vca", function()
|
||||
vim.lsp.buf.code_action()
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("n", "<leader>vrr", function()
|
||||
vim.lsp.buf.references()
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("n", "<leader>vrn", function()
|
||||
vim.lsp.buf.rename()
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("i", "<C-h>", function()
|
||||
vim.lsp.buf.signature_help()
|
||||
end, lsp_opts)
|
||||
end
|
||||
})
|
||||
|
||||
vim.lsp.config.tailwindcss = {
|
||||
filetypes_exclude = { "markdown", "rust", "proto", "sh", "gitignore", "toml", "json", "fugitive" },
|
||||
hovers = true,
|
||||
suggestions = true,
|
||||
root_dir = function(fname)
|
||||
local root_pattern = require("lspconfig").util.root_pattern(
|
||||
"tailwind.config.cjs",
|
||||
"talwind.config.js",
|
||||
"tailwind.config.ts",
|
||||
"postcss.config.js",
|
||||
"postcss.config.ts"
|
||||
)
|
||||
|
||||
return root_pattern(fname)
|
||||
end,
|
||||
}
|
||||
|
||||
vim.lsp.config.vtsls = {
|
||||
filetypes = {
|
||||
"svelte",
|
||||
"vue",
|
||||
"javascript",
|
||||
"javascriptreact",
|
||||
"javascript.jsx",
|
||||
"typescript",
|
||||
"typescriptreact",
|
||||
"typescript.tsx",
|
||||
},
|
||||
settings = {
|
||||
vtsls = {
|
||||
ts_ls = {
|
||||
globalPlugins = {
|
||||
{
|
||||
name = "typescript-svelte-plugin",
|
||||
location = vim.fn.getcwd() .. "/node_modules/typescript-svelte-plugin",
|
||||
enableForWorkspaceTypeScriptVersions = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
tsserver = {
|
||||
globalPlugins = {
|
||||
{
|
||||
name = "typescript-svelte-plugin",
|
||||
location = vim.fn.getcwd() .. "/node_modules/typescript-svelte-plugin",
|
||||
enableForWorkspaceTypeScriptVersions = true,
|
||||
}, {
|
||||
name = "@vue/typescript-plugin",
|
||||
location = vim.fn.expand "$MASON/packages" ..
|
||||
"/vue-language-server" .. "/node_modules/@vue/language-server",
|
||||
languages = { "vue" },
|
||||
configNamespace = 'typescript',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
typescript = {
|
||||
preferences = {
|
||||
quoteStyle = "single",
|
||||
},
|
||||
updateImportsOnFileMove = {
|
||||
enabled = "always",
|
||||
},
|
||||
suggest = {
|
||||
completeFunctionCalls = true,
|
||||
},
|
||||
},
|
||||
javascript = {
|
||||
preferences = {
|
||||
quoteStyle = "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
vim.lsp.config.vue_ls = {
|
||||
on_init = function(client)
|
||||
client.handlers['tsserver/request'] = function(_, result, context)
|
||||
local clients = vim.lsp.get_clients({ bufnr = context.bufnr, name = 'vtsls' })
|
||||
if #clients == 0 then
|
||||
vim.notify('Could not found `vtsls` lsp client, vue_lsp would not work without it.',
|
||||
vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
local ts_client = clients[1]
|
||||
|
||||
local param = unpack(result)
|
||||
local id, command, payload = unpack(param)
|
||||
ts_client:exec_cmd({
|
||||
title = 'vue_request_forward', -- You can give title anything as it's used to represent a command in the UI, `:h Client:exec_cmd`
|
||||
command = 'typescript.tsserverRequest',
|
||||
arguments = {
|
||||
command,
|
||||
payload,
|
||||
},
|
||||
}, { bufnr = context.bufnr }, function(_, r)
|
||||
local response_data = { { id, r.body } }
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
client:notify('tsserver/response', response_data)
|
||||
end)
|
||||
end
|
||||
end,
|
||||
}
|
||||
|
||||
vim.lsp.config.svelte = {
|
||||
capabilities = {
|
||||
workspace = {
|
||||
didChangeWatchedFiles = { dynamicRegistration = true },
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -122,7 +122,12 @@ return {
|
||||
},
|
||||
opts_extend = { "sources.default" },
|
||||
config = function(_, opts)
|
||||
require("blink.cmp").setup(opts)
|
||||
local blink = require("blink.cmp")
|
||||
|
||||
blink.setup(opts)
|
||||
|
||||
local capabilities = blink.get_lsp_capabilities()
|
||||
vim.lsp.config("*", { capabilities = capabilities })
|
||||
end,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,267 +0,0 @@
|
||||
return {
|
||||
{
|
||||
"VonHeikemen/lsp-zero.nvim",
|
||||
branch = "v2.x",
|
||||
dependencies = {
|
||||
{ "neovim/nvim-lspconfig" },
|
||||
{
|
||||
"williamboman/mason.nvim",
|
||||
build = function()
|
||||
---@diagnostic disable-next-line: param-type-mismatch
|
||||
pcall(vim.cmd, "MasonUpdate")
|
||||
end,
|
||||
},
|
||||
{ "williamboman/mason-lspconfig.nvim" },
|
||||
},
|
||||
config = function()
|
||||
local lsp = require("lsp-zero")
|
||||
|
||||
-- Hyprlang LSP
|
||||
vim.api.nvim_create_autocmd({ "BufEnter", "BufWinEnter" }, {
|
||||
pattern = { "*.hl", "hypr*.conf" },
|
||||
callback = function(event)
|
||||
vim.lsp.start({
|
||||
name = "hyprlang",
|
||||
cmd = { "hyprls" },
|
||||
root_dir = vim.fn.getcwd(),
|
||||
})
|
||||
end,
|
||||
})
|
||||
|
||||
lsp.on_attach(function(client, bufnr)
|
||||
if vim.bo[bufnr].filetype == "markdown" then
|
||||
return
|
||||
end
|
||||
|
||||
local lsp_opts = { buffer = bufnr, remap = false }
|
||||
|
||||
vim.keymap.set("n", "gd", function()
|
||||
vim.lsp.buf.definition({
|
||||
on_list = function(list)
|
||||
vim.lsp.util.show_document(list.items[1].user_data, "utf-8", { focus = true })
|
||||
end,
|
||||
})
|
||||
end, { buffer = bufnr, remap = false, nowait = true })
|
||||
vim.keymap.set("n", "gi", function()
|
||||
vim.lsp.buf.implementation({
|
||||
on_list = function(list)
|
||||
vim.lsp.util.show_document(list.items[1].user_data, "utf-8", { focus = true })
|
||||
end,
|
||||
})
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("n", "K", function()
|
||||
vim.lsp.buf.hover()
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("n", "<leader>vws", function()
|
||||
vim.lsp.buf.workspace_symbol()
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("n", "<leader>vd", function()
|
||||
vim.diagnostic.open_float()
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("n", "[d", function()
|
||||
vim.diagnostic.jump({ count = 1 })
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("n", "]d", function()
|
||||
vim.diagnostic.jump({ count = -1 })
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("n", "<leader>vca", function()
|
||||
vim.lsp.buf.code_action()
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("n", "<leader>vrr", function()
|
||||
vim.lsp.buf.references()
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("n", "<leader>vrn", function()
|
||||
vim.lsp.buf.rename()
|
||||
end, lsp_opts)
|
||||
vim.keymap.set("i", "<C-h>", function()
|
||||
vim.lsp.buf.signature_help()
|
||||
end, lsp_opts)
|
||||
end)
|
||||
end,
|
||||
},
|
||||
{
|
||||
"neovim/nvim-lspconfig",
|
||||
dependencies = {
|
||||
"williamboman/mason.nvim",
|
||||
"williamboman/mason-lspconfig.nvim",
|
||||
"saghen/blink.cmp",
|
||||
},
|
||||
opts = {
|
||||
diagnostics = {
|
||||
virtual_text = true,
|
||||
update_in_insert = true,
|
||||
float = {
|
||||
border = "single",
|
||||
},
|
||||
},
|
||||
inlay_hints = {
|
||||
enabled = false,
|
||||
},
|
||||
servers = {
|
||||
tailwindcss = {
|
||||
filetypes_exclude = { "markdown", "rust", "proto", "sh", "gitignore", "toml", "json", "fugitive" },
|
||||
hovers = true,
|
||||
suggestions = true,
|
||||
root_dir = function(fname)
|
||||
local root_pattern = require("lspconfig").util.root_pattern(
|
||||
"tailwind.config.cjs",
|
||||
"talwind.config.js",
|
||||
"tailwind.config.ts",
|
||||
"postcss.config.js",
|
||||
"postcss.config.ts"
|
||||
)
|
||||
|
||||
return root_pattern(fname)
|
||||
end,
|
||||
},
|
||||
vtsls = {
|
||||
filetypes = {
|
||||
"javascript",
|
||||
"javascriptreact",
|
||||
"javascript.jsx",
|
||||
"typescript",
|
||||
"typescriptreact",
|
||||
"typescript.tsx",
|
||||
},
|
||||
settings = {
|
||||
vtsls = {
|
||||
ts_ls = {
|
||||
globalPlugins = {
|
||||
{
|
||||
name = "typescript-svelte-plugin",
|
||||
location = vim.fn.getcwd() .. "/node_modules/typescript-svelte-plugin",
|
||||
enableForWorkspaceTypeScriptVersions = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
tsserver = {
|
||||
globalPlugins = {
|
||||
{
|
||||
name = "typescript-svelte-plugin",
|
||||
location = vim.fn.getcwd() .. "/node_modules/typescript-svelte-plugin",
|
||||
enableForWorkspaceTypeScriptVersions = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
typescript = {
|
||||
preferences = {
|
||||
quoteStyle = "single",
|
||||
},
|
||||
updateImportsOnFileMove = {
|
||||
enabled = "always",
|
||||
},
|
||||
suggest = {
|
||||
completeFunctionCalls = true,
|
||||
},
|
||||
},
|
||||
javascript = {
|
||||
preferences = {
|
||||
quoteStyle = "single",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
svelte = {
|
||||
capabilities = {
|
||||
workspace = {
|
||||
didChangeWatchedFiles = { dynamicRegistration = true },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
config = function(_, opts)
|
||||
local lspconfig = require("lspconfig")
|
||||
local lsp = require("lsp-zero")
|
||||
|
||||
vim.api.nvim_create_autocmd("LspAttach", {
|
||||
callback = function(args)
|
||||
local buffer = args.buf
|
||||
local lsp_opts = { buffer = buffer, remap = false, nowait = true }
|
||||
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
||||
|
||||
if
|
||||
opts.inlay_hints.enabled
|
||||
and client ~= nil
|
||||
and client.supports_method(client, "textDocument/inlayHint")
|
||||
then
|
||||
vim.lsp.inlay_hint.enable(true)
|
||||
end
|
||||
|
||||
if client ~= nil then
|
||||
if client.name == "svelte" then
|
||||
vim.api.nvim_create_autocmd("BufWritePost", {
|
||||
pattern = { "*.svelte", "*.js", "*.ts" },
|
||||
group = vim.api.nvim_create_augroup("svelte_ondidchangetsorjsfile", { clear = true }),
|
||||
callback = function(ctx)
|
||||
client.notify(client, "$/onDidChangeTsOrJsFile", { uri = ctx.match })
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
if vim.bo[buffer].filetype == "svelte" then
|
||||
vim.api.nvim_create_autocmd("BufWritePost", {
|
||||
pattern = { "*.svelte", "*.js", "*.ts" },
|
||||
callback = function(ctx)
|
||||
client.notify(client, "$/onDidChangeTsOrJsFile", { uri = ctx.match })
|
||||
end,
|
||||
})
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
vim.diagnostic.config(opts.diagnostics)
|
||||
|
||||
require("lspconfig.ui.windows").default_options = {
|
||||
border = "single",
|
||||
}
|
||||
|
||||
require("mason-lspconfig").setup({
|
||||
ensure_installed = {
|
||||
"vtsls",
|
||||
"eslint",
|
||||
"lua_ls",
|
||||
"jsonls",
|
||||
"html",
|
||||
"tailwindcss",
|
||||
"pylsp",
|
||||
"dockerls",
|
||||
"bashls",
|
||||
"marksman",
|
||||
"rust_analyzer",
|
||||
},
|
||||
handlers = {
|
||||
function(server_name)
|
||||
if lspconfig[server_name] ~= nil then
|
||||
local config = opts.servers[server_name] or {}
|
||||
config.capabilities = require("blink.cmp").get_lsp_capabilities(config.capabilities)
|
||||
|
||||
lspconfig[server_name].setup(config)
|
||||
end
|
||||
end,
|
||||
lua_ls = function()
|
||||
local config = lsp.nvim_lua_ls()
|
||||
config.capabilities = require("blink.cmp").get_lsp_capabilities(config.capabilities)
|
||||
|
||||
require("lspconfig").lua_ls.setup(config)
|
||||
end,
|
||||
},
|
||||
})
|
||||
end,
|
||||
},
|
||||
{
|
||||
"williamboman/mason.nvim",
|
||||
dependencies = {},
|
||||
opts = {
|
||||
PATH = "append",
|
||||
ui = {
|
||||
border = "single",
|
||||
},
|
||||
},
|
||||
config = function(_, opts)
|
||||
require("mason").setup(opts)
|
||||
end,
|
||||
},
|
||||
}
|
||||
37
lua/409/plugins/mason.lua
Normal file
37
lua/409/plugins/mason.lua
Normal file
@@ -0,0 +1,37 @@
|
||||
return {
|
||||
{
|
||||
"williamboman/mason.nvim",
|
||||
dependencies = {},
|
||||
opts = {
|
||||
PATH = "append",
|
||||
ui = {
|
||||
border = "single",
|
||||
},
|
||||
},
|
||||
config = function(_, opts)
|
||||
require("mason").setup(opts)
|
||||
end,
|
||||
},
|
||||
{
|
||||
"mason-org/mason-lspconfig.nvim",
|
||||
opts = {
|
||||
"vtsls",
|
||||
"eslint",
|
||||
"lua_ls",
|
||||
"jsonls",
|
||||
"html",
|
||||
"tailwindcss",
|
||||
"pylsp",
|
||||
"dockerls",
|
||||
"bashls",
|
||||
"marksman",
|
||||
"rust_analyzer",
|
||||
},
|
||||
dependencies = {
|
||||
{
|
||||
"mason-org/mason.nvim", opts = {}
|
||||
},
|
||||
"neovim/nvim-lspconfig",
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ return {
|
||||
{
|
||||
"nvim-treesitter/nvim-treesitter",
|
||||
dependencies = {
|
||||
"neovim/nvim-lspconfig",
|
||||
"nvim-treesitter/nvim-tree-docs",
|
||||
"JoosepAlviste/nvim-ts-context-commentstring",
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user