Skip to content

Commit

Permalink
feat: Make setup easier
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdevries committed Aug 25, 2021
1 parent e9587cd commit 935efd3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,7 @@ require'cmp'.setup {

-- The nvim-cmp almost supports LSP's capabilities so You should advertise it to LSP servers..
local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
capabilities.textDocument.completion.completionItem.preselectSupport = true
capabilities.textDocument.completion.completionItem.insertReplaceSupport = true
capabilities.textDocument.completion.completionItem.labelDetailsSupport = true
capabilities.textDocument.completion.completionItem.deprecatedSupport = true
capabilities.textDocument.completion.completionItem.commitCharactersSupport = true
capabilities.textDocument.completion.completionItem.tagSupport = { valueSet = { 1 } }
capabilities.textDocument.completion.completionItem.resolveSupport = {
properties = {
'documentation',
'detail',
'additionalTextEdits',
}
}
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)

-- The following example advertise capabilities to `clangd`.
require'lspconfig'.clangd.setup {
Expand Down
28 changes: 28 additions & 0 deletions lua/cmp_nvim_lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,34 @@ M.setup = function()
]])
end

local if_nil = function(val, default)
if val == nil then return default end
return val
end

M.update_capabilities = function(capabilities, override)
override = override or {}

local completionItem = capabilities.textDocument.completion.completionItem

completionItem.snippetSupport = if_nil(override.snippetSupport, true)
completionItem.preselectSupport = if_nil(override.preselectSupport, true)
completionItem.insertReplaceSupport = if_nil(override.insertReplaceSupport, true)
completionItem.labelDetailsSupport = if_nil(override.labelDetailsSupport, true)
completionItem.deprecatedSupport = if_nil(override.deprecatedSupport, true)
completionItem.commitCharactersSupport = if_nil(override.commitCharactersSupport, true)
completionItem.tagSupport = if_nil(override.tagSupport, { valueSet = { 1 } })
completionItem.resolveSupport = if_nil(override.resolveSupport, {
properties = {
'documentation',
'detail',
'additionalTextEdits',
}
})

return capabilities
end

---Refresh sources on InsertEnter.
M._on_insert_enter = function()
local allowed_clients = {}
Expand Down

0 comments on commit 935efd3

Please sign in to comment.