microsoft / microsoft/vscode

Support "on-delete rules" mirroring `onEnterRules`, to strip comment leaders on backward-merge

Open
#336,145 0 comments 2 reactions 1 assignee Claimed by @hediet View on GitHub
Dominant language
TypeScript
Stars
193k
Forks
42.4k
PR merge metrics
PR metrics pending

Description

VS Code currently supports [`onEnterRules`](https://code.visualstudio.com/api/language-extensions/language-configuration-guide#on-enter-rules), which let a language declare, up-front in its language configuration, how the editor should auto-continue things like comment markers (`///`, `//`, `*`, `#`, etc.) when the user presses Enter inside a matching context. This works entirely in the VS Code UI process, so it stays fast — no per-keystroke round-trip to an extension host.

There's no equivalent for the reverse operation: when the user presses **Delete** at the end of a line to merge it with the next line, and that next line starts with a comment leader (e.g. `///`, `//`, `*`, `#`, etc), VS Code doesn't know to strip that leader as part of the merge. So:

```dart
/// This line^
/// More text
class Foo;
```

Pressing Delete at the caret currently produces:

```dart
/// This line/// More text
class Foo;
```

instead of the expected:

```dart
/// This line More text
class Foo;
```

Today, the only way for an extension to fix this up is to intercept every keypress and handle the merge itself, which — per [microsoft/vscode#75627](https://github.com/microsoft/vscode/issues/75627) — causes noticeable input lag, since it moves typing/deletion out of the UI process and into the extension host.

**Feature request:** add a declarative counterpart to `onEnterRules` — something like `onDeleteRules` (or extend `onEnterRules` with a "reverse" mode) — that lets a language configuration declare a pattern to strip when Delete/Backspace merges a line starting with that pattern into the previous line. This would be handled in the UI process the same way `onEnterRules` is, avoiding the performance cost of per-keystroke extension-host handling.

This wouldn't just help Dart doc comments — it'd benefit any language with continuation-style comment markers (JSDoc `*`, `//`, `#`, etc.).

CC @DanTup

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.