Giter Club home page Giter Club logo

nvim-lspfuzzy's Introduction

nvim-lspfuzzy

This plugin makes the Neovim LSP client use 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

Installation

With packer.nvim:

use {
  'ojroques/nvim-lspfuzzy',
  requires = {
    {'junegunn/fzf'},
    {'junegunn/fzf.vim'},  -- to enable preview (optional)
  },
}

With paq-nvim:

paq {'junegunn/fzf'}
paq {'junegunn/fzf.vim'}  -- to enable preview (optional)
paq {'ojroques/nvim-lspfuzzy'}

Usage

Simply add this line to your init.lua:

require('lspfuzzy').setup {}

If you're using a .vimrc or init.vim:

lua require('lspfuzzy').setup {}

In addition, the plugin creates the following commands:

  • :LspDiagnostics <bufnr>: 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).

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:

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 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:

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

nvim-lspfuzzy's People

Contributors

110y avatar jaywonchung avatar kingcol13 avatar ojroques avatar srafi1 avatar zeertzjq avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nvim-lspfuzzy's Issues

Code action text missing sometimes (tsserver)

๐Ÿ‘‹๐Ÿผ

I mainly use the tsserver LSP and I'm seeing two issues when triggering codeAction with this plugin:

  • [lspfuzzy] json: cannot unmarshal number into Go struct field Diagnostic.context.diagnostics.code of t
    ype string
    image

  • Sometimes, maybe 1 out of 10, the text of the actions are missing. As soon as I input text and then remove it the text renders correctly. Do note that the count is correct though.
    image

Thank you for an otherwise awesome plugin ๐Ÿ™๐Ÿผ Just ping if you need further input/information.

How to use fzf for lsp?

So this is in your README.md file:

image

But I don't really understand what I have to do in order to be able to use FZF for searching symbols or references. Could you help me please?

Maintain the fzf_preview_window options.

I have defaulted fzf to show preview in the bottom ('down') but it keeps showing on right, so I think that you are probably overriding this settings somehow.

let functional actions be the last callbacks to be called with selected items

okay I am noticing that if we use a action which is a lua function, lspfuzzy will automatically set the qflist and open qflist, which might defeat the purpose fo the action argument. We can let action take complete control over what happens with the selections, which makes it more like the last callback.

I suggest letting the call return after calling functional action.

builds on #27

code action not works

codeAction doesn't seem to work for me. Here is the config.

 vim.api.nvim_buf_set_keymap('n', 'gca', [[<cmd>lua vim.lsp.buf.code_action()<CR>]], { silent = true, noremap = true })

'textDocument/codeAction' not support?

Hi, in README, the supported LSP functions are:

callHierarchy/incomingCalls
callHierarchy/outgoingCalls
textDocument/declaration
textDocument/definition
textDocument/documentSymbol
textDocument/implementation
textDocument/references
textDocument/typeDefinition
workspace/symbol

So textDocument/codeAction not support?

call lua function in action

hey, I have a setup using fzf.vim and nvim-lspfuzzy, with a custom function to send fzf selections to q qflist.

qf_populate = function(lines, mode)
    if mode == nil then
        lines = core.foreach(lines, function(item) return { filename = item, lnum = 1, col = 1 } end)
        mode = "r"
    end

    vim.fn.setqflist(lines, mode)
    vim.cmd [[
        copen
        setlocal statusline=%!v:lua.StatusLine('QuickFix')
        setlocal nobuflisted
        wincmd p
        echo hello
    ]]
end

and my fzf_actions is set as:

vim.g.fzf_action = {
    ["ctrl-q"] = qf_populate,
    ["ctrl-x"] = "split",
    ["ctrl-v"] = "vsplit"
}

this setup works for fzf.vim, and a few custom LSP handlers I wrote (using qf_populate for multi-file refactors). How can I get lspfuzzy to call this function, with the first param as the lines. ?

Reopen the last results

Is it possible to reopen the window with the last command results?
E.g. If I do find usages, and go to the first usage, I might want to go to another usage, after I reviewed the first one. Would it be possible to save the results and have an option to reopen the window?

Or another way to implement something like that would be to duplicate results into the QuickFix window; so you can run copen and look at them later.

BTW, thanks for the great plugin.

Actions in fzf broken on nvim nightly

๐Ÿ‘‹๐Ÿผ

I just noted that I'm no longer getting the actions in fzf on the latest neovim nightly. It works on 0.5.1 but fails on latest nightly (v0.6.0-dev+368-g9337fff8a).

Gimme a ping if you need any further information.

Feature Request: Severity color in LspDiagnostics

Hey there, first of all thanks for this: #36

I just wanna ask if it's possible to get color for the severity text. It doesn't need to set it according Diagnostic highlight, but maybe common diagnostic color. eg.
path/to/file: ansi.red [ERROR] ansi.reset error message bla bla

This would increase clarity.

Error when try to sink the fzf-result to quickfix window: set_qlist(a nil val)

5 fix set_qlist(a nil val)
6
7 diff --git a/lua/lspfuzzy.lua b/lua/lspfuzzy.lua
8 index fac5c6c..76a8937 100644
9 --- a/lua/lspfuzzy.lua
10 +++ b/lua/lspfuzzy.lua
11 @@ -92,7 +92,7 @@ local function jump(entries)
12
13 -- Use the quickfix list to store remaining locations
14 if #locations > 1 then
15 - vim.lsp.util.set_qflist(vim.lsp.util.locations_to_items(locations, offset_encoding))
16 + vim.fn.setqflist(vim.lsp.util.locations_to_items(locations, offset_encoding))
17 vim.cmd 'copen'
18 vim.cmd 'wincmd p'
19 end

Q: How can I exclude node_modules or other directories when executing commands such as go to definitions

Hi,

Thanks for the awesome plugin, I've been using it and I'm super happy!

I have a question:
When executing the lsp function to go to definition in a typescript project, it always lists the definition from dir node_modules I've tried to ignore that and it works when I use Rg and fzf commands but it doesn't work when using the plugin. Which leads me to think that customizing the FZF_DEFAULT_COMMAND in either nvim or my .zshrc file don't have an effect on the fzf command used for the lsp functions.

Is there a way to exclude files or directories for the plugin's supported commands?

If you need any more input let me know :)

Cheers!

Improving document symbols

First of all, thanks for the great plugin!

I am trying to improve the document symbol window, right now it depends on showing the entire file path to move to the correct position so when my editor is small-ish it stops being useful:

image

Is there a way to get around that limitation? Changing the modifier eventually ends up breaking and opening new buffers with names which makes sense but hasn't gotten me any closer. :p:t for example looks great but falls into these (which to be fair the read me mentions)

image

Any suggestions?

Adding option to set layout

The option to set fzf_layout is missing. Unable to use fzf_layout = { 'down' : '30%' } to get the fzf window down rather than in the middle.

Is it there and I am missing something?

If not, please add that support.

My configuration is -

-- Lsp fuzzy seach setup

local g = vim.g
local map = vim.api.nvim_set_keymap

require('lspfuzzy').setup {
  methods = 'all',         -- either 'all' or a list of LSP methods (see below)
  fzf_layout = 'down:30%',
  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'] = 'tabedit',  -- 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
}

map('n', '<A-g>', ':GFiles<cr>', {})
map('n', '<A-p>', ':Files<cr>', {})

I have added the option for layout as down but still the window is coming as floating window in the center.

fzf preview not works

preview works well on fzf's built-in function, what debug info do you need to help

fzf doesn't scroll preview to actual position

Issue:

Open a file with active LSP and call references. FZF window with references will pop up, but when you change the selected reference, the preview window shows the file in its current position (0 line for a closed file or current cursor position for an open file).

Expected behavior:

FZF window will scroll to a line with the selected reference.

Environment:

LSP clangd and pyls (the issue is reproducable on both LSPs)
Ubuntu 20.04
NeoVim 0.6.0
nvim-lspfuzzy - latest
fzf and fzf.vim installed, latest version

Make work with fzf-lua

I will probably pick this up when I have a bit of time. I have migrated to fzf-lua and would like to be able to use that for previews.

bad argument #1 to 'unpack' (table expected, got string)

I've updated everything and I am on neovim master but I get

|| E5108: Error executing lua ...to/.local/share/nvim/site/nvim-lspfuzzy/lua/lspfuzzy.lua:95: bad argument #1 to 'unpack' (table expected, got string)
|| E5108: Error executing lua ...to/.local/share/nvim/site/nvim-lspfuzzy/lua/lspfuzzy.lua:95: bad argument #1 to 'unpack' (table expected, got string)

on
:LspDiagnosticAll

@ojroques okay I am noticing that even after calling the action function, it automatically sets the qflist and opens that split, which defeats the purpose of my qf_list function. I we can let action take complete control over what happens with the selections, which makes it more like the last callback.

@ojroques okay I am noticing that even after calling the action function, it automatically sets the qflist and opens that split, which defeats the purpose of my qf_list function. I we can let action take complete control over what happens with the selections, which makes it more like the last callback.

I suggest letting the call return after calling functional action. What do you think?

Originally posted by @ViRu-ThE-ViRuS in #27 (comment)

Error expected table, got number when doing vim.lsp.buf.declaration

I'm a bit new to lua configuration but this is about as far as I got...

My setup is basic e.g. require('lspfuzzy').setup {} and when running vim.lsp.buf.declaration() is giving me this error. The result parameter in the returned handler in make_location_handler is of type number for some reason ๐Ÿคทโ€โ™‚๏ธ

local debug = require("debug")                                                                                                                     
xpcall(function() vim.lsp.buf.declaration() end, function() print(debug.traceback()) end)
EOF
stack traceback:
^I[string ":lua"]:2: in function <[string ":lua"]:2>
^I[C]: in function 'assert'
^Ivim/shared.lua:199: in function 'tbl_isempty'
^I...im/site/pack/packer/start/nvim-lspfuzzy/lua/lspfuzzy.lua:135: in function 'handler' <-------------
^I/usr/share/nvim/runtime/lua/vim/lsp.lua:1276: in function 'request'
^I/usr/share/nvim/runtime/lua/vim/lsp/buf.lua:69: in function 'declaration'
^I[string ":lua"]:2: in function <[string ":lua"]:2>
^I[C]: in function 'xpcall'
^I[string ":lua"]:2: in main chunk

switch to nvim-lua

was wondering if this project plans to ever switch over to using vijaymarupudi/nvim-fzf? The importance of doing this will become greater as lua support in neovim improves (and performance)

Feature request: Adding support for telescope.

Is there any plans for adding the option to choose between Telescope and FZF ?

At the moment, Telescope seems to be the most extensible fuzzy finder (and in consequence, probably the best one), it is written entirely in lua (unlike the FZF plugin for vim) and it has become the most popular fuzzy finder for users moving their configuration over to lua, and those users usually only want lua plugins.

It just makes sense adding support for telescope. How difficult would it be to implement ? Both plugins are written in lua so maybe that would make it a little bit easier.

How to configure LSP methods separately?

For instance, I'd like to use the preview window for the textDocument/references method, but not for textDocument/codeAction, since there is nothing to preview in that case. Thanks!

Expected table, got string error when calling vim.lsp.buf.definition()

Hi,

I'm running neovim NVIM v0.6.0-dev+1551-g0e22a40b6, and just updated a all of my plugins with Packer.

I am also using gopls, built-in LSP, and nvim-lspfuzzy. Previously, I would call vim.lsp.buf.definition() via a keybinding when hovering over a keyword in go. Often, there is only a single definition location, so my buffer would be moved automatically to that location. Further, if there were multiple definitions, I would get the fuzzy complete pop-up and could choose my definition.

For some reason, after upgrading, when I make a vim.lsp.buf.definition() call, I am getting the following error:

Error executing vim.schedule lua callback: vim/shared.lua:199: Expected table, got string

I also get this same error when calling vim.lsp.buf.implementation() and vim.lsp.buf.references().

I know that this is a nvim-lspfuzzy related issue, since when I disable nvim-lspfuzzy, these same function calls work as expected (except I don't get the pretty fuzzy pop-up!)

I am wondering if I am missing some configuration item here, or if this is an actual bug.

Please let me know if you would like additional information for re-producability.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.