Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marilari88/twoslash-queries.nvim
Nvim lua plugin which adds support for twoslash queries into typescript projects
https://github.com/marilari88/twoslash-queries.nvim
lua nvim plugin typescript
Last synced: about 2 months ago
JSON representation
Nvim lua plugin which adds support for twoslash queries into typescript projects
- Host: GitHub
- URL: https://github.com/marilari88/twoslash-queries.nvim
- Owner: marilari88
- License: mit
- Created: 2022-10-05T18:39:04.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-25T21:46:22.000Z (3 months ago)
- Last Synced: 2024-06-25T22:58:54.398Z (3 months ago)
- Topics: lua, nvim, plugin, typescript
- Language: Lua
- Homepage:
- Size: 25.4 KB
- Stars: 135
- Watchers: 4
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-neovim - marilari88/twoslash-queries.nvim - Provide inline virtual text displaying TypeScript types for the inspected variables. (LSP / (requires Neovim 0.5))
README
# twoslash-queries.nvim
Written in lua for nvimInspired by [vscode-twoslash-queries](https://github.com/orta/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"](https://twitter.com/tannerlinsley/status/1564254580715560960?s=20&t=E0Ap8W6vsFZhHyZFYlt_5w)![twoslashqueries](https://user-images.githubusercontent.com/32909388/204164892-3c1444d3-8f2d-4c6d-8c1a-b812f1e4c657.gif)
## How to install it
### Packer
```lua
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
```lua
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
```lua
vim.api.nvim_set_keymap('n',"","TwoslashQueriesInspect",{})
```
## Config
You can override default config use setup function:
```lua
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:
```typescript
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](https://github.com/undg/twoslash-queries.nvim/assets/32909388/55743a48-2250-4ca2-930d-ca0a310286e6)
## :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.