Coder Social home page Coder Social logo

nvim_context_vt's Introduction

nvim_context_vt

Shows virtual text of the current context after functions, methods, statements, etc.

nvim_context_vt

How to install

Use your favourite package manager and install treesitter alongside this plugin. No configuration is required out of the box.

Advanced usage

To customize the behavior use the setup function:

require('nvim_context_vt').setup({
  -- Enable by default. You can disable and use :NvimContextVtToggle to maually enable.
  -- Default: true
  enabled = true,

  -- Override default virtual text prefix
  -- Default: '-->'
  prefix = '',

  -- Override the internal highlight group name
  -- Default: 'ContextVt'
  highlight = 'CustomContextVt',

  -- Disable virtual text for given filetypes
  -- Default: { 'markdown' }
  disable_ft = { 'markdown' },

  -- Disable display of virtual text below blocks for indentation based languages like Python
  -- Default: false
  disable_virtual_lines = false,

  -- Same as above but only for spesific filetypes
  -- Default: {}
  disable_virtual_lines_ft = { 'yaml' },

  -- How many lines required after starting position to show virtual text
  -- Default: 1 (equals two lines total)
  min_rows = 1,

  -- Same as above but only for spesific filetypes
  -- Default: {}
  min_rows_ft = {},

  -- Custom virtual text node parser callback
  -- Default: nil
  custom_parser = function(node, ft, opts)
    local utils = require('nvim_context_vt.utils')

    -- If you return `nil`, no virtual text will be displayed.
    if node:type() == 'function' then
      return nil
    end

    -- This is the standard text
    return opts.prefix .. ' ' .. utils.get_node_text(node)[1]
  end,

  -- Custom node validator callback
  -- Default: nil
  custom_validator = function(node, ft, opts)
    -- Internally a node is matched against min_rows and configured targets
    local default_validator = require('nvim_context_vt.utils').default_validator
    if default_validator(node, ft) then
      -- Custom behaviour after using the internal validator
      if node:type() == 'function' then
        return false
      end
    end

    return true
  end,

  -- Custom node virtual text resolver callback
  -- Default: nil
  custom_resolver = function(nodes, ft, opts)
    -- By default the last node is used
    return nodes[#nodes]
  end,
})

Commands

  • :NvimContextVtToggle - Enable/disable context virtual text

Debug

If you don't see the expected context vitual text, run :NvimContextVtDebug to print out the context tree. Use this information to open a pull-request or an issue to add support.

License

MIT

nvim_context_vt's People

Contributors

6cdh avatar amaanq avatar andersevenrud avatar delphinus avatar figsoda avatar findnextstep avatar haringsrob avatar i3d avatar ippachi avatar luozhiya avatar lyokha avatar madlep avatar mortymacs avatar nawordar avatar p00f avatar ryoppippi avatar tamago324 avatar topaxi avatar winston0410 avatar yutkat 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  avatar  avatar

nvim_context_vt's Issues

Duplicate virtual text

I'm not really sure if this is something that very recently started happening, but I'm getting duplicate virtual texts when I go deeper into a tree.

Setup

NVIM v0.7.0-dev+811-gb0993bdc4
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by anders

nvim-treesitter checkhealth:

  - OK: `tree-sitter` found  0.20.1 (parser generator, only needed for :TSInstallFromGrammar)
  - OK: `node` found v17.2.0 (only needed for :TSInstallFromGrammar)
  - OK: `git` executable found.
  - OK: `cc` executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }
    Version: cc (GCC) 11.1.0
  - OK: Neovim was compiled with tree-sitter runtime ABI version 13 (required >=13). Parsers must be compatible with runtime ABI.

Installed nvim-treesitter HEAD:

fa2a6b68aaa6df0187b5bbebe6cbadc120d4a65a

Minimum reproducible configuration

require("packer").startup(function(use)
        use "wbthomason/packer.nvim"
        use {
                "nvim-treesitter/nvim-treesitter",
                config = function()
                        require'nvim-treesitter.configs'.setup {
                                ensure_installed = "maintained",
                                highlight = {
                                        enable = true,
                                },
                        }
                end
        }
        use {
                "haringsrob/nvim_context_vt",
                requires = { "nvim-treesitter/nvim-treesitter" }
        }
end)

Visualization

Watch as I step through every line of the configuration above in an isolated environment from my regular setup:

Ignore the difference in configuration from above example as I moved some text around for testing purposes

nvim_context_vt-bug-2022-01-03_18.26.51.mp4

Additional information

This is the output when I'm on line 2 using :lua require 'nvim_context_vt'.showDebug():

current type
function_definition
parent type
arguments

Rename project to `context-vt.nvim` ?

Using kebab-case and .nvim suffix seems to be the most common naming convention.

So maybe renaming this project to context-vt.nvim makes sense ?

Or maybe ts-context-vt.nvim ?

Show catch and show function name

Hello, I found two case that are not handled correctly

  • Catch block are ignored
    image
  • Some argument block don't show the parenthesis function name
    image

Update README demo GIF

This is probably due for an update. Would be nice to have a recording edited without all the typing [out character by character] and some more contexts beside functions to showcase this plugin.

Config option to start disabled

This seems like a really useful plugin. Would it be possible to have an option to start disabled? I installed it and am playing with it but my editor environment can get quite noisy and I like to toggle things on and off when I want them. E.g. I use blamer.nvim very occasionally. It's indispensible when I want it turned on, but I don't want it turned on very often. It seems I would want nvim_context_vt turned on more often, but still not all the time (and not by default at startup).

Error when using setup({...})

I'm using packer.nvim as package manager and in

require('packer').startup(function(use)
  use {
...

call setup() from respective plugin config parameter

...
    {
      'haringsrob/nvim_context_vt',
      config = function ()
        require("nvim_context_vt").setup({
          prefix = ' In:',
        })
      end
    },
...

That results in nvim startup error:
p6R8uk3nj9

Plugin works fine when I don't call setup().

OS: Arch Linux

$ nvim --version                                                                                                                                     15:30:46
NVIM v0.6.1
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by builduser

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/share/nvim"

Run :checkhealth for more info

Getting error when viewing help doc

Just started seeing this today, I am getting an error when viewing help anything

Error detected while processing BufReadPost Autocommands for "*":
Error executing lua callback: /tmp/.mount_nvimNISZ7o/usr/share/nvim/runtime/filetype.lua:21: Error executing lua: /tmp/.mount_nvimNISZ7o/usr/share/nvim/runtime/filetype.lua:22: Vim(append):Error executing lua ca
llback: ...SZ7o/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:219: query: invalid node type at position 14 for language help
stack traceback:
        [C]: in function '_ts_parse_query'
        ...SZ7o/usr/share/nvim/runtime/lua/vim/treesitter/query.lua:219: in function 'get_query'
        ...r/share/nvim/runtime/lua/vim/treesitter/languagetree.lua:52: in function 'new'
        ...nvimNISZ7o/usr/share/nvim/runtime/lua/vim/treesitter.lua:45: in function '_create_parser'
        ...nvimNISZ7o/usr/share/nvim/runtime/lua/vim/treesitter.lua:96: in function 'get_parser'
        ...nvimNISZ7o/usr/share/nvim/runtime/lua/vim/treesitter.lua:330: in function 'start'
        ...m/lazy/nvim-treesitter/lua/nvim-treesitter/highlight.lua:19: in function 'attach'
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:505: in function 'attach_module'
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:528: in function 'reattach_module'
        ...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:131: in function <...vim/lazy/nvim-treesitter/lua/nvim-treesitter/configs.lua:130>
        [C]: in function 'nvim_cmd'
        /tmp/.mount_nvimNISZ7o/usr/share/nvim/runtime/filetype.lua:22: in function </tmp/.mount_nvimNISZ7o/usr/share/nvim/runtime/filetype.lua:21>
        [C]: in function 'nvim_buf_call'
        /tmp/.mount_nvimNISZ7o/usr/share/nvim/runtime/filetype.lua:21: in function </tmp/.mount_nvimNISZ7o/usr/share/nvim/runtime/filetype.lua:10>
stack traceback:
        [C]: in function 'nvim_cmd'
        /tmp/.mount_nvimNISZ7o/usr/share/nvim/runtime/filetype.lua:22: in function </tmp/.mount_nvimNISZ7o/usr/share/nvim/runtime/filetype.lua:21>
        [C]: in function 'nvim_buf_call'
        /tmp/.mount_nvimNISZ7o/usr/share/nvim/runtime/filetype.lua:21: in function </tmp/.mount_nvimNISZ7o/usr/share/nvim/runtime/filetype.lua:10>
stack traceback:
        [C]: in function 'nvim_buf_call'
        /tmp/.mount_nvimNISZ7o/usr/share/nvim/runtime/filetype.lua:21: in function </tmp/.mount_nvimNISZ7o/usr/share/nvim/runtime/filetype.lua:10>

I would guess this error occurs on any buffer that doesn't have a treesitter language associated with it.

Minimal config

require('nvim_context_vt').setup({disable_ft = {"help"})

System details (I don't know if this is helpful but better to have too much info than not enough)

$ nvim --version
NVIM v0.9.0-dev-213+gcc5b7368d
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3
Compilation: /usr/bin/gcc-10 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1 -DNVIM_TS_HAS_SET_MATCH_LIMIT -DNVIM_TS_HAS_SET_ALLOCATOR -O2 -g -Og -g -Wall -Wextra -pedantic -Wno-unused-parameter -Wstrict-prototypes -std=gnu99 -Wshadow -Wconversion -Wdouble-promotion -Wmissing-noreturn -Wmissing-format-attribute -Wmissing-prototypes -Wimplicit-fallthrough -Wvla -fstack-protector-strong -fno-common -fdiagnostics-color=always -DINCLUDE_GENERATED_DECLARATIONS -D_GNU_SOURCE -DNVIM_MSGPACK_HAS_FLOAT32 -DNVIM_UNIBI_HAS_VAR_FROM -DMIN_LOG_LEVEL=3 -I/__w/neovim/neovim/build/cmake.config -I/__w/neovim/neovim/src -I/__w/neovim/neovim/.deps/usr/include -I/usr/include -I/__w/neovim/neovim/build/src/nvim/auto -I/__w/neovim/neovim/build/include
Compiled by root@56f30731e0be

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/__w/neovim/neovim/build/nvim.AppDir/usr/share/nvim"

Run :checkhealth for more info

Current revision in use

$ git log -1
commit e592a9142fbfe0878ce886cd0d745963604c61d2

Not really sure what I am doing wrong, this is a new issue I haven't seen before with nvim_context_vt. Ideas?

[suggestion] upload asset on github

Thanks for this nice plugin.

I noticed that you have a >3Mb demo gif file that is used in the readme. It would be a better experience and make your plugin lighter if you can upload that on GitHub as GitHub already supports file uploads for readme.

Add blacklist option

Currently the easiest way to add custom filtering of nodes is to either hook into the validator or the virtual text parser.

It would be nice to have the option to have the option blacklist_targets via the setup() method as an alternative that just provides a table for simplicity.

Golang nested struct doesn't work

Hi,

In Golang, when we have nested struct it doesn't work completely:
image

While it works fine in nested dictionary:
image

My config:

require("nvim_context_vt").setup({
  disable_virtual_lines = true,
  disable_ft = { "markdown", "yaml" },
})

Thank you!

Toggle option

Is it possible to add a toggle option so I can enable/disable it on the fly?

Something like

:ToggleNvimContextVT

[FR] print Lua variable names when function is assigned to a variable

I was just testing this plugin to see if I will add it to my new configuration.

If I do the following in Lua an anonymous function assigned to a variable.

{ 'andersevenrud/nvim_context_vt'
     config = function()
         -- do something
     endfunction
},

The plugin works by showing the closing function.
However, it would be useful to show the variable name that the function is assigned to.
Something like ...

endconfig => function

of course, this is probably the same for other language support.

Possible to show virtual text no matter where the cursor is?

As can be seen in the gif in the readme, the virtual text is only visible if the cursor is inside a scope block.

Is there an option to show it no matter where the cursor is?

Current behavior:

A {
<CURSOR IS HERE>
} --> A {

🡇

A {

} 
<CURSOR IS HERE>

Desired behavior:

A {
<CURSOR IS HERE>
} --> A {

🡇

A {

} --> A {
<CURSOR IS HERE>

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.