Enable lsp install plugin
This commit is contained in:
parent
d92d380f7a
commit
d74a4b7576
2
init.lua
2
init.lua
@ -66,8 +66,8 @@ require('nvim-treesitter.configs').setup({
|
|||||||
-------------------- TELESCOPE -----------------------------
|
-------------------- TELESCOPE -----------------------------
|
||||||
require('my_telescope')
|
require('my_telescope')
|
||||||
-------------------- LSP -----------------------------------
|
-------------------- LSP -----------------------------------
|
||||||
require('mylsp')
|
|
||||||
|
|
||||||
|
require('my_lspinstall')
|
||||||
-------------------- GITSIGNS ------------------------------
|
-------------------- GITSIGNS ------------------------------
|
||||||
require('gitsigns').setup()
|
require('gitsigns').setup()
|
||||||
-------------------- LIGHTBULB -----------------------------
|
-------------------- LIGHTBULB -----------------------------
|
||||||
|
94
lua/my_lspinstall.lua
Normal file
94
lua/my_lspinstall.lua
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
local utils = require('utils')
|
||||||
|
|
||||||
|
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.textDocument.completion.completionItem.resolveSupport = {
|
||||||
|
properties = {
|
||||||
|
'documentation',
|
||||||
|
'detail',
|
||||||
|
'additionalTextEdits',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local on_attach = function(client, bufnr)
|
||||||
|
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
|
||||||
|
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
|
||||||
|
|
||||||
|
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
|
||||||
|
|
||||||
|
-- Mappings.
|
||||||
|
local opts = { noremap=true, silent=true }
|
||||||
|
utils.map('n', '<space>,', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts)
|
||||||
|
utils.map('n', '<space>;', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts)
|
||||||
|
utils.map('n', '<space>a', '<cmd>Telescope lsp_code_actions<CR>', opts)
|
||||||
|
utils.map('n', '<space>d', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
|
||||||
|
utils.map('n', '<space>e', '<cmd>lua vim.lsp.buf.declaration()<CR>', opts)
|
||||||
|
utils.map('n', '<space>h', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
|
||||||
|
utils.map('n', '<space>c', '<cmd>lua vim.lsp.buf.outgoing_calls()<CR>', opts)
|
||||||
|
utils.map('n', '<space>C', '<cmd>lua vim.lsp.buf.incoming_calls()<CR>', opts)
|
||||||
|
utils.map('n', '<space>m', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
|
||||||
|
-- utils.map('n', '<space>r', '<cmd>lua vim.lsp.buf.references()<CR, opts>')
|
||||||
|
utils.map('n', '<space>s', '<cmd>lua vim.lsp.buf.document_symbol()<CR>', opts)
|
||||||
|
utils.map('n', '<C-t>', '<cmd>Telescope lsp_dynamic_workspace_symbols<CR>', opts)
|
||||||
|
utils.map('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts)
|
||||||
|
utils.map('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
|
||||||
|
utils.map('n', '<space>r', '<cmd>Telescope lsp_references<cr>')
|
||||||
|
utils.map('n', '<C-S-o>', '<cmd>Telescope lsp_document_symbols<cr>')
|
||||||
|
utils.map('n', '<A-m>', '<cmd>Telescope lsp_document_symbols<cr>')
|
||||||
|
utils.map('n', '<space>v', '<cmd>Telescope lsp_document_diagnostics<cr>')
|
||||||
|
utils.map('n', '<A-o>', ':ClangdSwitchSourceHeader<CR>', opts)
|
||||||
|
|
||||||
|
-- Set some keybinds conditional on server capabilities
|
||||||
|
if client.resolved_capabilities.document_formatting then
|
||||||
|
utils.map('n', '<space>f', '<cmd>lua vim.lsp.buf.formatting()<CR>', opts)
|
||||||
|
end
|
||||||
|
if client.resolved_capabilities.document_range_formatting then
|
||||||
|
utils.map('v', '<space>f', '<esc><cmd>lua vim.lsp.buf.range_formatting()<CR>', opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Set autocommands conditional on server_capabilities
|
||||||
|
if client.resolved_capabilities.document_highlight then
|
||||||
|
vim.api.nvim_exec([[
|
||||||
|
hi LspReferenceRead cterm=bold ctermbg=red guibg=DarkGreen
|
||||||
|
hi LspReferenceText cterm=bold ctermbg=Black guibg=DarkYellow guifg=Black
|
||||||
|
hi LspReferenceWrite cterm=bold ctermbg=red guibg=DarkRed
|
||||||
|
augroup lsp_document_highlight
|
||||||
|
autocmd! * <buffer>
|
||||||
|
autocmd CursorHold <buffer> lua vim.lsp.buf.document_highlight()
|
||||||
|
autocmd CursorHoldI <buffer> lua vim.lsp.buf.document_highlight()
|
||||||
|
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
|
||||||
|
augroup END
|
||||||
|
]], false)
|
||||||
|
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)
|
||||||
|
end
|
||||||
|
|
||||||
|
local lsp_installer = require("nvim-lsp-installer")
|
||||||
|
lsp_installer.on_server_ready(function(server)
|
||||||
|
local opts = {
|
||||||
|
on_attach = on_attach,
|
||||||
|
capabilities = capabilities,
|
||||||
|
}
|
||||||
|
|
||||||
|
-- (optional) Customize the options passed to the server
|
||||||
|
-- if server.name == "tsserver" then
|
||||||
|
-- opts.root_dir = function() ... end
|
||||||
|
-- end
|
||||||
|
|
||||||
|
-- This setup() function is exactly the same as lspconfig's setup function (:help lspconfig-quickstart)
|
||||||
|
server:setup(opts)
|
||||||
|
vim.cmd [[ do User LspAttachBuffers ]]
|
||||||
|
end)
|
@ -1,6 +1,19 @@
|
|||||||
local nvim_lsp = require 'lspconfig'
|
local nvim_lsp = require 'lspconfig'
|
||||||
local utils = require('utils')
|
local utils = require('utils')
|
||||||
|
|
||||||
|
local system_name
|
||||||
|
if vim.fn.has("mac") == 1 then
|
||||||
|
system_name = "macOS"
|
||||||
|
elseif vim.fn.has("unix") == 1 then
|
||||||
|
system_name = "Linux"
|
||||||
|
elseif vim.fn.has('win32') == 1 then
|
||||||
|
system_name = "Windows"
|
||||||
|
else
|
||||||
|
print("Unsupported system for sumneko")
|
||||||
|
end
|
||||||
|
|
||||||
|
local sumneko_root_path = 'D:/tmp/lua-language-server'
|
||||||
|
local sumneko_binary = sumneko_root_path.."/bin/"..system_name.."/lua-language-server"
|
||||||
-- We use the default settings for ccls and pylsp: the option table can stay empty
|
-- We use the default settings for ccls and pylsp: the option table can stay empty
|
||||||
-- nvim_lsp.ccls.setup {}
|
-- nvim_lsp.ccls.setup {}
|
||||||
nvim_lsp.pyright.setup{}
|
nvim_lsp.pyright.setup{}
|
||||||
@ -12,7 +25,6 @@ nvim_lsp.groovyls.setup{
|
|||||||
cmd = { "java", "-jar", "D:/tmp/groovy-language-server/build/libs/groovy-language-server-all.jar" }
|
cmd = { "java", "-jar", "D:/tmp/groovy-language-server/build/libs/groovy-language-server-all.jar" }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
-- Add additional capabilities supported by nvim-cmp
|
-- Add additional capabilities supported by nvim-cmp
|
||||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
capabilities.textDocument.completion.completionItem.documentationFormat = { 'markdown', 'plaintext' }
|
capabilities.textDocument.completion.completionItem.documentationFormat = { 'markdown', 'plaintext' }
|
||||||
@ -91,7 +103,7 @@ local on_attach = function(client, bufnr)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
|
-- Enable some language servers with the additional completion capabilities offered by nvim-cmp
|
||||||
local servers = { 'clangd', 'pyright', 'cmake', 'jsonls' }
|
local servers = {'clangd', 'pyright', 'cmake', 'jsonls'}
|
||||||
for _, lsp in ipairs(servers) do
|
for _, lsp in ipairs(servers) do
|
||||||
nvim_lsp[lsp].setup {
|
nvim_lsp[lsp].setup {
|
||||||
on_attach = on_attach,
|
on_attach = on_attach,
|
||||||
@ -99,6 +111,19 @@ for _, lsp in ipairs(servers) do
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
nvim_lsp.sumneko_lua.setup{
|
||||||
|
cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"},
|
||||||
|
on_attach = on_attach,
|
||||||
|
capabilities = capabilities,
|
||||||
|
}
|
||||||
|
|
||||||
|
nvim_lsp.groovyls.setup{
|
||||||
|
-- Unix
|
||||||
|
cmd = { "java", "-jar", "D:/tmp/groovy-language-server/build/libs/groovy-language-server-all.jar" },
|
||||||
|
on_attach = on_attach,
|
||||||
|
capabilities = capabilities,
|
||||||
|
}
|
||||||
|
|
||||||
local signs = { Error = " ", Warning = " ", Hint = " ", Information = " " }
|
local signs = { Error = " ", Warning = " ", Hint = " ", Information = " " }
|
||||||
for type, icon in pairs(signs) do
|
for type, icon in pairs(signs) do
|
||||||
local hl = "LspDiagnosticsSign" .. type
|
local hl = "LspDiagnosticsSign" .. type
|
||||||
|
Loading…
x
Reference in New Issue
Block a user