Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

[Refactor]: use nvim-cmp instead of compe #119

Merged
merged 1 commit into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions lua/doom/modules/config/doom-cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,16 @@ return function()
end
local function check_backspace()
local col = vim.fn.col(".") - 1
if col == 0 or vim.fn.getline("."):sub(col, col):match("%s") then
return true
else
return false
end
return col == 0 or vim.fn.getline("."):sub(col, col):match("%s")
end

cmp.setup({
completion = {
completeopt = "menu,menuone,preview,noinsert",
},
documentation = {
border = { "╭", "─", "╮", "│", "╯", "─", "╰", "│" },
},
formatting = {
format = function(entry, item)
item.kind = string.format("%s %s", get_kind(item.kind), item.kind)
Expand All @@ -59,21 +58,26 @@ return function()
nvim_lua = "[Lua]",
path = "[Path]",
})[entry.source.name]

item.dup = ({
buffer = 1,
path = 1,
nvim_lsp = 0,
})[entry.source.name] or 0
return item
end,
},
mappings = {
mapping = {
["<C-p>"] = cmp.mapping.select_prev_item(),
["<C-n>"] = cmp.mapping.select_next_item(),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.close(),
-- ["<ESC>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
}),
["<C-e>"] = cmp.mapping.close(),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-p>"] = cmp.mapping.select_prev_item(),
["<C-n>"] = cmp.mapping.select_next_item(),
["<Tab>"] = cmp.mapping(function(fallback)
if vim.fn.pumvisible() == 1 then
vim.fn.feedkeys(t("<C-n>"), "n")
Expand Down
28 changes: 24 additions & 4 deletions lua/doom/modules/config/doom-lsp-signature.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
return function()
-- Signature help
require("lsp_signature").setup({
local cfg = {
bind = true,
floating_window = true,
doc_lines = 10,
floating_window = false, -- show hint in a floating window, set to false for virtual text only mode
floating_window_above_cur_line = true,
fix_pos = false, -- set to true, the floating window will not auto-close until finish all parameters
hint_enable = true, -- virtual hint enable
-- hint_prefix = "🐼 ", -- Panda for parameter
hint_prefix = " ",
hint_scheme = "String",
-- use_lspsaga = false, -- set to true if you want to use lspsaga popup
hi_parameter = "Search", -- how your parameter will be highlight
max_height = 12, -- max height of signature floating_window, if content is more than max_height, you can scroll down
-- to view the hiding contents
max_width = 120, -- max_width of signature floating_window, line will be wrapped if exceed max_width
handler_opts = {
border = "single",
border = "single", -- double, single, shadow, none
},
})
-- transpancy = 80,
extra_trigger_chars = {}, -- Array of extra characters that will trigger signature completion, e.g., {"(", ","}
zindex = 200, -- by default it will be on top of all floating windows, set to 50 send it to bottom
debug = false, -- set to true to enable debug logging
log_path = "debug_log_file_path", -- debug log path
padding = "", -- character to pad on left and right of signature can be ' ', or '|' etc
shadow_blend = 36, -- if you using shadow as border use this set the opacity
shadow_guibg = "Black", -- if you using shadow as border use this set the color e.g. 'Green' or '#121315'
}
require("lsp_signature").setup(cfg)
end
27 changes: 26 additions & 1 deletion lua/doom/modules/config/doom-lspinstall.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,33 @@ return function()

-- Snippets support
local capabilities = vim.lsp.protocol.make_client_capabilities()
-- capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities)
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.snippetSupport = true
capabilities.textDocument.completion.completionItem.resolveSupport = {
properties = { "documentation", "detail", "additionalTextEdits" },
}
capabilities.textDocument.codeAction = {
dynamicRegistration = false,
codeActionLiteralSupport = {
codeActionKind = {
valueSet = {
"",
"quickfix",
"refactor",
"refactor.extract",
"refactor.inline",
"refactor.rewrite",
"source",
"source.organizeImports",
},
},
},
}

local lua_lsp = require("lua-dev").setup({
lspconfig = {
Expand Down
26 changes: 25 additions & 1 deletion lua/doom/modules/config/doom-luasnip.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
return function()
require("luasnip.loaders.from_vscode").lazy_load()
local util = require("doom.utils")
local luasnip = require("luasnip")

luasnip.config.set_config({
history = true,
-- Update more often, :h events for more info.
updateevents = "TextChanged,TextChangedI",
})

require("luasnip/loaders/from_vscode").load()

--- <tab> to jump to next snippet's placeholder
local function on_tab()
return luasnip.jump(1) and "" or util.t("<Tab>")
end

--- <s-tab> to jump to next snippet's placeholder
local function on_s_tab()
return luasnip.jump(-1) and "" or util.t("<S-Tab>")
end

util.imap("<Tab>", on_tab, { expr = true })
util.smap("<Tab>", on_tab, { expr = true })
util.imap("<S-Tab>", on_s_tab, { expr = true })
util.smap("<S-Tab>", on_s_tab, { expr = true })
end
49 changes: 49 additions & 0 deletions lua/doom/utils/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,55 @@ M.write_file = function(path, content, mode)
end)
end

-- keep functions that we want to call
M.functions = {}

-- execute the given lua functions
-- @tparam int index of the function in M.functions
function M.execute(id)
local func = M.functions[id]
if not func then
error("Function doest not exist: " .. id)
end
return func()
end

-- map keybindings to functions and cmds
local key_map = function(mode, key, cmd, opts, defaults)
opts = vim.tbl_deep_extend("force", { silent = true }, defaults or {}, opts or {})

if type(cmd) == "function" then
table.insert(M.functions, cmd)
if opts.expr then
cmd = ([[luaeval('require("doom.utils").execute(%d)')]]):format(#M.functions)
else
cmd = ("<cmd>lua require('doom.utils').execute(%d)<cr>"):format(#M.functions)
end
end
if opts.buffer ~= nil then
local buffer = opts.buffer
opts.buffer = nil
return vim.api.nvim_buf_set_keymap(buffer, mode, key, cmd, opts)
else
return vim.api.nvim_set_keymap(mode, key, cmd, opts)
end
end

-- map termcode keybindings
function M.t(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end

-- insert mode keybinding
function M.imap(key, cmd, opts)
return key_map("i", key, cmd, opts)
end

-- substitute mode keybinding
function M.smap(key, cmd, opts)
return key_map("s", key, cmd, opts)
end

M.load_modules = function(module_path, modules)
for i = 1, #modules, 1 do
local ok, err = xpcall(
Expand Down