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:
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>",{})
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
Write a // ^?
placing the sign ^
under the variable to inspected:
const variableToInspect = ....
// ^?
: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
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.