From d9ab89b76e86068a09c1f7cea537a141307f131e Mon Sep 17 00:00:00 2001 From: xiaoshihou Date: Thu, 23 Nov 2023 20:40:43 +0000 Subject: [PATCH] squash --- README.md | 36 ++++++++++++++++++++++++++++++++++-- lua/epo/init.lua | 13 +++++++++---- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 978eb8f..a0baaa6 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,12 @@ Blazing fast and minimal lsp auto-completion plugin for neovim. **Needs neovim nightly** +**This plugin would be much feature-complete after [this pr](https://github.com/neovim/neovim/pull/24723) is merged** + ## Usage ```lua +vim.opt.completeopt = "menu,menuone,noselect" require('epo').setup({ fuzzy = false, -- increase this value can aviod trigger complete when delete character. @@ -15,6 +18,12 @@ require('epo').setup({ signature = false, -- extend vscode format snippet json files. like rust.json/typescriptreact.json/zig.json snippet_path = nil, + -- border for lsp signature popup + signature_border = 'rounded' + -- lsp kind formatting + kind_format = opt.kind_format or function(k) + return k:lower():sub(1, 1) + end }) ``` @@ -28,9 +37,10 @@ local capabilities = vim.tbl_deep_extend( ) ``` -## Keymap +
+Click to show some preset mappings -Supercharge TAB and Shift-tab for completion and snippet expansion. +- TAB complete ```lua vim.keymap.set('i', '', function() @@ -61,4 +71,26 @@ vim.keymap.set('i', '', function() end, {expr = true}) ``` +- `` completion + +```lua +-- For using enter as completion, may conflict with some autopair plugin +vim.keymap.set("i", "", function() + if vim.fn.pumvisible() == 1 then + return "" + end + return "" +end, { expr = true, noremap = true }) + +-- nvim-autopair compatibility +vim.keymap.set("i", "", function() + if vim.fn.pumvisible() == 1 then + return "" + end + return require("nvim-autopairs").autopairs_cr() +end, { expr = true, noremap = true }) +``` + +
+ ## License MIT diff --git a/lua/epo/init.lua b/lua/epo/init.lua index 63a24d4..9e8656f 100644 --- a/lua/epo/init.lua +++ b/lua/epo/init.lua @@ -7,7 +7,8 @@ local ns = api.nvim_create_namespace('Epo') local match_fuzzy = false local signature = false local debounce_time = 100 -local snippet_path = nil +local snippet_path, signature_border, kind_format + -- Ctrl-Y will trigger TextChangedI again -- avoid completion redisplay add a status check local disable = nil @@ -59,7 +60,7 @@ end local function lspkind(kind) local k = protocol.CompletionItemKind[kind] or 'Unknown' - return k:lower():sub(1, 1) + return kind_format(k) end local function show_info(bufnr) @@ -113,7 +114,7 @@ local function signature_help(client, bufnr, lnum) lines = { unpack(lines, 1, 3) } fbuf, fwin = util.open_floating_preview(lines, 'markdown', { close_events = {}, - border = 'rounded', + border = signature_border, }) vim.bo[fbuf].syntax = 'on' @@ -337,7 +338,7 @@ local function completion_handler(_, result, ctx) prefix = prefix:lower() for _, item in - ipairs(vim.list_extend(compitems, context.snippets[vim.bo[ctx.bufnr].filetype] or {})) + ipairs(vim.list_extend(compitems, context.snippets[vim.bo[ctx.bufnr].filetype] or {})) do local entry = { abbr = item.label, @@ -516,6 +517,10 @@ local function setup(opt) debounce_time = opt.debounce_time or 50 signature = opt.signature or false snippet_path = opt.snippet_path + signature_border = opt.signature_border or 'rounded' + kind_format = opt.kind_format or function(k) + return k:lower():sub(1, 1) + end -- Usually I just use one client for completion so just one api.nvim_create_autocmd('LspAttach', {