use mason for lsp install
This commit is contained in:
parent
8ebf953ec7
commit
894dba3337
@ -34,7 +34,6 @@ require('packer').init({
|
||||
return require('packer').startup(function()
|
||||
-- Packer can manage itself as an optional plugin
|
||||
use({ 'wbthomason/packer.nvim' })
|
||||
use({ 'neovim/nvim-lspconfig' })
|
||||
use({
|
||||
'nvim-treesitter/nvim-treesitter',
|
||||
run = ':TSUpdate',
|
||||
@ -84,7 +83,6 @@ return require('packer').startup(function()
|
||||
})
|
||||
use({
|
||||
'hrsh7th/nvim-cmp',
|
||||
event = 'InsertEnter',
|
||||
requires = {
|
||||
{ 'hrsh7th/cmp-buffer', after = 'nvim-cmp' },
|
||||
{ 'hrsh7th/cmp-nvim-lsp', after = 'nvim-cmp' },
|
||||
@ -134,6 +132,25 @@ return require('packer').startup(function()
|
||||
'p00f/clangd_extensions.nvim',
|
||||
},
|
||||
config = get_setup('lspinstall'),
|
||||
disable = true,
|
||||
})
|
||||
use {
|
||||
'williamboman/mason.nvim',
|
||||
requires = {
|
||||
'neovim/nvim-lspconfig',
|
||||
'williamboman/mason-lspconfig.nvim',
|
||||
},
|
||||
config = get_setup('my_mason')
|
||||
}
|
||||
use({
|
||||
'p00f/clangd_extensions.nvim'
|
||||
})
|
||||
use({
|
||||
'neovim/nvim-lspconfig',
|
||||
requires = {
|
||||
'p00f/clangd_extensions.nvim',
|
||||
},
|
||||
config = get_setup('my_lspconfig'),
|
||||
})
|
||||
use({
|
||||
'jose-elias-alvarez/null-ls.nvim',
|
||||
|
179
lua/setup/my_lspconfig.lua
Normal file
179
lua/setup/my_lspconfig.lua
Normal file
@ -0,0 +1,179 @@
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities.textDocument.completion.completionItem.documentationFormat = { 'markdown', 'plaintext' }
|
||||
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||
capabilities.textDocument.completion.completionItem.preselectSupport = true
|
||||
capabilities.textDocument.completion.completionItem.insertReplaceSupport = true
|
||||
capabilities.textDocument.completion.completionItem.labelDetailsSupport = true
|
||||
capabilities.textDocument.completion.completionItem.deprecatedSupport = true
|
||||
capabilities.textDocument.completion.completionItem.commitCharactersSupport = true
|
||||
capabilities.textDocument.completion.completionItem.tagSupport = { valueSet = { 1 } }
|
||||
capabilities.offsetEncoding = { 'utf-16' }
|
||||
capabilities.textDocument.completion.completionItem.resolveSupport = {
|
||||
properties = {
|
||||
'documentation',
|
||||
'detail',
|
||||
'additionalTextEdits',
|
||||
},
|
||||
}
|
||||
|
||||
OpenDiagFloat = function()
|
||||
for _, winid in pairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||
if vim.api.nvim_win_get_config(winid).zindex then
|
||||
return
|
||||
end
|
||||
end
|
||||
vim.diagnostic.open_float({ focusable = false })
|
||||
end
|
||||
|
||||
local on_attach = function(client, bufnr)
|
||||
local function buf_set_option(...)
|
||||
vim.api.nvim_buf_set_option(bufnr, ...)
|
||||
end
|
||||
|
||||
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
||||
vim.api.nvim_buf_set_option(0, 'formatexpr', 'v:lua.vim.lsp.formatexpr()')
|
||||
|
||||
-- Mappings.
|
||||
local opts = { noremap = true, silent = false, buffer = bufnr }
|
||||
vim.keymap.set('n', '<space>,', vim.lsp.diagnostic.goto_prev, opts)
|
||||
vim.keymap.set('n', '<space>;', vim.lsp.diagnostic.goto_next, opts)
|
||||
vim.keymap.set('n', '<space>a', vim.lsp.buf.code_action, opts)
|
||||
vim.keymap.set('n', '<space>d', vim.lsp.buf.definition, opts)
|
||||
vim.keymap.set('n', '<space>e', vim.lsp.buf.declaration, opts)
|
||||
vim.keymap.set('n', '<space>h', vim.lsp.buf.hover, opts)
|
||||
vim.keymap.set('n', '<space>c', vim.lsp.buf.outgoing_calls, opts)
|
||||
vim.keymap.set('n', '<space>C', vim.lsp.buf.incoming_calls, opts)
|
||||
vim.keymap.set('n', '<space>m', vim.lsp.buf.rename, opts)
|
||||
local tele_builtins = require('telescope.builtin')
|
||||
vim.keymap.set('n', '<C-t>', tele_builtins.lsp_dynamic_workspace_symbols, opts)
|
||||
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
|
||||
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
|
||||
vim.keymap.set('n', '<space>r', tele_builtins.lsp_references, opts)
|
||||
vim.keymap.set('n', '<A-m>', '<cmd>Telescope aerial<cr>', opts)
|
||||
vim.keymap.set('n', '<space>v', function() tele_builtins.diagnostics({ bufnr = 0 }) end, opts)
|
||||
vim.keymap.set('n', '<A-o>', '<cmd>ClangdSwitchSourceHeader<CR>', opts)
|
||||
|
||||
vim.cmd([[autocmd CursorHold <buffer> lua OpenDiagFloat()]])
|
||||
|
||||
-- Set some keybinds conditional on server capabilities
|
||||
if client.server_capabilities.documentFormattingProvider then
|
||||
vim.keymap.set('n', '<space>f', vim.lsp.buf.format, opts)
|
||||
end
|
||||
if client.server_capabilities.documentRangeFormattingProvider then
|
||||
vim.keymap.set('v', '<space>f', vim.lsp.buf.range_formatting, opts)
|
||||
end
|
||||
|
||||
-- Set autocommands conditional on server_capabilities
|
||||
if client.server_capabilities.documentHighlightProvider then
|
||||
vim.api.nvim_exec(
|
||||
[[
|
||||
hi LspReferenceRead cterm=bold ctermbg=red guibg=DarkGreen
|
||||
hi LspReferenceWrite cterm=bold ctermbg=red guibg=DarkRed
|
||||
]], false)
|
||||
vim.api.nvim_create_augroup("lsp_document_highlight", { clear = true })
|
||||
vim.api.nvim_clear_autocmds { buffer = bufnr, group = "lsp_document_highlight" }
|
||||
vim.api.nvim_create_autocmd("CursorHold", {
|
||||
callback = vim.lsp.buf.document_highlight,
|
||||
buffer = bufnr,
|
||||
group = "lsp_document_highlight",
|
||||
desc = "Document Highlight",
|
||||
})
|
||||
vim.api.nvim_create_autocmd("CursorMoved", {
|
||||
callback = vim.lsp.buf.clear_references,
|
||||
buffer = bufnr,
|
||||
group = "lsp_document_highlight",
|
||||
desc = "Clear All the References",
|
||||
})
|
||||
end
|
||||
|
||||
require('lsp_signature').on_attach({
|
||||
bind = true, -- This is mandatory, otherwise border config won't get registered.
|
||||
handler_opts = {
|
||||
border = 'single',
|
||||
},
|
||||
hi_parameter = 'IncSearch',
|
||||
}, bufnr)
|
||||
require("aerial").on_attach(client, bufnr)
|
||||
end
|
||||
|
||||
require('lspconfig')['pyright'].setup{
|
||||
on_attach = on_attach,
|
||||
}
|
||||
|
||||
require('lspconfig')['cmake'].setup{
|
||||
on_attach = on_attach,
|
||||
}
|
||||
|
||||
-- require('lspconfig')['clangd'].setup{
|
||||
-- on_attach = on_attach,
|
||||
-- }
|
||||
require('clangd_extensions').setup({
|
||||
server = {
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
cmd = { 'clangd', '--compile-commands-dir=build_nvim' },
|
||||
},
|
||||
})
|
||||
|
||||
require('lspconfig')['jsonls'].setup{
|
||||
on_attach = on_attach,
|
||||
}
|
||||
|
||||
local lua_rtp = vim.split(package.path, ';')
|
||||
table.insert(lua_rtp, 'lua/?.lua')
|
||||
table.insert(lua_rtp, 'lua/?/init.lua')
|
||||
require('lspconfig').sumneko_lua.setup{
|
||||
on_attach = on_attach,
|
||||
settings = {
|
||||
Lua = {
|
||||
runtime = {
|
||||
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
|
||||
version = 'LuaJIT',
|
||||
-- Setup your lua path
|
||||
path = lua_rtp,
|
||||
},
|
||||
diagnostics = {
|
||||
-- Get the language server to recognize the `vim` global
|
||||
globals = { 'vim', 'use' },
|
||||
},
|
||||
workspace = {
|
||||
-- Make the server aware of Neovim runtime files
|
||||
library = vim.api.nvim_get_runtime_file('', true),
|
||||
},
|
||||
-- Do not send telemetry data containing a randomized but unique identifier
|
||||
telemetry = {
|
||||
enable = false,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
require('lspconfig')['dockerls'].setup{
|
||||
on_attach = on_attach,
|
||||
}
|
||||
|
||||
require('lspconfig')['yamlls'].setup{
|
||||
on_attach = on_attach,
|
||||
settings = {
|
||||
yaml = {
|
||||
validate = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
local null_ls = require('null-ls')
|
||||
null_ls.setup({
|
||||
sources = {
|
||||
null_ls.builtins.code_actions.gitsigns,
|
||||
null_ls.builtins.formatting.autopep8,
|
||||
null_ls.builtins.formatting.prettier,
|
||||
null_ls.builtins.diagnostics.flake8,
|
||||
null_ls.builtins.formatting.isort,
|
||||
null_ls.builtins.formatting.cmake_format,
|
||||
},
|
||||
on_attach = on_attach,
|
||||
capabilities = capabilities,
|
||||
})
|
||||
|
||||
vim.diagnostic.config({ virtual_text = false })
|
||||
|
4
lua/setup/my_mason.lua
Normal file
4
lua/setup/my_mason.lua
Normal file
@ -0,0 +1,4 @@
|
||||
require('mason').setup()
|
||||
require('mason-lspconfig').setup({
|
||||
automatic_installation = true,
|
||||
})
|
Loading…
x
Reference in New Issue
Block a user