question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add support for capture groups in onEnterRules

See original GitHub issue

From @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:open
  • Created 7 years ago
  • Reactions:11
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hedietcommented, May 3, 2021

Before:

// comment
//     indented|

After:

// comment
//     indented
//     |

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:

/**
 * Example:
 * ```ts
 * class Foo { <<User types enter here>>
 *
 * ```
 *
 */
function bar() {}

Ideally, the outer and inner typescript rules would be combined somehow, yielding this:

/**
 * Example:
 * ```ts
 * class Foo {
 *     <<New Cursor Position>>
 *
 * ```
 *
 */
function bar() {}

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.

1reaction
jriekencommented, Feb 4, 2021

Right, using $1 (no curly brackets) is a good fit

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found