Open imbrish opened 3 years ago
That's expected behavior.
The clear_scopes
command is so to say a counter part of meta_scope
and behaves like that with regards to boundaries. It means it clears meta scopes from current context including the region captured by the initial match, which pushed the context onto stack.
You need an intermediate context to solve that issue
preprocessor:
- match: '^(?=\s*#)'
push:
- match: '#'
set:
- clear_scopes: true
- meta_content_scope: support.function
- match: '(?=\s*$)'
pop: true
What we'd need to solve such kinds of issues was a clear_content_scopes
as counter part of meta_content_scopes
to support your kind of use case. I already had 1 or 2 situations when I whished something like that, too.
The main purpose of clear_scopes
is to support things like string interpolation by removing the string
scope within the whole interpolation region, which normally includes opening and closing punctuation.
I understand your point. The match that clears the scopes is included in the main context, so it clears the scopes of the main context. But when the pushed scope pops, it should no longer apply, right?
But even if that's the expected behavior, then it is still inconsistent. My point is that it affects further matches in a weird way:
#
in the first line when the syntax file is saved, the scopes from the other lines will never be cleared, even if #
is added back. If #
is present when the syntax is saved, the scopes will always be cleared, even if #
is deleted.I see what you mean.
The clear_scope
command is applied to the consuming part of \s*(?=#)
even though the pattern does not fully match and thus the context which contains clear_scope
not to be pushed onto stack. Thus that command should not have an effect at all on lines other than 1.
That's a bug.
I can still reproduce it on ST 4094 even with setting sublime-syntax to version: 2
.
I think the issue is even more involved than that. Note, that what we match is actually ^\s*(?=#)
, with ^
in front, so it should only ever match at the start of a line. But it does not clear scopes only on starting spaces, it clears scopes on anything that is subsequently matched, as long as no new scopes are added. You could try this by replacing \s*
with -*
. It still has the exact same effect.
Description
When
clear_scopes: true
is used in a context with a lookahead inmatch
, the scopes will also be cleared for text matched in other contexts, if the matched text has no explicit scope assigned.Steps to reproduce
Syntax Minimal.sublime-syntax
in the User package:contexts: main:
include: section
preprocessor:
match: '^\s*(?=#)' push:
section:
this line with spaces in front is necessary
scopes here are just fine
[but_are_cleared_around_this]
Syntax Minimal
to theTest Minimal.txt
.Expected behavior
Actual behavior
[this]
will always be cleared.captures
will causeinvalid.illegal
to be cleared from the whole line.match: '^\s*(?=#)'
withmatch: '^(?=\s*#)'
ie. moving the whole match into lookahead, fixes the issue.Environment