Support auto-completion with LSP

This commit is contained in:
ItsDrike 2021-12-09 00:54:06 +01:00
parent 50a139f0f0
commit f7516182c3
No known key found for this signature in database
GPG key ID: FB8CA11A2CF3A843
2 changed files with 23 additions and 2 deletions

View file

@ -65,7 +65,14 @@ local plugin_list = {
{ {
"williamboman/nvim-lsp-installer", "williamboman/nvim-lsp-installer",
config = get_plugin_file("lsp.lua"), config = get_plugin_file("lsp.lua"),
requires = { "neovim/nvim-lspconfig" }, requires = {
"neovim/nvim-lspconfig",
"hrsh7th/nvim-cmp",
"hrsh7th/cmp-nvim-lsp",
"hrsh7th/cmp-buffer",
"hrsh7th/cmp-path",
"hrsh7th/cmp-cmdline",
},
}, },
--{ --{
-- "nvim-telescope/telescope.nvim", -- "nvim-telescope/telescope.nvim",

View file

@ -10,6 +10,19 @@ local fn = vim.fn
require("lsp") require("lsp")
-- Configure nvim-cmp to respect LSP completions.
local cmp = require("cmp")
cmp.setup({
sources = {
{ name = "nvim_lsp" }
}
})
-- The nvim-cmp almost supports LSP's capabilities so you should advertise it to LSP servers
local cmp_capabilities = vim.lsp.protocol.make_client_capabilities()
cmp_capabilities = require("cmp_nvim_lsp").update_capabilities(cmp_capabilities)
-- Load in the needed settigns for nvim-lsp-installer plugin. -- Load in the needed settigns for nvim-lsp-installer plugin.
-- This ensures automatic installation for the individual language servers. -- This ensures automatic installation for the individual language servers.
local lsp_installer = require("nvim-lsp-installer") local lsp_installer = require("nvim-lsp-installer")
@ -56,7 +69,8 @@ for _, requested_server in pairs(requested_servers) do
if server_available then if server_available then
-- Setup the server once it will become ready -- Setup the server once it will become ready
server:on_ready(function() server:on_ready(function()
local opts = {} -- Advertise completion capabilities by nvim-cmp
local opts = { capabilities = cmp_capabilities }
server:setup(opts) server:setup(opts)
end) end)
-- If the server isn't yet installed, schedule the installation -- If the server isn't yet installed, schedule the installation