Fix scope issues in lspconfig

This commit is contained in:
Marko Korhonen 2022-08-23 19:14:09 +03:00
parent b985e8a28a
commit 0f738beb9b
No known key found for this signature in database
GPG Key ID: 911B85FBC6003FE5
3 changed files with 89 additions and 94 deletions

View File

@ -17,4 +17,4 @@ require('jdtls').start_or_attach({
} }
}) })
require('plugins.lspconfig').lsp_map_keys('jdtls', nil) require('plugins.lspconfig').map_keys('jdtls', nil)

View File

@ -1,5 +1,5 @@
require 'plugins/init'
require 'autocmd' require 'autocmd'
require 'keybinds' require 'keybinds'
require 'settings' require 'settings'
require 'common' require 'common'
require 'plugins/init'

View File

@ -1,103 +1,98 @@
local M = {} M = {}
function lsp_map_keys(server, bufnr) function M.map_keys(server, bufnr)
print('lsp_map_keys') local function map_key(...)
local function map_key(...) -- Map to buffer if buffer number is supplied,
-- Map to buffer if buffer number is supplied, -- globally otherwise
-- globally otherwise if bufnr == nil then
if bufnr == nil then vim.api.nvim_set_keymap(...)
vim.api.nvim_set_keymap(...) else
else vim.api.nvim_buf_set_keymap(bufnr, ...)
vim.api.nvim_buf_set_keymap(bufnr, ...) end
end end
end
local keymapOpts = { noremap = true, silent = true } local keymapOpts = {noremap = true, silent = true}
map_key('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', keymapOpts) map_key('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<CR>', keymapOpts)
map_key('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', keymapOpts) map_key('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<CR>', keymapOpts)
map_key('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', keymapOpts) map_key('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', keymapOpts)
map_key('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', keymapOpts) map_key('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', keymapOpts)
map_key('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', map_key('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>',
keymapOpts) keymapOpts)
map_key('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', map_key('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>',
keymapOpts) keymapOpts)
map_key('n', '<space>wr', map_key('n', '<space>wr',
'<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', keymapOpts) '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', keymapOpts)
map_key('n', '<space>wl', map_key('n', '<space>wl',
'<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>',
keymapOpts) keymapOpts)
map_key('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', map_key('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>',
keymapOpts) keymapOpts)
map_key('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', keymapOpts) map_key('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', keymapOpts)
map_key('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', map_key('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>',
keymapOpts) keymapOpts)
map_key('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', keymapOpts) map_key('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', keymapOpts)
map_key('n', '<space>e', map_key('n', '<space>e',
'<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>',
keymapOpts) keymapOpts)
map_key('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', keymapOpts) map_key('n', '[d', '<cmd>lua vim.diagnostic.goto_prev()<CR>', keymapOpts)
map_key('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', keymapOpts) map_key('n', ']d', '<cmd>lua vim.diagnostic.goto_next()<CR>', keymapOpts)
map_key('n', '<space>q', '<cmd>lua vim.diagnostic.set_loclist()<CR>', map_key('n', '<space>q', '<cmd>lua vim.diagnostic.set_loclist()<CR>',
keymapOpts) keymapOpts)
map_key('n', '<space>f', '<cmd>lua vim.lsp.buf.format()<CR>', keymapOpts) map_key('n', '<space>f', '<cmd>lua vim.lsp.buf.format()<CR>', keymapOpts)
end end
M.on_attach = function(server, bufnr)
print('on_attach')
-- Setup lsp signature plugin
require('lsp_signature').setup {}
-- Setup keybinds
lsp_map_keys(server, bufnr)
end
function M.setup() function M.setup()
local lspconfig = require('lspconfig') -- Pairs of server name and settings.
-- This is iterated through and every
-- server is setup with lspconfig
local servers = {
html = {},
jsonls = {},
marksman = {},
yamlls = {},
tsserver = {},
sumneko_lua = {
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 = vim.split(package.path, ';')
},
diagnostics = {
-- Get the language server to recognize the `vim` global
globals = {'vim'}
},
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}
}
}
}
local capabilities = vim.lsp.protocol.make_client_capabilities() local function on_attach(server, bufnr)
-- Setup lsp signature plugin
require('lsp_signature').setup {}
-- Common settings for all servers -- Setup keybinds
local lsp_defaults = { M.map_keys(server, bufnr)
on_attach = M.on_attach, -- Common on_attach end
capabilities = capabilities -- Add additional capabilities supported by nvim-cmp
}
-- Set default config for all servers -- Setup every defined server
--lspconfig.util.default_config = vim.tbl_deep_extend('force', lspconfig.util.default_config, lsp_defaults) for server, settings in pairs(servers) do
require('lspconfig')[server].setup {
-- Register capabilities to cmp.nvim on_attach = on_attach,
--require('cmp_nvim_lsp').update_capabilities(capabilities) settings = settings,
-- Updates capabilities to cmp.nvim and
-- LSP servers setup -- informs the server about the client capabilities
--lspconfig.tsserver.setup {} capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp
--lspconfig.yamlls.setup {} .protocol
--lspconfig.jsonls.setup {} .make_client_capabilities())
--lspconfig.html.setup {} }
--lspconfig.marksman.setup {} end
--lspconfig.sumneko_lua.setup {
-- 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 = vim.split(package.path, ';')
-- },
-- diagnostics = {
-- -- Get the language server to recognize the `vim` global
-- globals = { 'vim' }
-- },
-- 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 }
-- }
-- }
--}
end end
return M return M