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

Commit

Permalink
squash
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoshihou514 committed Nov 23, 2023
1 parent 7b3db28 commit d9ab89b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
36 changes: 34 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
})
```

Expand All @@ -28,9 +37,10 @@ local capabilities = vim.tbl_deep_extend(
)
```

## Keymap
<details>
<summary>Click to show some preset mappings</summary>

Supercharge <kbd>TAB</kbd> and <kbd>Shift-tab</kbd> for completion and snippet expansion.
- <kbd>TAB</kbd> complete

```lua
vim.keymap.set('i', '<TAB>', function()
Expand Down Expand Up @@ -61,4 +71,26 @@ vim.keymap.set('i', '<C-e>', function()
end, {expr = true})
```

- `<cr>` completion

```lua
-- For using enter as completion, may conflict with some autopair plugin
vim.keymap.set("i", "<cr>", function()
if vim.fn.pumvisible() == 1 then
return "<C-y>"
end
return "<cr>"
end, { expr = true, noremap = true })

-- nvim-autopair compatibility
vim.keymap.set("i", "<cr>", function()
if vim.fn.pumvisible() == 1 then
return "<C-y>"
end
return require("nvim-autopairs").autopairs_cr()
end, { expr = true, noremap = true })
```

</details>

## License MIT
13 changes: 9 additions & 4 deletions lua/epo/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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'

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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', {
Expand Down

0 comments on commit d9ab89b

Please sign in to comment.