Rebuilding config
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
vim.opt.completeopt = {'menu', 'menuone', 'noselect'}
|
||||
local cmp = require('cmp')
|
||||
|
||||
if cmp ~= nil then
|
||||
|
||||
local select_opts = {behavior = cmp.SelectBehavior.Select}
|
||||
|
||||
cmp.setup({
|
||||
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
|
||||
end,
|
||||
},
|
||||
|
||||
sources = {
|
||||
-- l'ordine indica la priorità o aggiungere `priority = k`
|
||||
{ name = 'luasnip' },
|
||||
{ name = 'nvim_lsp', keyword_length = 3,
|
||||
-- Disable LSP snippets
|
||||
entry_filter = function(entry)
|
||||
return require("cmp").lsp.CompletionItemKind.Snippet ~= entry:get_kind()
|
||||
end },
|
||||
{ name = 'buffer', keyword_length = 3 },
|
||||
{ name = 'path' },
|
||||
{ name = 'nvim_lua' },
|
||||
},
|
||||
|
||||
window = {
|
||||
completion = {
|
||||
scrolloff = 2
|
||||
},
|
||||
documentation = {
|
||||
max_width = 80
|
||||
}
|
||||
},
|
||||
|
||||
formatting = {
|
||||
fields = { 'abbr', 'kind', 'menu' },
|
||||
format = function(entry, item)
|
||||
local menu_icon = {
|
||||
nvim_lsp = '[LSP]',
|
||||
luasnip = '[Snip]',
|
||||
buffer = '[Buf]',
|
||||
path = '[Path]',
|
||||
latex_symbols = '[LaTeX]',
|
||||
nvim_lua = '[Lua]'
|
||||
}
|
||||
|
||||
item.menu = menu_icon[entry.source.name]
|
||||
|
||||
if (string.len(item.abbr) > 50) then
|
||||
item.abbr = string.sub(item.abbr, 1, 50) .. ".."
|
||||
end
|
||||
|
||||
return item
|
||||
end,
|
||||
},
|
||||
|
||||
mapping = {
|
||||
['<C-p>'] = cmp.mapping.select_prev_item(select_opts),
|
||||
['<C-n>'] = cmp.mapping.select_next_item(select_opts),
|
||||
|
||||
['<C-u>'] = cmp.mapping.scroll_docs(-4),
|
||||
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||
|
||||
--['<C-e>'] = cmp.mapping.abort(), -- cmp.mapping.close()
|
||||
|
||||
['<CR>'] = cmp.mapping.confirm({select = true}),
|
||||
['<C-y>'] = cmp.mapping.confirm({select = true}),
|
||||
|
||||
--['<C-Space>'] = cmp.mapping.complete(),
|
||||
['<C-Space>'] = function()
|
||||
if cmp.visible() then
|
||||
cmp.abort()
|
||||
else
|
||||
cmp.complete()
|
||||
end
|
||||
end
|
||||
|
||||
--['<Tab>'] = cmp.mapping(function(fallback)
|
||||
|
||||
-- local col = vim.fn.col('.') - 1
|
||||
|
||||
-- if cmp.visible() then
|
||||
-- cmp.select_next_item(select_opts)
|
||||
-- elseif col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
|
||||
-- fallback()
|
||||
-- else
|
||||
-- cmp.complete()
|
||||
-- end
|
||||
--end, {'i', 's'}),
|
||||
|
||||
--['<S-Tab>'] = cmp.mapping(function(fallback)
|
||||
-- if cmp.visible() then
|
||||
-- cmp.select_prev_item(select_opts)
|
||||
-- else
|
||||
-- fallback()
|
||||
-- end
|
||||
--end, {'i', 's'}),
|
||||
},
|
||||
})
|
||||
|
||||
end
|
||||
@@ -0,0 +1,151 @@
|
||||
-- Global configuration
|
||||
local lsp_defaults = {
|
||||
flags = {
|
||||
debounce_text_changes = 150,
|
||||
},
|
||||
capabilities = require('cmp_nvim_lsp').default_capabilities(
|
||||
vim.lsp.protocol.make_client_capabilities()
|
||||
),
|
||||
}
|
||||
|
||||
local lspconfig = require('lspconfig')
|
||||
|
||||
lspconfig.util.default_config = vim.tbl_deep_extend(
|
||||
'force',
|
||||
lspconfig.util.default_config,
|
||||
lsp_defaults
|
||||
)
|
||||
|
||||
-- Disable lsp messages over text
|
||||
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
|
||||
vim.lsp.diagnostic.on_publish_diagnostics, {
|
||||
signs = false,
|
||||
virtual_text = false,
|
||||
}
|
||||
)
|
||||
|
||||
-- Show diagnostic window when cursor is over error
|
||||
vim.o.updatetime = 250
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
command = [[autocmd! CursorHold * lua vim.diagnostic.open_float(nil, {focus=false, scope="cursor"})]],
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
desc = 'LSP Keybinds',
|
||||
|
||||
callback = function(ev)
|
||||
local bufmap = function(mode, keys, func)
|
||||
local opts = {buffer = 0}
|
||||
vim.keymap.set(mode, keys, func, opts)
|
||||
end
|
||||
|
||||
bufmap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>')
|
||||
bufmap('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>')
|
||||
bufmap('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>')
|
||||
bufmap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>')
|
||||
bufmap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>')
|
||||
bufmap('n', '<leader>rn', '<cmd>lua vim.lsp.buf.rename()<cr>')
|
||||
bufmap({'n', 'v'}, '<leader>ca', '<cmd>lua vim.lsp.buf.code_action()<cr>')
|
||||
|
||||
bufmap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<cr>')
|
||||
bufmap('n', '<C-h>', '<cmd>lua vim.diagnostic.setloclist()<cr>')
|
||||
bufmap('n', '<C-p>', '<cmd>lua vim.diagnostic.goto_prev()<cr>')
|
||||
bufmap('n', '<C-n>', '<cmd>lua vim.diagnostic.goto_next()<cr>')
|
||||
-- Jumps to the definition of the type symbol
|
||||
--bufmap('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>')
|
||||
--print(string.format('event fired: %s', vim.inspect(ev)))
|
||||
|
||||
bufmap('n', '<leader>sa', '<cmd>vim.lsp.buf.add_workspace_folder<cr>')
|
||||
bufmap('n', '<leader>sr', '<cmd>vim.lsp.buf.remove_workspace_folder<cr>')
|
||||
bufmap('n', '<leader>sl', function()
|
||||
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
|
||||
end)
|
||||
|
||||
end,
|
||||
})
|
||||
|
||||
-- Lsp autoformat file
|
||||
vim.api.nvim_create_autocmd('LspAttach', {
|
||||
command = [[lua vim.api.nvim_buf_create_user_command(0, 'Format',
|
||||
function()
|
||||
vim.lsp.buf.format()
|
||||
end, { desc = 'Format current buffer with LSP' })
|
||||
]]
|
||||
})
|
||||
|
||||
-- Lsp server init
|
||||
|
||||
-- https://pypi.org/project/pyright/
|
||||
require'lspconfig'.pyright.setup{}
|
||||
|
||||
-- require'lspconfig'.dockerls.setup{ }
|
||||
|
||||
-- https://github.com/MaskRay/ccls/wiki
|
||||
--require'lspconfig'.ccls.setup {
|
||||
-- init_options = {
|
||||
-- compilationDatabaseDirectory = "build";
|
||||
-- index = {
|
||||
-- threads = 0;
|
||||
-- };
|
||||
-- clang = {
|
||||
-- excludeArgs = { "-frounding-math"} ;
|
||||
-- };
|
||||
-- }
|
||||
--}
|
||||
|
||||
-- require('lspconfig').yamlls.setup {
|
||||
-- settings = {
|
||||
-- yaml = {
|
||||
-- schemas = {
|
||||
-- ["https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.1/schema.yaml"] = "/*.openapi.yaml"
|
||||
-- },
|
||||
-- },
|
||||
-- }
|
||||
-- }
|
||||
|
||||
-- https://github.com/golang/tools/tree/master/gopls
|
||||
require'lspconfig'.gopls.setup{
|
||||
cmd = {'gopls', '--remote=auto'}
|
||||
}
|
||||
|
||||
-- https://clangd.llvm.org/installation.html
|
||||
require'lspconfig'.clangd.setup{}
|
||||
|
||||
-- https://quick-lint-js.com/
|
||||
require'lspconfig'.quick_lint_js.setup{}
|
||||
|
||||
-- require'lspconfig'.vuels.setup{}
|
||||
|
||||
-- npm install -g @angular/language-server
|
||||
-- https://github.com/neovim/nvim-lspconfig/issues/1155#issuecomment-1205680003
|
||||
local npm_path = "/usr/lib/node_modules"
|
||||
local cmd = {"ngserver", "--stdio", "--tsProbeLocations", npm_path , "--ngProbeLocations", npm_path}
|
||||
|
||||
require'lspconfig'.angularls.setup{
|
||||
cmd = cmd,
|
||||
on_new_config = function(new_config,new_root_dir)
|
||||
new_config.cmd = cmd
|
||||
end,
|
||||
}
|
||||
|
||||
-- npm install -g typescript typescript-language-server
|
||||
require'lspconfig'.tsserver.setup{}
|
||||
|
||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||
capabilities.textDocument.completion.completionItem.snippetSupport = true
|
||||
|
||||
-- npm i -g vscode-langservers-extracted
|
||||
require'lspconfig'.html.setup {
|
||||
capabilities = capabilities,
|
||||
filetypes = { "css", "html", "php" }
|
||||
}
|
||||
|
||||
-- npm i -g vscode-langservers-extracted
|
||||
require'lspconfig'.cssls.setup{
|
||||
capabilities = capabilities,
|
||||
filetypes = { "css", "html", "php" }
|
||||
}
|
||||
|
||||
require'lspconfig'.cssmodules_ls.setup{
|
||||
filetypes = { "css", "html", "php" }
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
require('lsp/lsp')
|
||||
require('lsp/cmp_conf')
|
||||
require('lsp/snippets')
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
local bind = vim.keymap.set
|
||||
local ls = require("luasnip")
|
||||
|
||||
local snip = ls.snippet
|
||||
local node = ls.snippet_node
|
||||
local text = ls.text_node
|
||||
local insert = ls.insert_node
|
||||
local func = ls.function_node
|
||||
local choice = ls.choice_node
|
||||
local dynamicn = ls.dynamic_node
|
||||
|
||||
local fmt = require('luasnip.extras.fmt').fmt
|
||||
|
||||
ls.config.set_config({
|
||||
history = true,
|
||||
updateevents = "TextChanged, TextChangedI",
|
||||
enable_autosnippets = true,
|
||||
})
|
||||
|
||||
-- Lua snips
|
||||
bind({"i", "s"}, "<C-l>", function()
|
||||
if ls.expand_or_jumpable() then
|
||||
ls.expand_or_jump()
|
||||
end
|
||||
end)
|
||||
|
||||
bind({"i", "s"}, "<C-h>", function()
|
||||
if ls.jumpable(-1) then
|
||||
ls.jump(-1)
|
||||
end
|
||||
end, {silent = true})
|
||||
|
||||
bind({"i", "s"}, "<C-k>", function()
|
||||
if ls.choice_active() then
|
||||
ls.change_choice(1)
|
||||
end
|
||||
end, {silent = true})
|
||||
|
||||
ls.add_snippets(nil, {
|
||||
all = {
|
||||
snip({
|
||||
trig = "ternary",
|
||||
},
|
||||
{
|
||||
-- equivalent to "${1:cond} ? ${2:then} : ${3:else}"
|
||||
insert(1, "cond"), text(" ? "), insert(2, "then"), text(" : "), insert(3, "else")
|
||||
}),
|
||||
},
|
||||
sh = {
|
||||
snip({
|
||||
trig = "shebang-bash",
|
||||
namr = "Shebang bash",
|
||||
dscr = "Shebang for bash",
|
||||
},
|
||||
{
|
||||
text { "#!/bin/bash", ""},
|
||||
insert(0),
|
||||
}),
|
||||
|
||||
snip({
|
||||
trig = "shebang-shell",
|
||||
namr = "Shebang shell",
|
||||
dscr = "Shebang for shell"
|
||||
},
|
||||
{
|
||||
text { "#!/bin/sh", ""},
|
||||
insert(0),
|
||||
}),
|
||||
},
|
||||
|
||||
typescript = ({
|
||||
snip({
|
||||
trig = "cfunction",
|
||||
namr = "Class typed function",
|
||||
},
|
||||
fmt([[{} {}({}): {}{{{}}}]],
|
||||
{
|
||||
choice(1,
|
||||
{
|
||||
text(""),
|
||||
text("private"),
|
||||
text("public")
|
||||
}),
|
||||
insert(2, "func"),
|
||||
insert(3, "params"),
|
||||
insert(4, "return_type"),
|
||||
insert(5),
|
||||
})
|
||||
),
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
require("luasnip.loaders.from_vscode").lazy_load()
|
||||
Reference in New Issue
Block a user