bennypowers / nvim-regexplainer Goto Github PK
View Code? Open in Web Editor NEWDescribe the regexp under the cursor
Describe the regexp under the cursor
regexplainer seems to use nui popups that always have the "shadow" border style. Since all my other popups have a different border style, it would be nice if they were consistent, meaning an option to change the popup border style would be very useful.
I'm unable to get this to run.
I first tried installing it in an lazy-idiomatic way:
{
"bennypowers/nvim-regexplainer",
dependencies = {
"nvim-treesitter/nvim-treesitter",
"MunifTanjim/nui.nvim",
},
keys = {
{
"<leader>cx",
"<cmd>Regexplainer<cr>",
desc = "Explain regex",
mode = "n",
},
},
},
Since this didn't work, I then tried to install it like in the documentation:
{
"bennypowers/nvim-regexplainer",
dependencies = {
"nvim-treesitter/nvim-treesitter",
"MunifTanjim/nui.nvim",
},
config = function()
-- defaults
require'regexplainer'.setup {
-- 'narrative'
mode = 'narrative', -- TODO: 'ascii', 'graphical'
-- automatically show the explainer when the cursor enters a regexp
auto = false,
-- filetypes (i.e. extensions) in which to run the autocommand
filetypes = {
'html',
'js',
'cjs',
'mjs',
'ts',
'jsx',
'tsx',
'cjsx',
'mjsx',
},
-- Whether to log debug messages
debug = false,
-- 'split', 'popup'
display = 'popup',
mappings = {
toggle = 'gR',
-- examples, not defaults:
-- show = 'gS',
-- hide = 'gH',
-- show_split = 'gP',
-- show_popup = 'gU',
},
narrative = {
indendation_string = '> ', -- default ' '
},
}
end,
},
However, this isn't working either. I reinstalled the treesitter parsers using :TSInstall regex typescript
, but to no avail.
Support for other forms of regex would be awesome โ especially since as a nvim-user, you have to know vimscript patterns, lua patterns, and most likely js regex, it sometimes gets a bit confusing.
For lua patterns, I know there is this repo which visualizes lua patterns quite decently, maybe you could make use of that? https://github.com/GitSparTV/lua-patterns
It seems that when the initial position of the cursor is on the regular expression when the program starts, the auto option causes an error.
Currently I can only reproduce the examples in the readme, and failed to get the popup in other lang, like bash
or lua
? Is this plugin js/ts specific?
P.S. I had already install the regex
bash
lua
ts parsers and set them in regexplainer
's config
with this config, one can't show a split using :RegexplainerShowSplit
require'regexplainer'.setup {
auto = true,
display = 'popup',
}
I believe that what's happening is the split is open with the command, but that triggers the autocommand which closes the split, then reopens the popup
I have just installed nvim-regexplainer but I cannot get it to actually show up.
I use lunarvim (nvim with config from lunarvim.org) but the config etc is the usual lua way:
{ 'bennypowers/nvim-regexplainer',
requires = {
'nvim-lua/plenary.nvim',
'MunifTanjim/nui.nvim',
},
config = function() require'regexplainer'.setup({
-- 'narrative'
mode = 'narrative', -- TODO: 'ascii', 'graphical'
-- automatically show the explainer when the cursor enters a regexp
auto = true,
-- Whether to log debug messages
debug = false,
-- 'split', 'popup'
display = 'popup',
mappings = {
toggle = 'gR',
-- examples, not defaults:
-- show = 'gS',
-- hide = 'gH',
show_split = 'gP',
show_popup = 'gU',
},
narrative = {
separator = '\n',
},
})
end,
}
I can see that it is loaded (the gR, gH etc mappings are available and also the :RegexplainerShow etc) but nothing happens when I call any of them. Nothing in :messages - even when I call :RegexplainerDebug
nvim version 0.7.0-dev
any idea?
Hi, love the plugin! Will make writing regex so much better. I'm wondering if this is either a bug or needs implementing; I want to have auto = false
for the config, so I have to manually show the popup, but then when I move my cursor away on to a different line, it auto hides. Currently the popup persists until I hide it/toggle it off again. Not a deal breaker but more keystrokes than necessary!
The project has grown to the point that manual testing is no longer sufficient
We need automated tests that will cover at least the following:
I've briefly glanced at busted but that seems insufficient on it's own, since so much of what the plugin does relies on treesitter and nui. What we need are proper integration tests.
/elements@\d\.\d\.\d\/elements\/.*lightdom\.css$/;
EXPECTED:
`elements@`
**0-9**
`.`
**0-9**
`.`
**0-9**
`/elements/`
**ANY** (_>= 0x_)
`lightdom.css`
**END**
ACTUAL:
`elements@`
**d.**
**d.**
`\\d/elements/`
**ANY** (_>= 0x_)
`lightdom.css`
**END**
Awesome idea!
I tried a simple regex in a scratch buffer:
let reggie = /^p[^p]*p/
Regexplainer incorrectly explains it like so:
START
`p`
One of ^, or p (>= 0x)
`p`
The first caret is correctly explained as the "start" anchor, but the second caret is interpreted as part of the character list.
The first caret inside square brackets actually negates the character list.
So maybe the output of regexplainer would be:
START
`p`
Any character not in the list: `p` (>= 0x)
`p`
And for a character list with multiple characters, e.g. /^p[^p^a]*p/
:
START
`p`
Any character not in the list: `p`, `^`, `a` (>= 0x)
`p`
This is how regex101 treats that last example: https://regex101.com/r/mGQXlb/1
I'd like to use this plugin but as someone averse to clutter installing nui.nvim for this single plugin just does not warrant it.
If you are ok with the addition of this feature I could make the PR myself.
Hi, I think it'll be a very beneficial feature to be able to set one keybinding for both hiding and showing the explainer based on its current state, or at least having a default binding to be able to exit from open windows with <Esc>
.
Hi, it would be nice to be able to set transparency of the popup window using vim.api.nvim_win_set_option(winnr, "winblend", ?)
, where ?
can be passed in as a config option :))
Hello Guys,
i wanted to try this amazing plugin.
But calling any of the provided Regexplain functions as well as the autocmd don't work.
I tried creating files with supported filetypes and several keybindings formats.
Is this error just in the latest release?
Best regards
The new version of regex parser (https://github.com/tree-sitter/tree-sitter-regex/pull/15/files) supports lookbehind (under the new name lookaround
)
SO let's suport that here.
Hi, Is there a way set popup window borders?
Nice plugin btw.
Thanks.
User donbex at neovim discourse noted that some escape chars and alternation terms were missing from explanations
to wit:
let re = /@scope\/(.*)\.(?<extension>graphql|(?:t|j|cs)s)";?/;
^ ^
was missing the escaped .
after the first anonymous capture group, and the s
following the (cs)
capture group
in certain HTML files, Regexplainer can try too hard to find a pattern in start_tag, end_tag, or text nodes. I don't have a minimal repro, but check rh-audio-player detailed-transcript.html demo, particularly in the cue elements
Currently, regex like /[\u005D-\uFFFF]/
: is parsed as a set of literals, not as a unicode range:
One of `u`, `0`, `0`, `5`, `D-\\u`, `F`, `F`, `F`, or `F`
It should be something like:
One of \u005D-\uFFF
/(['"]).*?\1/g
EXPECTED:
capture group 1:
> One of `'`, or `"`
**ANY** (_>= 0x_) (_lazy_)
(capture group 1)
ACTUAL:
capture group 1:
> One of `'`, or `"`
**ANY** (_>= 0x_) (_lazy_)
`1`
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.