Add support for capture groups in onEnterRules
See original GitHub issueFrom @siegebell in https://github.com/Microsoft/vscode/issues/3088#issuecomment-267236002
Before:
// comment
// indented|
After:
// comment
// indented
// |
For this case, onEnterRules
could be extended to support matching groups like find/replace currently does…
languages.setLanguageConfiguration(modeID, {
onEnterRules: [
{ // insert comment on new line while preserving the indent
beforeText: /^\s*(\/\/\s*)\S.*$/,
action: { indentAction: IndentAction.None, appendText: '$1' }
}
]
});
Issue Analytics
- State:
- Created 7 years ago
- Reactions:11
- Comments:5 (5 by maintainers)
Top Results From Across the Web
Are named capture groups supported? If so, how to engage?
I understand that VSCode uses the JavaScript regex engine for its functionality. The latest JavaScript specification allows for named capture ...
Read more >January 2021 (version 1.53) - Visual Studio Code
Configure tab decorations - Add editor tab status decorations. Customize search mode - Use the Search view or open a new Search editor....
Read more >Capturing groups - The Modern JavaScript Tutorial
Capturing groups. A part of a pattern can be enclosed in parentheses (...) . This is called a “capturing group”. That has two...
Read more >Capturing Groups and Backreferences
Feature Syntax JGsoft.NET Java Perl PCRE PCRE2 PHP Delphi R
Capturing group (regex) YES YES YES YES YES YES YES YES YES
Capturing group \(regex\)...
Read more >Grouping Constructs in Regular Expressions - Microsoft Learn
The following table lists the grouping constructs supported by the . ... The regular expression pattern's two capturing groups represent the ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
For me, there are two indentations in this example. The indentation of the comment and the indentation of the text within the comment. I find it strange to use two different strategies to handle these indentations (explicit indent/dedent/none actions of the onEnter rule vs regex whitespace group references in the insert text).
Is there a scenario where it makes sense to reference a regex group that matches non-whitespace text?
Also, should indentation/dedentation be supported for nested indentations (rather than just keeping the indentation as is)?
Maybe it might also be valuable to consider embedded languages in general. Imagine using a markdown codeblock in doc-comments:
Ideally, the outer and inner typescript rules would be combined somehow, yielding this:
Currently VS Code ignores the rules of the inner language.
This feature would not fix #66235 anyway.
I think this feature might require more discussions. Until then, it could be investigated how parts of this feature can be implemented by extensions listening on
onDidChangeTextDocument
and issuing edits and selection updates instead.Right, using
$1
(no curly brackets) is a good fit