Giter Site home page Giter Site logo

goto-preview's Introduction

โญ Goto Preview

A small Neovim plugin for previewing native LSP's goto definition calls in floating windows.

๐Ÿš€ Showcase

๐Ÿ”— References

โš ๏ธ IMPORTANT NOTE

There is currently an open Neovim TUI bug that prevents the correct positioning of more than one preview window. One singular preview window should work fine but jumping to a subsequent preview will position it in an undesired spot.

๐ŸŽ‰ GUIs like Goneovim and Uivonim implement the correct positioning behaviour and will behave as intended.

โš ๏ธ UPDATE

The issue is fixed in Neovim v0.6.0-dev (master) and is set for the milestone 0.5.1 at the time of writing. neovim/neovim#14770

๐Ÿ“ฆ Installation

Packer.nvim

use {
  'rmagatti/goto-preview',
  config = function()
    require('goto-preview').setup {}
  end
}

โš™๏ธ Configuration

Default

require('goto-preview').setup {
    width = 120; -- Width of the floating window
    height = 15; -- Height of the floating window
    default_mappings = false; -- Bind default mappings
    debug = false; -- Print debug information
    opacity = nil; -- 0-100 opacity level of the floating window where 100 is fully transparent.
    post_open_hook = nil -- A function taking two arguments, a buffer and a window to be ran as a hook.
  }

The post_open_hook function gets called right before setting the cursor position in the new floating window. One can use this to set custom key bindings or really anything else they want to do when a new preview window opens.

โŒจ๏ธ Mappings

There are no mappings by default, you can set default_mappings = true in the config to make use of the mappings I use or define your own.
Default

nnoremap gpd <cmd>lua require('goto-preview').goto_preview_definition()<CR>
nnoremap gpi <cmd>lua require('goto-preview').goto_preview_implementation()<CR>
nnoremap gP <cmd>lua require('goto-preview').close_all_win()<CR>

Custom example

vim.api.nvim_set_keymap("n", "gp", "<cmd>lua require('goto-preview').goto_preview_definition()<CR>", {noremap=true})

Supported languages

Goto Preview should work with LSP responses for most languages now! If something doesn't work as expected, drop an issue and I'll be happy to check it out!

Note: different language servers have potentially different shapes for the result of the textDocument/definition and textDocument/implementation calls. Until more are added one can pass in custom responses through the lsp_configs config value. Just follow the same pattern returning two values, a target (string) and a cursor_position ({line_num, col_num}). The data parameter is the [1] of the LSP's result of the definition/implementation calls and is what gets passed into the custom get_config function.

Tested with

NVIM v0.5.0-dev+7d4f890aa  
Build type: Release  
LuaJIT 2.1.0-beta3  

goto-preview's People

Contributors

rmagatti avatar hobord avatar

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.