234 lines
7.9 KiB
Lua
234 lines
7.9 KiB
Lua
local M = {
|
|
'neovim/nvim-lspconfig',
|
|
dependencies = {
|
|
'folke/neodev.nvim',
|
|
'b0o/schemastore.nvim',
|
|
'SmiteshP/nvim-navic',
|
|
{ 'j-hui/fidget.nvim', config = true },
|
|
{ 'ray-x/lsp_signature.nvim', opts = { hint_prefix = '⥊ ', floating_window = false, hint_scheme = 'Identifier' } },
|
|
'hrsh7th/nvim-cmp',
|
|
},
|
|
keys = {
|
|
{ '<Space>li', '<Cmd>LspInfo<CR>', desc = 'Lsp info' },
|
|
{ '<Space>ll', '<Cmd>LspLog<CR>', desc = 'Lsp log' },
|
|
},
|
|
lazy = false
|
|
}
|
|
|
|
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 opts = { noremap = true, silent = true, buffer = args.buf }
|
|
local function mkOpts(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
|
|
|
|
if client.server_capabilities.codeLensProvider then
|
|
vim.api.nvim_create_autocmd(
|
|
{ 'BufEnter', 'CursorHold', 'InsertLeave' }, {
|
|
callback = vim.lsp.codelens.refresh,
|
|
buffer = bufnr,
|
|
})
|
|
vim.keymap.set('n', '<space>cl', vim.lsp.codelens.run, mkOpts('LSP Run code lens'))
|
|
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', 'gr', '<Cmd>Trouble lsp_references<CR>', 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 -- }}}
|
|
|
|
function M.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 = { -- {{{
|
|
cmd = { '/usr/bin/omnisharp' },
|
|
-- Enables support for reading code style, naming convention and analyzer
|
|
-- settings from .editorconfig.
|
|
enable_editorconfig_support = true,
|
|
|
|
-- If true, MSBuild project system will only load projects for files that
|
|
-- were opened in the editor. This setting is useful for big C# codebases
|
|
-- and allows for faster initialization of code navigation features only
|
|
-- for projects that are relevant to code that is being edited. With this
|
|
-- setting enabled OmniSharp may load fewer projects and may thus display
|
|
-- incomplete reference lists for symbols.
|
|
enable_ms_build_load_projects_on_demand = false,
|
|
|
|
-- Enables support for roslyn analyzers, code fixes and rulesets.
|
|
enable_roslyn_analyzers = true,
|
|
|
|
-- Specifies whether 'using' directives should be grouped and sorted during
|
|
-- document formatting.
|
|
organize_imports_on_format = true,
|
|
|
|
-- Enables support for showing unimported types and unimported extension
|
|
-- methods in completion lists. When committed, the appropriate using
|
|
-- directive will be added at the top of the current file. This option can
|
|
-- have a negative impact on initial completion responsiveness,
|
|
-- particularly for the first few completion sessions after opening a
|
|
-- solution.
|
|
enable_import_completion = true,
|
|
|
|
-- Specifies whether to include preview versions of the .NET SDK when
|
|
-- determining which version to use for project loading.
|
|
sdk_include_prereleases = true,
|
|
|
|
-- Only run analyzers against open files when 'enableRoslynAnalyzers' is
|
|
-- true
|
|
analyze_open_documents_only = true,
|
|
|
|
}, -- }}}
|
|
sumneko_lua = { -- {{{
|
|
settings = {
|
|
Lua = {
|
|
workspace = {
|
|
checkThirdParty = false,
|
|
},
|
|
completion = {
|
|
callSnippet = 'Replace',
|
|
},
|
|
},
|
|
},
|
|
}, -- }}}
|
|
phpactor = { -- {{{
|
|
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
|
|
|
|
--[[ 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
|