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

Commit

Permalink
Merge pull request #3 from xiaoshihou514/main
Browse files Browse the repository at this point in the history
chore: two useful options and doc renovation
  • Loading branch information
glepnir authored Nov 24, 2023
2 parents 9e1d31d + f340412 commit e63510e
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 16 deletions.
67 changes: 54 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,63 @@
## Epo
## epo.nvim

a blazing fast and minimal less than 300 lines. neovim lsp auto-completion plugin.
Blazingly fast, minimal lsp auto-completion and snippet plugin for neovim.

**Need neovim nightly**
**Needs neovim nightly**

**This plugin would be much more feature-complete after [this pr](https://github.com/neovim/neovim/pull/24723) is merged**

## Usage

```lua
-- suggested completeopt
vim.opt.completeopt = "menu,menuone,noselect"

-- default settings
require('epo').setup({
-- default value of options.
-- fuzzy match
fuzzy = false,
-- increase this value can aviod trigger complete when delete character.
debounce = 50,
-- when completion confrim auto show a signature help floating window.
signature = false,
-- extend vscode format snippet json files. like rust.json/typescriptreact.json/zig.json
-- vscode style json snippet path
snippet_path = nil,
-- border for lsp signature popup, :h nvim_open_win
signature_border = 'rounded'
-- lsp kind formatting, k is kind string "Field", "Struct", "Keyword" etc.
kind_format = function(k)
return k:lower():sub(1, 1)
end
})
```

register capabilities for `vim.snippet`
You may want to pass the capabilities to your lsp

```lua
server_config = {
capabilities = vim.tbl_deep_extend(
local capabilities = vim.tbl_deep_extend(
'force',
vim.lsp.protocol.make_client_capabilities(),
require('epo').register_cap()
)
}
```

## Keymap
Completion menu look dull and boring? Your colorscheme may be missing these highlights:

```
Pmenu
PmenuExtra
PmenuSel
PmenuKind
PmenuKindSel
PmenuExtraSel
PmenuSbar
PmenuThumb
```

<details>
<summary>Click to show some mapping presets</summary>

Super <kbd>TAB</kbd> and <kbd>Shift-tab</kbd> bind tab and shift-tab for completion and snippet
expand.
- <kbd>TAB</kbd> complete

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

- use `<cr>` to accept 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 })
```

third param is fuzzy match enable.
</details>

## License MIT
11 changes: 8 additions & 3 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 @@ -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 e63510e

Please sign in to comment.