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

267 lines
10 KiB
Lua

local function formatting_filter(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 function mkOpts(desc)
return { noremap = true, silent = true, buffer = args.buf, desc = desc }
end
-- null-ls has mostly no hover and therefore trashes manpages for shell
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.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
if client.server_capabilities.codeLensProvider then
vim.api.nvim_create_autocmd(
{ 'BufEnter', 'CursorHold', 'InsertLeave', }, {
callback = vim.lsp.codelens.refresh,
buffer = bufnr,
})
end
vim.keymap.set('n', '<leader>cl', vim.lsp.codelens.run, mkOpts('LSP Run code lens'))
vim.keymap.set('n', '<leader>ci', vim.lsp.buf.implementation, mkOpts('LSP implementation'))
vim.keymap.set('n', '<leader>cd', vim.lsp.buf.type_definition, mkOpts('LSP type definition'))
vim.keymap.set('n', '<leader>cD', vim.lsp.buf.declaration, mkOpts('LSP declaration'))
vim.keymap.set('n', '<leader>cR', vim.lsp.buf.rename, mkOpts('LSP rename'))
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, mkOpts('LSP Code action'))
vim.keymap.set('v', '<leader>ca', vim.lsp.buf.code_action, mkOpts('LSP Code action'))
vim.keymap.set('n', '<leader>cci', vim.lsp.buf.incoming_calls, mkOpts('LSP incoming calls'))
vim.keymap.set('n', '<leader>cco', vim.lsp.buf.outgoing_calls, mkOpts('LSP outgoing calls'))
-- vim.keymap.set('n', 'gr', vim.lsp.buf.references, mkOpts('LSP references'))
vim.keymap.set('n', '<leader>cr', '<Cmd>Trouble lsp_references<CR>', mkOpts('LSP references'))
vim.keymap.set(
{ 'v', 'n' }, '<leader>F', function()
vim.lsp.buf.format({ async = true, filter = formatting_filter, })
end,
mkOpts('Lsp Format')
)
if (formatting_filter(client)) then
vim.api.nvim_buf_set_option(bufnr, 'formatexpr', 'v:lua.vim.lsp.formatexpr(#{timeout_ms:250})')
end
if client.name == 'omnisharp' then
client.server_capabilities.semanticTokensProvider.legend = {
tokenModifiers = { 'static' },
tokenTypes = {
'comment', -- "comment",
'comment', -- "excluded_code",
'identifier', -- "identifier",
'keyword', -- "keyword",
'keyword', -- "keyword_control",
'number', -- "number",
'operator', -- "operator",
'operator', -- "operator_overloaded",
'preproc', -- "preprocessor_keyword",
'string', -- "string",
'whitespace', -- "whitespace",
'text', -- "text",
'static', -- "static_symbol",
'preproc', -- "preprocessor_text",
'punctuation', -- "punctuation",
'string.escape', -- "string_verbatim",
'character.special', -- "string_escape_character",
'class', -- "class_name",
'type', -- "delegate_name",
'enum', -- "enum_name",
'interface', -- "interface_name",
'namespace', -- "module_name",
'struct', -- "struct_name",
'typeParameter', -- "type_parameter_name",
'field', -- "field_name",
'enumMember', -- "enum_member_name",
'constant', -- "constant_name",
'variable', -- "local_name",
'parameter', -- "parameter_name",
'method', -- "method_name",
'method', -- "extension_method_name",
'property', -- "property_name",
'event', -- "event_name",
'namespace', -- "namespace_name",
'label', -- "label_name",
'text.literal', -- "xml_doc_comment_attribute_name",
'text.literal', -- "xml_doc_comment_attribute_quotes",
'text.literal', -- "xml_doc_comment_attribute_value",
'text.literal', -- "xml_doc_comment_cdata_section",
'text.literal', -- "xml_doc_comment_comment",
'text.literal', -- "xml_doc_comment_delimiter",
'text.literal', -- "xml_doc_comment_entity_reference",
'text.literal', -- "xml_doc_comment_name",
'text.literal', -- "xml_doc_comment_processing_instruction",
'text.literal', -- "xml_doc_comment_text",
'text.literal', -- "xml_literal_attribute_name",
'text.literal', -- "xml_literal_attribute_quotes",
'text.literal', -- "xml_literal_attribute_value",
'text.literal', -- "xml_literal_cdata_section",
'text.literal', -- "xml_literal_comment",
'text.literal', -- "xml_literal_delimiter",
'text.literal', -- "xml_literal_embedded_expression",
'text.literal', -- "xml_literal_entity_reference",
'text.literal', -- "xml_literal_name",
'text.literal', -- "xml_literal_processing_instruction",
'text.literal', -- "xml_literal_text",
'regexp', -- "regex_comment",
'regexp', -- "regex_character_class",
'regexp', -- "regex_anchor",
'regexp', -- "regex_quantifier",
'regexp', -- "regex_grouping",
'regexp', -- "regex_alternation",
'regexp', -- "regex_text",
'regexp', -- "regex_self_escaped_character",
'regexp' -- "regex_other_escape",
},
}
end
end -- }}}
local function config()
require('neodev').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 = {
powershell_es = { bundle_path = '/home/vladimir/devel/PowerShellEditorServices/module' },
gopls = {},
clangd = {},
zls = {},
hls = {},
tsserver = {},
perlls = {},
rust_analyzer = {},
cssls = {},
html = {},
omnisharp = { -- {{{
handlers = {
['textDocument/definition'] = require('omnisharp_extended').handler,
},
cmd = { '/usr/bin/omnisharp' },
enable_editorconfig_support = true,
enable_ms_build_load_projects_on_demand = false,
enable_roslyn_analyzers = true,
organize_imports_on_format = true,
enable_import_completion = true,
sdk_include_prereleases = true,
analyze_open_documents_only = true,
}, -- }}}
sumneko_lua = { -- {{{
settings = {
Lua = {
workleader = {
checkThirdParty = false,
},
completion = {
callSnippet = 'Replace',
},
},
},
}, -- }}}
phpactor = { -- {{{
handlers = {
['textDocument/publishDiagnostics'] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
virtual_text = {
severity = vim.diagnostic.severity.ERROR,
}
}
),
},
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
}, -- }}}
yamlls = { -- {{{
settings = {
validate = { enable = true },
json = {
schemas = require('schemastore').json.schemas {},
},
},
}, -- }}}
jsonls = { -- {{{
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',
}
},
},
},
},
},
}, -- }}}
}
local capabilities = require('cmp_nvim_lsp').default_capabilities()
for name, conf in pairs(servers) do
conf.capabilities = capabilities
nvim_lsp[name].setup(conf)
end
end
return {
{
'neovim/nvim-lspconfig',
dependencies = {
{ 'j-hui/fidget.nvim', config = true },
{ 'ray-x/lsp_signature.nvim', opts = { hint_prefix = '', floating_window = false, hint_scheme = 'Identifier' } },
},
keys = {
{ '<leader>li', '<Cmd>LspInfo<CR>', desc = 'Lsp info' },
{ '<leader>ll', '<Cmd>LspLog<CR>', desc = 'Lsp log' },
},
event = 'BufRead',
config = config,
},
{ 'SmiteshP/nvim-navic', lazy = true },
{ 'Hoffs/omnisharp-extended-lsp.nvim', lazy = true },
{ 'b0o/schemastore.nvim', lazy = true },
{ 'folke/neodev.nvim', lazy = true }
}