Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ojroques/nvim-lspfuzzy

A Neovim plugin to make the LSP client use FZF
https://github.com/ojroques/nvim-lspfuzzy

fzf neovim-lsp neovim-lua neovim-plugin

Last synced: 7 days ago
JSON representation

A Neovim plugin to make the LSP client use FZF

Awesome Lists containing this project

README

        

# nvim-lspfuzzy

This plugin makes the Neovim LSP client use
[FZF](https://github.com/junegunn/fzf) to display results and navigate the code.
It works by redefining your LSP handlers so that they call FZF.

**The plugin requires Neovim 0.6+.** For Neovim 0.5, use version `v0.1.0`.

![demo](https://user-images.githubusercontent.com/23409060/188602802-456cc524-e723-4142-94b3-98df04bf4897.gif)

## Installation
With [packer.nvim](https://github.com/wbthomason/packer.nvim):
```lua
use {
'ojroques/nvim-lspfuzzy',
requires = {
{'junegunn/fzf'},
{'junegunn/fzf.vim'}, -- to enable preview (optional)
},
}
```

With [paq-nvim](https://github.com/savq/paq-nvim):
```lua
paq {'junegunn/fzf'}
paq {'junegunn/fzf.vim'} -- to enable preview (optional)
paq {'ojroques/nvim-lspfuzzy'}
```

## Usage
Simply add this line to your *init.lua*:
```lua
require('lspfuzzy').setup {}
```

If you're using a *.vimrc* or *init.vim*:
```vim
lua require('lspfuzzy').setup {}
```

In addition, the plugin creates the following commands:
* `:LspDiagnostics `: list diagnostics from given buffer (use `0` for
current buffer).
* `:LspDiagnosticsAll`: list diagnostics from all buffers.
* `:LspFuzzyLast`: re-open the last results (requires `save_last = true`, see
[Configuration](#configuration)).

By default the following FZF actions are available:
* **tab** : select multiple entries
* **shift+tab** : deselect an entry
* **ctrl-a** : select all entries
* **ctrl-d** : deselect all entries
* **ctrl-t** : go to location in a new tab
* **ctrl-v** : go to location in a vertical split
* **ctrl-x** : go to location in a horizontal split

## Configuration
You can pass options to the `setup()` function. Here are all available options
with their default settings:
```lua
require('lspfuzzy').setup {
methods = 'all', -- either 'all' or a list of LSP methods (see below)
jump_one = true, -- jump immediately if there is only one location
save_last = false, -- save last location results for the :LspFuzzyLast command
callback = nil, -- callback called after jumping to a location
fzf_preview = { -- arguments to the FZF '--preview-window' option
'right:+{2}-/2' -- preview on the right and centered on entry
},
fzf_action = { -- FZF actions
['ctrl-t'] = 'tab split', -- go to location in a new tab
['ctrl-v'] = 'vsplit', -- go to location in a vertical split
['ctrl-x'] = 'split', -- go to location in a horizontal split
},
fzf_modifier = ':~:.', -- format FZF entries, see |filename-modifiers|
fzf_trim = true, -- trim FZF entries
}
```

The `fzf_preview` and `fzf_action` settings are determined as follows:
1. Values passed to `setup()` are used first.
2. Otherwise the plugin will try to load values from the respective FZF options
`g:fzf_preview_window` and `g:fzf_action` if they are set.
3. Finally the default values will be used.

For others FZF options such as `g:fzf_layout` or `g:fzf_colors` the plugin will
respect your settings.

## Supported LSP methods
You can enable FZF only for some LSP methods by passing them as a list to the
`methods` option when calling `setup()`. The supported LSP methods are:
```
callHierarchy/incomingCalls
callHierarchy/outgoingCalls
textDocument/declaration
textDocument/definition
textDocument/documentSymbol
textDocument/implementation
textDocument/references
textDocument/typeDefinition
workspace/symbol
```

## Troubleshooting
#### Preview does not work
You need to install [fzf.vim](https://github.com/junegunn/fzf.vim) to enable
previews. If it's already installed, make sure it's up-to-date.

#### Preview does not scroll to the selected location
Try to append `+{2}-/2` to either `g:fzf_preview_window` or to the `fzf_preview`
option in `setup()` to make the preview respect line numbers. For instance:
```lua
vim.g.fzf_preview_window = {'down:+{2}-/2'}
```

#### Using the `fzf_modifier` option breaks the plugin
The plugin uses the filename embedded in the FZF entry currently selected to
jump to the correct location. Therefore it must resolve to a valid path: for
instance `:.` or `:p` can be used but not `:t`.

## License
[LICENSE](./LICENSE)