Skip to content

[folding] Support pattern+flags object syntax on folding.markers RegExps - #312679

Merged
Martin Aeschlimann (aeschli) merged 6 commits into
mainfrom
copilot/enhance-folding-markers-regexps
Jun 1, 2026
Merged

Martin Aeschlimann (aeschli) merged 6 commits into
mainfrom
copilot/enhance-folding-markers-regexps

Conversation

Copilot AI commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

folding.markers.start and folding.markers.end in language-configuration.json only accepted plain strings, with no way to specify regexp flags (e.g., case-insensitive matching). wordPattern and indentationRules already support a { pattern, flags } object form — this brings folding.markers to parity.

Changes

  • Schema (languageConfigurationExtensionPoint.ts): Changed folding.markers.start and folding.markers.end from type: 'string' to type: ['string', 'object'] with pattern and flags sub-properties (flags validated against ^([gimuy]+)$). This eliminates the spurious "Incorrect type. Expected: string" schema warning when the object form was used.
  • Comment (languageConfiguration.ts): Removed the stale JSDoc note saying "regexp flags (i, g) are ignored" — the underlying _parseRegex helper already handled the object form; only the schema was incorrectly rejecting it.
  • Runtime (indentRangeProvider.ts): When markers.start and markers.end share the same flags, a single combined RegExp is built with those flags. When the flags differ, two separate regexes are used and tested independently per line — preventing one marker's flags from incorrectly being applied to the other.

Example

"folding": {
  "markers": {
    "start": { "pattern": "^\\s*#region\\b", "flags": "i" },
    "end":   { "pattern": "^\\s*#endregion\\b", "flags": "i" }
  }
}

Mixed flags are also supported:

"folding": {
  "markers": {
    "start": { "pattern": "^\\s*#region\\b", "flags": "i" },
    "end":   { "pattern": "^\\s*#endregion\\b" }
  }
}

Copilot AI requested review from Copilot and removed request for Copilot April 27, 2026 08:32
Copilot AI changed the title [WIP] Support flags on folding.markers RegExps [folding] Support pattern+flags object syntax on folding.markers RegExps Apr 27, 2026
@aeschli

Copy link
Copy Markdown
Contributor

Copilot This also needs adoption here:

pattern = new RegExp(`(${markers.start.source})|(?:${markers.end.source})`);

pattern = new RegExp((${markers.start.source})|(?:${markers.end.source}));

Copilot AI requested review from Copilot and removed request for Copilot April 29, 2026 09:23

Copilot AI commented Apr 29, 2026

Copy link
Copy Markdown
Contributor Author

Copilot This also needs adoption here:

pattern = new RegExp(`(${markers.start.source})|(?:${markers.end.source})`);

`pattern = ...

Fixed in 026d4db. The flags from markers.start and markers.end are now merged (deduplicated) and applied to the combined pattern:

const flags = [...new Set([...markers.start.flags, ...markers.end.flags])].join('');
pattern = new RegExp(`(${markers.start.source})|(?:${markers.end.source})`, flags);

let pattern: RegExp | undefined = undefined;
if (markers) {
pattern = new RegExp(`(${markers.start.source})|(?:${markers.end.source})`);
const flags = [...new Set([...markers.start.flags, ...markers.end.flags])].join('');

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot Merging the flags can result in modified regexes. If the flags are not the same, two separate regexes are needed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. When markers.start.flags === markers.end.flags, a single combined regex is used as before. When the flags differ, startPattern and endPattern are kept as separate regexes and each is tested independently per line, so neither pattern picks up the other's flags.

Copilot AI requested review from Copilot and removed request for Copilot May 11, 2026 15:49
Copilot AI review requested due to automatic review settings June 1, 2026 15:11
@aeschli
Martin Aeschlimann (aeschli) marked this pull request as ready for review June 1, 2026 15:12
@aeschli
Martin Aeschlimann (aeschli) enabled auto-merge (squash) June 1, 2026 15:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR brings folding.markers.start / folding.markers.end in language-configuration.json up to parity with other language configuration RegExp fields by allowing the { pattern, flags } object form (enabling explicit RegExp flags), and updates folding range computation to correctly handle stateful flags.

Changes:

  • Extend the language-configuration JSON schema to accept { pattern, flags } objects for folding markers.
  • Adjust folding marker matching logic to avoid incorrect behavior when marker RegExps use stateful flags (e.g. g).
  • Add tests covering parsing of { pattern, flags } for folding markers and folding behavior with stateful flags.
Show a summary per file
File Description
src/vs/workbench/contrib/codeEditor/test/node/autoindent.test.ts Adds a parsing test ensuring folding markers support { pattern, flags }.
src/vs/workbench/contrib/codeEditor/common/languageConfigurationExtensionPoint.ts Updates the language configuration schema so folding markers accept string-or-object RegExp definitions.
src/vs/editor/contrib/folding/test/browser/indentRangeProvider.test.ts Adds coverage for folding with stateful RegExp flags (g, gi) on markers.
src/vs/editor/contrib/folding/browser/indentRangeProvider.ts Updates marker matching to handle differing flags and reset lastIndex for stateful regexes.
src/vs/editor/common/languages/languageConfiguration.ts Removes stale JSDoc claiming folding marker flags are ignored.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 3

if (markers) {
pattern = new RegExp(`(${markers.start.source})|(?:${markers.end.source})`);
if (markers.start.flags === markers.end.flags) {
pattern = new RegExp(`(${markers.start.source})|(?:${markers.end.source})`, markers.start.flags);
Comment on lines +758 to +764
flags: {
type: 'string',
description: nls.localize('schema.folding.markers.start.flags', 'The RegExp flags for the start marker.'),
default: '',
pattern: '^([gimuy]+)$',
patternErrorMessage: nls.localize('schema.folding.markers.start.errorMessage', 'Must match the pattern `/^([gimuy]+)$/`.')
}
Comment on lines +776 to +782
flags: {
type: 'string',
description: nls.localize('schema.folding.markers.end.flags', 'The RegExp flags for the end marker.'),
default: '',
pattern: '^([gimuy]+)$',
patternErrorMessage: nls.localize('schema.folding.markers.end.errorMessage', 'Must match the pattern `/^([gimuy]+)$/`.')
}
@aeschli
Martin Aeschlimann (aeschli) merged commit 8b203d3 into main Jun 1, 2026
26 checks passed
@aeschli
Martin Aeschlimann (aeschli) deleted the copilot/enhance-folding-markers-regexps branch June 1, 2026 17:39
@vs-code-engineering vs-code-engineering Bot added this to the 1.124.0 milestone Jun 1, 2026
roblourens added a commit that referenced this pull request Jun 4, 2026
PR #312679 (folding markers pattern+flags syntax) removed a doc line
from FoldingMarkers in languageConfiguration.ts but didn't regenerate
src/vs/monaco.d.ts. Picking up the regeneration so the monaco-d.ts
check passes.

Co-authored-by: Copilot <[email protected]>
roblourens added a commit that referenced this pull request Jun 5, 2026
#319456)

* agentHost: narrow Copilot resume fallback to true empty-session errors

The catch block in CopilotAgent._doResumeSession converted *any* -32603
JSON-RPC error from client.resumeSession into a fresh session created with
the same id via client.createSession({ sessionId }). When the underlying
session file fails schema validation (e.g. a session.compaction_complete
event with batchSize: 0, rejected by @github/copilot's schema), this masked
the corruption: the user saw an empty chat instead of an error, and the
original session contents were not surfaced.

Narrow the fallback so we only recreate an empty session when the error
message clearly indicates 'no messages / empty session', and never when the
message looks like corruption / validation / parse failure. All other
-32603s now propagate so the UI and logs reflect the real failure.

Add regression tests that exercise the real _doResumeSession path via a
ResumePathCopilotAgent subclass: one confirming the empty-session fallback
still works, one confirming a corrupted-session error is no longer swallowed.

Co-authored-by: Copilot <[email protected]>

* agentHost: preserve resume fallback for Start Over / truncated sessions

The previous narrowing was too aggressive: it required the SDK error
message to match a small whitelist ('no messages', 'empty session', ...)
to trigger the fallback. But the legitimate empty-session case this
fallback exists for is post-'Start Over' / post-truncateSession, where
the SDK currently surfaces a generic 'no events' message that doesn't
match any of those phrases. The previous version would have regressed
Start Over (user truncates all turns, reopens session, gets a hard
error instead of an empty chat).

Invert the heuristic: treat any -32603 from resumeSession as the
empty-session case (preserving Start Over and any future SDK rewording)
UNLESS the message clearly indicates corruption / schema validation /
parse failure / malformed  those should propagate so the userinput
sees the real error rather than silently getting an empty session.

Refresh tests: add a Start Over / truncated-session test using a
realistic 'returned no events' message, plus an 'unknown -32603'
defensive test; keep the corruption test.

Co-authored-by: Copilot <[email protected]>

* monaco: regenerate monaco.d.ts after folding markers change

PR #312679 (folding markers pattern+flags syntax) removed a doc line
from FoldingMarkers in languageConfiguration.ts but didn't regenerate
src/vs/monaco.d.ts. Picking up the regeneration so the monaco-d.ts
check passes.

Co-authored-by: Copilot <[email protected]>

---------

Co-authored-by: Copilot <[email protected]>
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Jul 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[folding] Support flags on folding.markers RegExps

4 participants