marilari88/twoslash-queries.nvim

github github
lspneovim-0.5
stars 128
issues 2
subscribers 4
forks 6
CREATED

2022-10-05

UPDATED

3 months ago


twoslash-queries.nvim

Written in lua for nvim

Inspired by vscode-twoslash-queries, this plugin allows you to print typescript types as inline virtual text and dynamically update it instantly without having to move the cursor over the inspected variable

This is particularly useful when you are playing with complex typescript types:

"Added @typescript twoslash support to vscode with this little extension and I couldn't be happier with it"

twoslashqueries

How to install it

Packer

use("marilari88/twoslash-queries.nvim")

Make sure you have typescript language server properly installed and configured (personally I use Mason and Lspconfig plugins)

Then attach it on your tsserver in lspconfig setup

require("lspconfig")["tsserver"].setup({
    on_attach = function(client, bufnr)
       require("twoslash-queries").attach(client, bufnr)
    end,
})

Optionally you can define a custom keymap for TwoslashQueriesInspect command

vim.api.nvim_set_keymap('n',"<C-k>","<cmd>TwoslashQueriesInspect<CR>",{})

Config

You can override default config use setup function:

use({
   "marilari88/twoslash-queries.nvim",			
    config = function()
        require("twoslash-queries").setup({
            multi_line = true, -- to print types in multi line mode
            is_enabled = false, -- to keep disabled at startup and enable it on request with the TwoslashQueriesEnable 
            highlight = "Type", -- to set up a highlight group for the virtual text
       })
    end,
})

Default config:

  • multi_line = false
  • is_enabled = true

Usage

Write a // ^? placing the sign ^ under the variable to inspected:

const variableToInspect = ....
//      ^?

Custom commands

:TwoslashQueriesEnable Enable the plugin for the current session

:TwoslashQueriesDisable Disable the plugin for the current session

:TwoslashQueriesInspect Inspect variable under the cursor

:TwoslashQueriesRemove Remove all twoslash queries in the current buffer

Commands

:gift: Contributing

Please raise a PR if you are interested in adding new functionality or fixing any bugs. When submitting a bug, please include an example spec that can be tested.