summaryrefslogtreecommitdiff
path: root/lua/lvim/core
diff options
context:
space:
mode:
authorkylo252 <[email protected]>2021-10-30 14:43:29 +0200
committerkylo252 <[email protected]>2021-10-30 14:44:24 +0200
commit17648e5a07f8c4fe851b09f3037db58c73fe292f (patch)
tree6ef8f701b823e5d4f61945142eb7ceec2581ead4 /lua/lvim/core
parent1f2167df0ea3f837c9c78a0137a888ca05e5e83a (diff)
parentc4a85b32752e1ca41c6d9a2613b9d2e75dbf463d (diff)
Merge branch 'rolling'
Diffstat (limited to 'lua/lvim/core')
-rw-r--r--lua/lvim/core/autopairs.lua16
-rw-r--r--lua/lvim/core/cmp.lua66
-rw-r--r--lua/lvim/core/dashboard.lua12
-rw-r--r--lua/lvim/core/which-key.lua2
4 files changed, 67 insertions, 29 deletions
diff --git a/lua/lvim/core/autopairs.lua b/lua/lvim/core/autopairs.lua
index eb080fb1..51649790 100644
--- a/lua/lvim/core/autopairs.lua
+++ b/lua/lvim/core/autopairs.lua
@@ -4,8 +4,6 @@ function M.config()
lvim.builtin.autopairs = {
active = true,
on_config_done = nil,
- ---@usage auto insert after select function or method item
- map_complete = true,
---@usage -- modifies the function or method delimiter by filetypes
map_char = {
all = "(",
@@ -52,14 +50,12 @@ M.setup = function()
end),
}
- if package.loaded["cmp"] then
- require("nvim-autopairs.completion.cmp").setup {
- map_cr = false,
- map_complete = lvim.builtin.autopairs.map_complete,
- map_char = lvim.builtin.autopairs.map_char,
- }
- -- we map CR explicitly in cmp.lua but we still need to setup the autopairs CR keymap
- vim.api.nvim_set_keymap("i", "<CR>", "v:lua.MPairs.autopairs_cr()", { expr = true, noremap = true })
+ local cmp_status_ok, cmp = pcall(require, "cmp")
+ if cmp_status_ok then
+ -- If you want insert `(` after select function or method item
+ local cmp_autopairs = require "nvim-autopairs.completion.cmp"
+ local map_char = lvim.builtin.autopairs.map_char
+ cmp.event:on("confirm_done", cmp_autopairs.on_confirm_done { map_char = map_char })
end
require("nvim-treesitter.configs").setup { autopairs = { enable = true } }
diff --git a/lua/lvim/core/cmp.lua b/lua/lvim/core/cmp.lua
index b1cb1431..68c695cb 100644
--- a/lua/lvim/core/cmp.lua
+++ b/lua/lvim/core/cmp.lua
@@ -1,14 +1,29 @@
local M = {}
+M.methods = {}
+---checks if the character preceding the cursor is a space character
+---@return boolean true if it is a space character, false otherwise
local check_backspace = function()
local col = vim.fn.col "." - 1
return col == 0 or vim.fn.getline("."):sub(col, col):match "%s"
end
+M.methods.check_backspace = check_backspace
local function T(str)
return vim.api.nvim_replace_termcodes(str, true, true, true)
end
+---wraps vim.fn.feedkeys while replacing key codes with escape codes
+---Ex: feedkeys("<CR>", "n") becomes feedkeys("^M", "n")
+---@param key string
+---@param mode string
+local function feedkeys(key, mode)
+ vim.fn.feedkeys(T(key), mode)
+end
+M.methods.feedkeys = feedkeys
+
+---checks if emmet_ls is available and active in the buffer
+---@return boolean true if available, false otherwise
local is_emmet_active = function()
local clients = vim.lsp.buf_get_clients()
@@ -19,16 +34,17 @@ local is_emmet_active = function()
end
return false
end
+M.methods.is_emmet_active = is_emmet_active
-M.config = function()
- local status_cmp_ok, cmp = pcall(require, "cmp")
- if not status_cmp_ok then
- return
- end
- local status_luasnip_ok, luasnip = pcall(require, "luasnip")
- if not status_luasnip_ok then
+---when inside a snippet, seeks to the nearest luasnip field if possible, and checks if it is jumpable
+---@param dir number 1 for forward, -1 for backward; defaults to 1
+---@return boolean true if a jumpable luasnip field is found while inside a snippet
+local function jumpable(dir)
+ local luasnip_ok, luasnip = pcall(require, "luasnip")
+ if not luasnip_ok then
return
end
+
local win_get_cursor = vim.api.nvim_win_get_cursor
local get_current_buf = vim.api.nvim_get_current_buf
@@ -121,11 +137,33 @@ M.config = function()
return false
end
+ if dir == -1 then
+ return inside_snippet() and luasnip.jumpable(-1)
+ else
+ return inside_snippet() and seek_luasnip_cursor_node() and luasnip.jumpable()
+ end
+end
+M.methods.jumpable = jumpable
+
+M.config = function()
+ local status_cmp_ok, cmp = pcall(require, "cmp")
+ if not status_cmp_ok then
+ return
+ end
+ local status_luasnip_ok, luasnip = pcall(require, "luasnip")
+ if not status_luasnip_ok then
+ return
+ end
+
lvim.builtin.cmp = {
confirm_opts = {
behavior = cmp.ConfirmBehavior.Replace,
select = false,
},
+ completion = {
+ ---@usage The minimum length of a word to complete on.
+ keyword_length = 1,
+ },
experimental = {
ghost_text = true,
native_menu = false,
@@ -209,19 +247,19 @@ M.config = function()
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
-- TODO: potentially fix emmet nonsense
- ["<Tab>"] = cmp.mapping(function()
+ ["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expandable() then
luasnip.expand()
- elseif inside_snippet() and seek_luasnip_cursor_node() and luasnip.jumpable() then
+ elseif jumpable() then
luasnip.jump(1)
elseif check_backspace() then
- vim.fn.feedkeys(T "<Tab>", "n")
+ fallback()
elseif is_emmet_active() then
return vim.fn["cmp#complete"]()
else
- vim.fn.feedkeys(T "<Tab>", "n")
+ fallback()
end
end, {
"i",
@@ -230,7 +268,7 @@ M.config = function()
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
- elseif inside_snippet() and luasnip.jumpable(-1) then
+ elseif jumpable(-1) then
luasnip.jump(-1)
else
fallback()
@@ -241,13 +279,13 @@ M.config = function()
}),
["<C-Space>"] = cmp.mapping.complete(),
- ["<C-e>"] = cmp.mapping.close(),
+ ["<C-e>"] = cmp.mapping.abort(),
["<CR>"] = cmp.mapping(function(fallback)
if cmp.visible() and cmp.confirm(lvim.builtin.cmp.confirm_opts) then
return
end
- if inside_snippet() and seek_luasnip_cursor_node() and luasnip.jumpable() then
+ if jumpable() then
if not luasnip.jump(1) then
fallback()
end
diff --git a/lua/lvim/core/dashboard.lua b/lua/lvim/core/dashboard.lua
index 108ed0d2..11053796 100644
--- a/lua/lvim/core/dashboard.lua
+++ b/lua/lvim/core/dashboard.lua
@@ -31,22 +31,26 @@ M.config = function(config)
custom_section = {
a = {
- description = { " Find File " },
+ description = { " Find File " },
command = "Telescope find_files",
},
b = {
+ description = { " New File " },
+ command = ":ene!",
+ },
+ c = {
description = { " Recent Projects " },
command = "Telescope projects",
},
- c = {
+ d = {
description = { " Recently Used Files" },
command = "Telescope oldfiles",
},
- d = {
+ e = {
description = { " Find Word " },
command = "Telescope live_grep",
},
- e = {
+ f = {
description = { " Configuration " },
command = ":e " .. config.user_config_file,
},
diff --git a/lua/lvim/core/which-key.lua b/lua/lvim/core/which-key.lua
index fcaeacf5..42e37456 100644
--- a/lua/lvim/core/which-key.lua
+++ b/lua/lvim/core/which-key.lua
@@ -177,7 +177,7 @@ M.config = function()
L = {
name = "+LunarVim",
c = {
- "<cmd>edit" .. get_config_dir() .. "/config.lua<cr>",
+ "<cmd>edit " .. get_config_dir() .. "/config.lua<cr>",
"Edit config.lua",
},
f = {