125 lines
4.5 KiB
Lua
125 lines
4.5 KiB
Lua
local M = {}
|
|
local function on_attach(args)
|
|
-- require "lsp_signature".on_attach()
|
|
-- require'completion'.on_attach()
|
|
|
|
|
|
local client = vim.lsp.get_client_by_id(args.data.client_id)
|
|
-- Mappings.
|
|
local opts = { noremap = true, silent = true, buffer = args.buf }
|
|
|
|
if client.server_capabilities.definitionProvider then
|
|
vim.keymap.set('n', 'gd', vim.lsp.buf.definition, opts)
|
|
end
|
|
if client.server_capabilities.declarationProvider then
|
|
vim.keymap.set('n', 'gD', vim.lsp.buf.declaration, opts)
|
|
end
|
|
if client.supports_method("textDocument/hover") then
|
|
vim.keymap.set('n', 'K', vim.lsp.buf.hover, opts)
|
|
end
|
|
if client.server_capabilities.implementationProvider then
|
|
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, opts)
|
|
end
|
|
|
|
if client.server_capabilities.signatureHelpProvider then
|
|
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
|
|
vim.keymap.set('i', '<C-k>', vim.lsp.buf.signature_help, opts)
|
|
end
|
|
|
|
vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
|
|
vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
|
|
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, opts)
|
|
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, opts)
|
|
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, opts)
|
|
vim.keymap.set('v', '<space>ca', vim.lsp.buf.range_code_action, opts)
|
|
vim.keymap.set('n', 'gr', vim.lsp.buf.references, opts)
|
|
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
|
|
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, opts)
|
|
vim.keymap.set('n', '<space>q', vim.diagnostic.setloclist, opts)
|
|
vim.keymap.set('n', '<space>F', function() vim.lsp.buf.format({ async = true }) end, opts)
|
|
vim.keymap.set('v', '<space>F', vim.lsp.buf.range_formatting, opts)
|
|
end
|
|
|
|
function M.setup()
|
|
require("lua-dev").setup({})
|
|
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
callback = on_attach
|
|
})
|
|
|
|
local nvim_lsp = require('lspconfig')
|
|
|
|
-- Use a loop to conveniently both setup defined servers
|
|
-- and map buffer local keybindings when the language server attaches
|
|
local servers = {
|
|
'phpactor',
|
|
'gopls',
|
|
'clangd',
|
|
'zls',
|
|
'hls',
|
|
'tsserver',
|
|
'sumneko_lua',
|
|
'perlls',
|
|
'rust_analyzer',
|
|
'cssls',
|
|
'html',
|
|
}
|
|
for _, lsp in ipairs(servers) do
|
|
nvim_lsp[lsp].setup {
|
|
on_attach = M.on_attach,
|
|
capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()),
|
|
}
|
|
end
|
|
|
|
require('lspconfig').jsonls.setup {
|
|
-- on_attach = M.on_attach,
|
|
capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()),
|
|
settings = {
|
|
validate = { enable = true },
|
|
json = {
|
|
schemas = require('schemastore').json.schemas {
|
|
replace = {
|
|
['openapi.json'] = {
|
|
description = 'A JSON schema for Open API documentation files',
|
|
fileMatch = { "openapi.json", "openapi.yml", "openapi.yaml", "openapi/*.json" },
|
|
name = 'openapi.json',
|
|
url = 'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.json',
|
|
versions = {
|
|
["3.1"] = "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.1/schema.json",
|
|
["3.0"] = "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.json",
|
|
}
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
require 'lspconfig'.phpactor.setup {
|
|
-- on_attach = M.on_attach,
|
|
capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities()),
|
|
|
|
root_dir = function(startpath)
|
|
local u = require('lspconfig.util')
|
|
return u.search_ancestors(startpath, function(path)
|
|
return not string.find(path, '/vendor/') and (
|
|
u.path.exists(u.path.join(path, 'composer.json'))
|
|
or u.path.exists(u.path.join(path, '.git'))
|
|
)
|
|
end)
|
|
end
|
|
}
|
|
|
|
require 'lspconfig'.omnisharp.setup {
|
|
cmd = { '/usr/bin/omnisharp', '--languageserver', '--hostPID', tostring(pid) },
|
|
-- on_attach = M.on_attach,
|
|
capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
|
|
}
|
|
|
|
require 'lspconfig'.powershell_es.setup {
|
|
bundle_path = '/home/vladimir/devel/PowerShellEditorServices/module',
|
|
capabilities = require('cmp_nvim_lsp').update_capabilities(vim.lsp.protocol.make_client_capabilities())
|
|
}
|
|
end
|
|
|
|
return M
|