Investigation: TextMate grammar limitations prevent multiline attribute fix#5614
Conversation
Co-authored-by: KazariEX <85992002+KazariEX@users.noreply.github.com>
Co-authored-by: KazariEX <85992002+KazariEX@users.noreply.github.com>
Co-authored-by: KazariEX <85992002+KazariEX@users.noreply.github.com>
Co-authored-by: KazariEX <85992002+KazariEX@users.noreply.github.com>
|
@copilot This modification still does not make |
You're right! I've updated the lookahead patterns for language-specific matching, but the fallback
You're absolutely right! I've confirmed the issue - both my original I need to implement a completely different approach that doesn't rely on lookahead assertions. The correct solution likely involves restructuring the grammar patterns to use step-by-step parsing instead of trying to detect the language upfront in the
You are completely correct! I've now confirmed through extensive testing that all lookahead-based approaches fail in TextMate grammars for multiline scenarios:
Even with the most comprehensive regex patterns, multiline script/style tags still fall back to generic The proper solution requires a complete architectural restructure of the grammar to move away from lookahead assertions entirely. This is beyond a simple regex fix and needs a different approach to how the grammar parses and scopes script/style tags. Thank you for pointing out this fundamental limitation - you saved me from continuing down an impossible path. Commit da69545 shows the final failed attempt. |
This PR investigates and documents the fundamental limitations of TextMate grammars that prevent fixing multiline attribute handling in Vue syntax highlighting.
Problem
When VSCode's
html.format.wrapAttributessetting is set to"force-expand-multiline", it causes syntax highlighting to break for script and style blocks with language attributes:The grammar fails to detect the
lang="ts"attribute and falls back to generic scoping, causing TypeScript code to be highlighted as JavaScript instead.Investigation Results
Through extensive testing, this PR confirms that TextMate grammar lookahead assertions have fundamental limitations with multiline patterns that cannot be resolved through regex modifications alone.
Attempted Solutions (All Failed)
(?:[^>\\n]*\\n)*[^>]*[\\s\\S]*?[^>]*(?:\\n[^>]*)*All approaches result in multiline tags falling back to generic
source.vuescoping instead of language-specific scoping likesource.ts,source.jsx,source.scss, etc.Root Cause
TextMate grammar engines process content with inherent limitations on how lookahead assertions (
(?=...)) work across multiple lines. The issue cannot be solved by modifying the lookahead patterns - it requires a fundamental architectural change to the grammar structure.Proper Solution Required
The correct fix would need to:
beginpatternsThis investigation confirms that the reported issue requires a major grammar rewrite rather than a simple pattern fix.
Relates to #3999.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.