156 lines
5.4 KiB
Lua
156 lines
5.4 KiB
Lua
return {
|
|
'neovim/nvim-lspconfig',
|
|
dependencies = {
|
|
{ 'mason-org/mason.nvim', opts = {} },
|
|
'mason-org/mason-lspconfig.nvim',
|
|
{ 'j-hui/fidget.nvim', opts = {
|
|
notification = {
|
|
window = {
|
|
winblend = 0,
|
|
},
|
|
},
|
|
} },
|
|
'saghen/blink.cmp',
|
|
'WhoIsSethDaniel/mason-tool-installer.nvim',
|
|
'b0o/schemastore.nvim',
|
|
},
|
|
config = function()
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
|
|
callback = function(event)
|
|
local map = function(keys, func, desc, mode)
|
|
mode = mode or 'n'
|
|
vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
|
|
end
|
|
|
|
-- map('<leader>a', vim.lsp.buf.code_action, 'Code Action', { 'n', 'x', 'v' })
|
|
|
|
map('gr', require('telescope.builtin').lsp_references, 'Goto References')
|
|
|
|
map('gi', require('telescope.builtin').lsp_implementations, 'Goto Implementation')
|
|
|
|
map('gd', require('telescope.builtin').lsp_definitions, 'Goto Definition')
|
|
|
|
map('<leader>fs', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Open Workspace Symbols')
|
|
|
|
map('<leader>d', vim.diagnostic.open_float, 'Show Diagnostics')
|
|
map('<leader>D', function()
|
|
vim.diagnostic.jump({ count = 1, float = true })
|
|
end, 'Next Diagnostics')
|
|
|
|
-- This function resolves a difference between neovim nightly (version 0.11) and stable (version 0.10)
|
|
---@param client vim.lsp.Client
|
|
---@param method vim.lsp.protocol.Method
|
|
---@param bufnr? integer some lsp support methods only in specific files
|
|
---@return boolean
|
|
local function client_supports_method(client, method, bufnr)
|
|
if vim.fn.has('nvim-0.11') == 1 then
|
|
return client:supports_method(method, bufnr)
|
|
else
|
|
return client.supports_method(method, { bufnr = bufnr })
|
|
end
|
|
end
|
|
|
|
-- The following two autocommands are used to highlight references of the
|
|
-- word under your cursor when your cursor rests there for a little while.
|
|
-- See `:help CursorHold` for information about when this is executed
|
|
--
|
|
-- When you move your cursor, the highlights will be cleared (the second autocommand).
|
|
local client = vim.lsp.get_client_by_id(event.data.client_id)
|
|
if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_documentHighlight, event.buf) then
|
|
local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight', { clear = false })
|
|
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, {
|
|
buffer = event.buf,
|
|
group = highlight_augroup,
|
|
callback = vim.lsp.buf.document_highlight,
|
|
})
|
|
|
|
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
|
|
buffer = event.buf,
|
|
group = highlight_augroup,
|
|
callback = vim.lsp.buf.clear_references,
|
|
})
|
|
|
|
vim.api.nvim_create_autocmd('LspDetach', {
|
|
group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }),
|
|
callback = function(event2)
|
|
vim.lsp.buf.clear_references()
|
|
vim.api.nvim_clear_autocmds({ group = 'kickstart-lsp-highlight', buffer = event2.buf })
|
|
end,
|
|
})
|
|
end
|
|
|
|
-- The following code creates a keymap to toggle inlay hints in your
|
|
-- code, if the language server you are using supports them
|
|
--
|
|
-- This may be unwanted, since they displace some of your code
|
|
if client and client_supports_method(client, vim.lsp.protocol.Methods.textDocument_inlayHint, event.buf) then
|
|
map('<leader>th', function()
|
|
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = event.buf }))
|
|
end, '[T]oggle Inlay [H]ints')
|
|
end
|
|
end,
|
|
})
|
|
|
|
local servers = {
|
|
lua_ls = {
|
|
settings = {
|
|
Lua = {
|
|
runtime = {
|
|
version = 'LuaJIT',
|
|
path = {
|
|
'lua/?.lua',
|
|
'lua/?/init.lua',
|
|
},
|
|
},
|
|
-- Make the server aware of Neovim runtime files
|
|
workspace = {
|
|
checkThirdParty = false,
|
|
library = vim.api.nvim_get_runtime_file('', true),
|
|
},
|
|
},
|
|
},
|
|
},
|
|
bashls = {},
|
|
zls = {},
|
|
cssls = {},
|
|
prismals = {},
|
|
intelephense = {},
|
|
html = {},
|
|
yamlls = {},
|
|
eslint = {},
|
|
tailwindcss = {},
|
|
vtsls = {
|
|
settings = {
|
|
vtsls = { autoUseWorkspaceTsdk = true },
|
|
},
|
|
},
|
|
jsonls = {
|
|
settings = {
|
|
json = {
|
|
schemas = require('schemastore').json.schemas(),
|
|
validate = { enable = true },
|
|
},
|
|
},
|
|
},
|
|
gopls = {},
|
|
}
|
|
local ensure_installed = vim.tbl_keys(servers or {})
|
|
vim.list_extend(ensure_installed, {
|
|
'stylua',
|
|
'prettierd',
|
|
'php-cs-fixer',
|
|
'cspell',
|
|
})
|
|
|
|
local capabilities = require('blink.cmp').get_lsp_capabilities()
|
|
|
|
require('mason-tool-installer').setup({ ensure_installed = ensure_installed })
|
|
for server_name, server in pairs(servers) do
|
|
server.capabilities = vim.tbl_deep_extend('force', {}, capabilities, server.capabilities or {})
|
|
vim.lsp.config(server_name, server)
|
|
vim.lsp.enable(server_name)
|
|
end
|
|
end,
|
|
}
|