1
0
Fork 0
chezmoi/dot_config/nvim/lua/configs/packages/lsp.lua

193 lines
5.8 KiB
Lua

local M = {
'neovim/nvim-lspconfig',
dependencies = {
'folke/neodev.nvim',
'b0o/schemastore.nvim',
'SmiteshP/nvim-navic',
{ 'j-hui/fidget.nvim', config = true },
},
keys = {
{'<Space>li', '<Cmd>LspInfo<CR>', desc = 'Lsp info' },
{'<Space>ll', '<Cmd>LspLog<CR>', desc = 'Lsp log' },
},
lazy = false
}
function M.config()
require('neodev').setup({})
local formatting_filter = function(c)
local bl = {
'phpactor'
}
for _, name in ipairs(bl) do
if c.name == name then
return false;
end
end
return true
end
local function on_attach(args)
-- require "lsp_signature".on_attach()
-- require'completion'.on_attach()
local bufnr = args.buf
local client = vim.lsp.get_client_by_id(args.data.client_id)
if (client.server_capabilities.documentSymbolProvider) then
require('nvim-navic').attach(client, bufnr)
end
-- Mappings.
local opts = { noremap = true, silent = true, buffer = args.buf }
local mkOpts = function(desc)
return { noremap = true, silent = true, buffer = args.buf, desc = desc }
end
-- use LSP default tagfunc
-- 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, mkOpts('LSP declaration'))
end
if client.supports_method('textDocument/hover') and client.name ~= 'null-ls' then
vim.keymap.set('n', 'K', vim.lsp.buf.hover, mkOpts('LSP hover'))
end
if client.server_capabilities.implementationProvider then
vim.keymap.set('n', 'gi', vim.lsp.buf.implementation, mkOpts('LSP implementation'))
end
if client.server_capabilities.signatureHelpProvider then
vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, mkOpts('LSP signature help'))
vim.keymap.set('i', '<C-k>', vim.lsp.buf.signature_help, mkOpts('LSP signature help'))
end
vim.keymap.set('n', '<space>D', vim.lsp.buf.type_definition, mkOpts('LSP type definition'))
vim.keymap.set('n', '<space>rn', vim.lsp.buf.rename, mkOpts('LSP rename'))
vim.keymap.set('n', '<space>ca', vim.lsp.buf.code_action, mkOpts('LSP Code action'))
vim.keymap.set('v', '<space>ca', vim.lsp.buf.code_action, mkOpts('LSP Code action'))
vim.keymap.set('n', 'gr', vim.lsp.buf.references, mkOpts('LSP references'))
vim.keymap.set('n', '<space>F', function() vim.lsp.buf.format({ async = true, filter = formatting_filter, }) end, opts)
if (formatting_filter(client)) then
vim.api.nvim_buf_set_option(bufnr, 'formatexpr', 'v:lua.vim.lsp.formatexpr(#{timeout_ms:250})')
end
end
vim.api.nvim_create_autocmd('LspAttach', {
callback = on_attach
})
local nvim_lsp = require('lspconfig')
local capabilities = require('cmp_nvim_lsp').default_capabilities()
-- 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 = capabilities
}
end
require('lspconfig').jsonls.setup {
capabilities = 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').yamlls.setup {
capabilities = capabilities,
settings = {
validate = { enable = true },
json = {
schemas = require('schemastore').json.schemas {},
},
},
}
require 'lspconfig'.phpactor.setup {
-- on_attach = M.on_attach,
capabilities = 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, 'sharedLibs'))
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 = capabilities,
}
require 'lspconfig'.powershell_es.setup {
bundle_path = '/home/vladimir/devel/PowerShellEditorServices/module',
capabilities = capabilities,
}
--[[ local util = require("lspconfig.util")
require("lspconfig.configs").coffeesense = {
default_config = {
cmd = { '/home/vladimir/devel/coffeesense/server/bin/coffeesense-language-server' },
filetypes = { 'coffee' },
root_dir = function(pattern)
local cwd = vim.loop.cwd()
local root = util.root_pattern('package.json', '.git')(pattern)
-- prefer cwd if root is a descendant
return util.path.is_descendant(cwd, root) and cwd or root
end,
}
}
require("lspconfig").coffeesense.setup({}) ]]
end
return M