chore: Added lsp capabilities of nvim cmp. It can now do much more as LSPs see

nvim has more functionalities (Show unimported functions etc). Also
added better sorting to cmp entries. Added a notification when LSP
finished loading.
This commit is contained in:
Afonso Franco 2022-12-15 17:43:06 +00:00
parent 6939a13ae0
commit 54485a1dcd
Signed by: afonso
SSH key fingerprint: SHA256:gkVPzsQQJzqi21ntQBV6pXTx4bYI53rFGI4XtvCpwd4
3 changed files with 154 additions and 126 deletions

View file

@ -109,6 +109,13 @@ cmp.setup {
return vim_item return vim_item
end, end,
}, },
sorting = {
comparators = {
cmp.config.compare.exact,
cmp.config.compare.offset,
cmp.config.compare.recently_used,
}
},
sources = { sources = {
{ name = "nvim_lsp" }, { name = "nvim_lsp" },
{ name = "luasnip" }, { name = "luasnip" },
@ -131,5 +138,3 @@ cmp.setup {
native_menu = false, native_menu = false,
}, },
} }

View file

@ -1,10 +1,12 @@
local mason_lspconfig = require "mason-lspconfig" local mason_lspconfig = require "mason-lspconfig"
local notify = require "notify"
mason_lspconfig.setup({ mason_lspconfig.setup({
ensure_installed = { "sumneko_lua", "rust_analyzer", "texlab", "hls", "yamlls" }, ensure_installed = { "sumneko_lua", "rust_analyzer", "texlab", "hls", "yamlls" },
automatic_installation = true automatic_installation = true
}) })
local opts = { noremap = true, silent = true } local opts = { noremap = true, silent = true }
vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts) vim.keymap.set('n', '<space>e', vim.diagnostic.open_float, opts)
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts) vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, opts)
@ -46,15 +48,32 @@ local on_attach = function(client, bufnr)
end end
end end
local on_init = function (client, initialize_result)
-- Alert user that LSP finished loading
notify("Finished loading " ..client.name, "info", {title = "LSP"})
end
local lspconfig = require "lspconfig" local lspconfig = require "lspconfig"
-- ADD NVIM CMP AS A CAPABILITY
local lsp_defaults = lspconfig.util.default_config
local capabilities = vim.tbl_deep_extend(
'force',
lsp_defaults.capabilities,
require('cmp_nvim_lsp').default_capabilities()
)
mason_lspconfig.setup_handlers { mason_lspconfig.setup_handlers {
-- This is a default handler that will be called for each installed server (also for new servers that are installed during a session) -- This is a default handler that will be called for each installed server (also for new servers that are installed during a session)
function(server_name) function(server_name)
lspconfig[server_name].setup { lspconfig[server_name].setup {
on_attach = on_attach, on_attach = on_attach,
on_init = on_init,
flags = lsp_flags, flags = lsp_flags,
capabilities = capabilities,
} }
end, end,
} }

View file

@ -46,6 +46,19 @@ local plugins = packer.startup({ function(use)
vim.notify = require("notify") vim.notify = require("notify")
end end
} }
--------------------------------------------------SUGGESTION BOX-----------------------------------------
use { "hrsh7th/nvim-cmp",
requires = {
'hrsh7th/cmp-nvim-lsp', -- lsp
'hrsh7th/cmp-buffer', --buffer completions
'hrsh7th/cmp-path', --path completions
'hrsh7th/cmp-cmdline' --cmdline completions
},
config = function()
require "plugins.cmp"
end
}
-------------------------------------------------------LSP---------------------------------------------- -------------------------------------------------------LSP----------------------------------------------
use { "williamboman/mason.nvim", use { "williamboman/mason.nvim",
@ -56,6 +69,8 @@ local plugins = packer.startup({ function(use)
use { "williamboman/mason-lspconfig.nvim" } use { "williamboman/mason-lspconfig.nvim" }
use { "hrsh7th/cmp-nvim-lsp"}
use { "neovim/nvim-lspconfig", use { "neovim/nvim-lspconfig",
config = function() config = function()
require "plugins.lspconfig" require "plugins.lspconfig"
@ -74,19 +89,8 @@ local plugins = packer.startup({ function(use)
"saadparwaiz1/cmp_luasnip" "saadparwaiz1/cmp_luasnip"
}, },
} }
--------------------------------------------------SUGGESTION BOX-----------------------------------------
use { "hrsh7th/nvim-cmp",
requires = {
'hrsh7th/cmp-nvim-lsp', -- lsp
'hrsh7th/cmp-buffer', --buffer completions
'hrsh7th/cmp-path', --path completions
'hrsh7th/cmp-cmdline' --cmdline completions
},
config = function()
require "plugins.cmp"
end
}
------------------------------------------------------------------------------------------
use { 'nvim-tree/nvim-tree.lua', use { 'nvim-tree/nvim-tree.lua',
requires = { requires = {