Skip to content

Commit

Permalink
refactor: changes cmp & lsp_signature behaviours
Browse files Browse the repository at this point in the history
This commit brings the following changes:
- Removes the enter to select first item in cmp
  as that sometimes you don't mean to press the
  completion and just want to make a new line.
- Removes the automatic lsp_signature float window
  as that sometimes it's a bit annoying, coming up
  everywhere. It can be manually toggled using
  ctrl + k.
- Formats all files using stylua.
  • Loading branch information
ixahmedxi committed Dec 28, 2022
1 parent 4fb3859 commit 4acc7b1
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 153 deletions.
217 changes: 108 additions & 109 deletions lua/config/cmp.lua
Original file line number Diff line number Diff line change
@@ -1,115 +1,114 @@
import({ "cmp", "luasnip", "lspkind", "luasnip/loaders/from_vscode" }, function(modules)
modules["luasnip/loaders/from_vscode"].lazy_load()
modules["luasnip/loaders/from_vscode"].lazy_load()

local check_backspace = function()
local col = vim.fn.col(".") - 1
return col == 0 or vim.fn.getline("."):sub(col, col):match("%s")
end
local check_backspace = function()
local col = vim.fn.col(".") - 1
return col == 0 or vim.fn.getline("."):sub(col, col):match("%s")
end

modules.cmp.setup({
snippet = {
expand = function(args)
modules.luasnip.lsp_expand(args.body)
end,
},
mapping = {
["<C-k>"] = modules.cmp.mapping.select_prev_item(),
["<C-j>"] = modules.cmp.mapping.select_next_item(),
["<C-b>"] = modules.cmp.mapping(modules.cmp.mapping.scroll_docs(-1), { "i", "c" }),
["<C-f>"] = modules.cmp.mapping(modules.cmp.mapping.scroll_docs(1), { "i", "c" }),
["<C-Space>"] = modules.cmp.mapping(modules.cmp.mapping.complete(), { "i", "c" }),
["<C-y>"] = modules.cmp.config.disable,
["<C-e>"] = modules.cmp.mapping({
i = modules.cmp.mapping.abort(),
c = modules.cmp.mapping.close(),
}),
["<CR>"] = modules.cmp.mapping.confirm({ select = true }),
["<Tab>"] = modules.cmp.mapping(function(fallback)
if modules.cmp.visible() then
modules.cmp.select_next_item()
elseif modules.luasnip.expandable() then
modules.luasnip.expand()
elseif modules.luasnip.expand_or_jumpable() then
modules.luasnip.expand_or_jump()
elseif check_backspace() then
fallback()
else
fallback()
end
end, {
"i",
"s",
}),
["<S-Tab>"] = modules.cmp.mapping(function(fallback)
if modules.cmp.visible() then
modules.cmp.select_prev_item()
elseif modules.luasnip.jumpable(-1) then
modules.luasnip.jump(-1)
else
fallback()
end
end, {
"i",
"s",
}),
},
formatting = {
fields = { "abbr", "kind", "menu" },
format = modules.lspkind.cmp_format({
mode = "symbol_text",
symbol_map = {
Copilot = "",
},
before = function(entry, vim_item)
vim_item.menu = ({
nvim_lsp = "[LSP]",
luasnip = "[Snippet]",
buffer = "[Buffer]",
path = "[Path]",
})[entry.source.name]
return vim_item
end,
}),
},
sources = {
{ name = "nvim_lsp", group_index = 1, keyword_length = 4 },
{ name = "copilot", group_index = 1 },
{ name = "luasnip", group_index = 2 },
{ name = "buffer", group_index = 2 },
{ name = "path", group_index = 2 },
},
confirm_opts = {
behavior = modules.cmp.ConfirmBehavior.Replace,
select = false,
},
window = {
completion = modules.cmp.config.window.bordered(),
documentation = modules.cmp.config.window.bordered(),
},
experimental = {
ghost_text = false,
native_menu = false,
},
performance = {
trigger_debounce_time = 500,
throttle = 550,
fetching_timeout = 80,
},
})
modules.cmp.setup({
snippet = {
expand = function(args)
modules.luasnip.lsp_expand(args.body)
end,
},
mapping = {
["<C-k>"] = modules.cmp.mapping.select_prev_item(),
["<C-j>"] = modules.cmp.mapping.select_next_item(),
["<C-b>"] = modules.cmp.mapping(modules.cmp.mapping.scroll_docs(-1), { "i", "c" }),
["<C-f>"] = modules.cmp.mapping(modules.cmp.mapping.scroll_docs(1), { "i", "c" }),
["<C-Space>"] = modules.cmp.mapping(modules.cmp.mapping.complete(), { "i", "c" }),
["<C-y>"] = modules.cmp.config.disable,
["<C-e>"] = modules.cmp.mapping({
i = modules.cmp.mapping.abort(),
c = modules.cmp.mapping.close(),
}),
["<Tab>"] = modules.cmp.mapping(function(fallback)
if modules.cmp.visible() then
modules.cmp.select_next_item()
elseif modules.luasnip.expandable() then
modules.luasnip.expand()
elseif modules.luasnip.expand_or_jumpable() then
modules.luasnip.expand_or_jump()
elseif check_backspace() then
fallback()
else
fallback()
end
end, {
"i",
"s",
}),
["<S-Tab>"] = modules.cmp.mapping(function(fallback)
if modules.cmp.visible() then
modules.cmp.select_prev_item()
elseif modules.luasnip.jumpable(-1) then
modules.luasnip.jump(-1)
else
fallback()
end
end, {
"i",
"s",
}),
},
formatting = {
fields = { "abbr", "kind", "menu" },
format = modules.lspkind.cmp_format({
mode = "symbol_text",
symbol_map = {
Copilot = "",
},
before = function(entry, vim_item)
vim_item.menu = ({
nvim_lsp = "[LSP]",
luasnip = "[Snippet]",
buffer = "[Buffer]",
path = "[Path]",
})[entry.source.name]
return vim_item
end,
}),
},
sources = {
{ name = "nvim_lsp", group_index = 1, keyword_length = 4 },
{ name = "copilot", group_index = 1 },
{ name = "luasnip", group_index = 2 },
{ name = "buffer", group_index = 2 },
{ name = "path", group_index = 2 },
},
confirm_opts = {
behavior = modules.cmp.ConfirmBehavior.Replace,
select = false,
},
window = {
completion = modules.cmp.config.window.bordered(),
documentation = modules.cmp.config.window.bordered(),
},
experimental = {
ghost_text = false,
native_menu = false,
},
performance = {
trigger_debounce_time = 500,
throttle = 550,
fetching_timeout = 80,
},
})

modules.cmp.setup.cmdline({ "/", "?" }, {
mapping = modules.cmp.mapping.preset.cmdline(),
sources = {
{ name = "buffer" },
},
})
modules.cmp.setup.cmdline({ "/", "?" }, {
mapping = modules.cmp.mapping.preset.cmdline(),
sources = {
{ name = "buffer" },
},
})

modules.cmp.setup.cmdline(":", {
mapping = modules.cmp.mapping.preset.cmdline(),
sources = modules.cmp.config.sources({
{ name = "path" },
}, {
{ name = "cmdline" },
}),
})
modules.cmp.setup.cmdline(":", {
mapping = modules.cmp.mapping.preset.cmdline(),
sources = modules.cmp.config.sources({
{ name = "path" },
}, {
{ name = "cmdline" },
}),
})
end)
76 changes: 38 additions & 38 deletions lua/config/colorschemes.lua
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import("catppuccin", function(catppuccin)
catppuccin.setup({
flavour = "mocha", -- latte, frappe, macchiato, mocha
term_colors = true,
transparent_background = false,
no_italic = false,
no_bold = false,
styles = {
comments = {},
conditionals = {},
loops = {},
functions = {},
keywords = {},
strings = {},
variables = {},
numbers = {},
booleans = {},
properties = {},
types = {},
},
color_overrides = {
mocha = {
base = "#000000",
},
},
highlight_overrides = {
mocha = function(C)
return {
TabLineSel = { bg = C.pink },
NvimTreeNormal = { bg = C.none },
CmpBorder = { fg = C.surface2 },
Pmenu = { bg = C.none },
NormalFloat = { bg = C.none },
TelescopeBorder = { link = "FloatBorder" },
}
end,
},
})
vim.cmd.colorscheme("catppuccin")
catppuccin.setup({
flavour = "mocha", -- latte, frappe, macchiato, mocha
term_colors = true,
transparent_background = false,
no_italic = false,
no_bold = false,
styles = {
comments = {},
conditionals = {},
loops = {},
functions = {},
keywords = {},
strings = {},
variables = {},
numbers = {},
booleans = {},
properties = {},
types = {},
},
color_overrides = {
mocha = {
base = "#000000",
},
},
highlight_overrides = {
mocha = function(C)
return {
TabLineSel = { bg = C.pink },
NvimTreeNormal = { bg = C.none },
CmpBorder = { fg = C.surface2 },
Pmenu = { bg = C.none },
NormalFloat = { bg = C.none },
TelescopeBorder = { link = "FloatBorder" },
}
end,
},
})
vim.cmd.colorscheme("catppuccin")
end)
4 changes: 2 additions & 2 deletions lua/config/git-conflict.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import("git-conflict", function (gitConflict)
gitConflict.setup()
import("git-conflict", function(gitConflict)
gitConflict.setup()
end)
4 changes: 2 additions & 2 deletions lua/config/lsp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ import({ "mason", "mason-lspconfig", "lspconfig", "cmp_nvim_lsp" }, function(mod
end)
end,
["rust_analyzer"] = function()
import("rust-tools", function (rustTools)
rustTools.setup({ server = opts })
import("rust-tools", function(rustTools)
rustTools.setup({ server = opts })
end)
end,
})
Expand Down
1 change: 1 addition & 0 deletions lua/config/lsp/signature.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ import("lsp_signature", function(signature)
border = "rounded",
},
toggle_key = "<M-x>",
floating_window = false,
})
end)
4 changes: 2 additions & 2 deletions lua/config/tmux.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import("tmux", function (tmux)
tmux.setup()
import("tmux", function(tmux)
tmux.setup()
end)

0 comments on commit 4acc7b1

Please sign in to comment.