Repository navigation
[folding] Support pattern+flags object syntax on folding.markers RegExps - #312679
Conversation
pattern+flags object syntax on folding.markers RegExps
|
Copilot This also needs adoption here: pattern = new RegExp((${markers.start.source})|(?:${markers.end.source}));
|
Fixed in 026d4db. The flags from 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(''); |
There was a problem hiding this comment.
Copilot Merging the flags can result in modified regexes. If the flags are not the same, two separate regexes are needed.
There was a problem hiding this comment.
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.
Co-authored-by: aeschli <[email protected]>
…ng-markers-regexps
There was a problem hiding this comment.
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); |
| 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]+)$/`.') | ||
| } |
| 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]+)$/`.') | ||
| } |
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]>
#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]>
folding.markers.startandfolding.markers.endinlanguage-configuration.jsononly accepted plain strings, with no way to specify regexp flags (e.g., case-insensitive matching).wordPatternandindentationRulesalready support a{ pattern, flags }object form — this bringsfolding.markersto parity.Changes
languageConfigurationExtensionPoint.ts): Changedfolding.markers.startandfolding.markers.endfromtype: 'string'totype: ['string', 'object']withpatternandflagssub-properties (flags validated against^([gimuy]+)$). This eliminates the spurious"Incorrect type. Expected: string"schema warning when the object form was used.languageConfiguration.ts): Removed the stale JSDoc note saying "regexp flags (i, g) are ignored" — the underlying_parseRegexhelper already handled the object form; only the schema was incorrectly rejecting it.indentRangeProvider.ts): Whenmarkers.startandmarkers.endshare the same flags, a single combinedRegExpis 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
Mixed flags are also supported: