-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The prototype context is not included when specifying a syntax file #1062
Comments
This affects github-flavored markdown modes quite significantly, since most language modes use |
As a temporary work-around, explicitly include the prototype scopes in |
This also affects the |
Fixes #21 Due to sublimehq/sublime_text#1062 the `prototype` context of a super syntax needs to be included into all alias syntaxes.
Fixes sublimehq#2318 Problem Description The Makefile.sublime-syntax includes the Bash.sublime-syntax. The `scope:source.shell#prototype` is injected into the embedded Bash.sublime-syntax using `with_prototype` maybe as workaround for sublimehq/sublime_text#1062 The `with_prototype` command ignores `meta_include_prototype: false`, which is heavily used by Bash.sublime-syntax to prevent the `prototype` context from being included into a bunch of contexts such as strings. Fix Description As the prototype context is not included into source.shell's main context only, it is not necessary to inject it via `with_protoype`. Hence it is moved to the `shell-body` together with `source.shell`, which is suggested by the core issue as proper workaround. Notes: The `prototype` context of the Bash.sublime-syntax also includes proper rules to pop off all contexts at eol with respect of line continuation. Hence those don't need to be part of the `with_proptype` statement as well. They are moved to just pop off the Bash's main context as soon as the eol is reached. The `source.shell.embedded` scope is applied to all embedded shell syntax regions.
If a Example Syntax A %YAML 1.2
---
name: Syntax A
scope: source.syntax-a
contexts:
main:
- include: functions
prototype:
- match: \d
scope: constant.numeric.integer.syntax-a
functions:
- match: \w+
scope: entity.name.function.syntax-a Syntax B %YAML 1.2
---
name: Syntax B
scope: source.syntax-b
contexts:
main:
- include: scope:source.syntax-a#functions If the following is typed to a new view, the number is not highlighted as constant if
This behavior makes absolutly sense as it is not obvious what happens with prototype being included implicitly as well, when picking single contexts. With a look at Bash.sublime-syntax and the way it cooperates with the auto generated commands-builtin-shell-bash.sublime-syntax any other behavior could easily result in inclusion loops, maybe. With that in mind I wonder if it was a reasonable solution to
Example %YAML 1.2
---
name: My Syntax
scope: source.my-syntax
contexts:
main:
- include: with_prototype
- include: without_prototype
with_prototype:
# include prototype of `source.c`
- include: scope:source.c
# include prototype of `source.c`
- match: blabla
push:
- include: scope:source.c
# include prototype of `source.c`
- match: blabla
push: scope:source.c
# include prototype of `source.c`
- match: blabla
set: scope:source.c
# include prototype of `source.c`
- match: blabla
embed: scope:source.c
escape: ;
without_prototype:
# do not include prototype of `source.c`
- include: scope:source.c#main
# do not include prototype of `source.c`
- match: blabla
push: scope:source.c#main
# do not include prototype of `source.c`
- match: blabla
set: scope:source.c#main
# do not include prototype of `source.c`
- match: blabla
embed: scope:source.c#main
escape: ; With regards to #2482 (comment) it would propably even make sense to limit the implicit include to direct push/set statements and embeds. Note: Find it less consistent compared with the previous solution though. Example %YAML 1.2
---
name: My Syntax
scope: source.my-syntax
contexts:
main:
# do not include prototype of `source.c`
- include: scope:source.c
# do not include prototype of `source.c`
- match: blabla
push:
- include: scope:source.c
# include prototype of `source.c`
- match: blabla
push: scope:source.c
# include prototype of `source.c`
- match: blabla
set: scope:source.c
# include prototype of `source.c`
- match: blabla
embed: scope:source.c
escape: ; |
@deathaxe I think you forgot to update a few comments in the Other than that, I support the proposal to only include the prototype for includes/pushes where no context is provided. If the prototype was undesired the syntax's |
I was getting different results (prototype was never applied to any external syntax). Turns out the issue is that the order of processing the contexts affects things, at least in the case of using include. |
It reads as the expectation was the Just to be sure - that's not the case. Hence, your result is not different from what we see, IMHO. To clarify: My recent comment is only about possibilities to give a syntax control about whether to include a syntax with or without applying its prototype. May not be sufficient though. - It is not to demonstrate any actual behavior. I guess it is not expected The main point is: if a whole syntax is included using There are two workarounds for that (nearly) out in the wild:
They might conflict or create avoidable overhead if both the included and including syntax try to fix it. The situation is just not clear. |
I spent some more time thinking about this, and I think the current behavior is more or less correct, with the possibility of one change. In short, including a context should generally never include the prototype automatically. If you are in a syntax and include a Now, when dealing with external contexts, i.e. a context from a different syntax file, things get different. If you are including a context, it is usually because you want certain patterns. At this point, things get brittle. The external syntax could be modified to rename contexts, or add/remove the prototype, etc. However, if you are specifying a context name, you are getting specific enough that you probably don't want implicitly to get the external prototype. And if you do want the external prototype, you can just include that also. Now, we could (theoretically) add syntax so when including you could explicitly ask for the prototype to be added: - include: scope:source.foo
include_prototype: true But that can be accomplished via: - include: scope:source.foo#prototype
- include: scope:source.foo So we haven't really gained anything. I don't think we'd want to change I suppose the only benefit that could be had by adding something like Perhaps the simplest option here is to just clearly document how includes work for an external syntax. The |
What I mainly have in mind when thinking about With your explanations in mind I did some tests on my end using the examples of one of my former comments. I modified them to include the The results make me fully agree with your statements above. Sublime Text behaves correctly. If we directly %YAML 1.2
---
name: My Syntax
scope: source.my-syntax
contexts:
main:
# `source.yaml#prototype` is applied implicitly
# => comments show correctly
- match: \`{3}
scope: punctuation.section.begin
push: scope:source.yaml
with_prototype:
- match: \`{3}
scope: punctuation.section.begin
pop: true
# `source.yaml#prototype` is applied implicitly
# => comments show correctly
- match: \`{3}
scope: punctuation.section.begin
embed: scope:source.yaml
escape: \`{3}
escape_captures:
0: punctuation.section.begin If we include %YAML 1.2
---
name: My Syntax
scope: source.my-syntax
contexts:
main:
# `source.yaml#prototype` is not applied implicitly
# => comments not highlighted
- match: \`{3}
scope: punctuation.section.begin
push: embedded-yaml
with_prototype:
- match: \`{3}
scope: punctuation.section.begin
pop: true
# `source.yaml#prototype` is not applied implicitly
# => comments not highlighted
- match: \`{3}
scope: punctuation.section.begin
embed: embedded-yaml
escape: \`{3}
escape_captures:
0: punctuation.section.begin
embedded-yaml:
- meta_content_scope: source.yaml.embedded.my-syntax
- include: scope:source.yaml As we have full control about whether to include the prototype, the only issue remaining is indeed a missing If we want to use such intermediate contexts such as |
This commit introduces an intermediate `embedded-javascript` context to avoid applying the `source.js` scope of the embedded syntax as we want to scope the section `source.js.embedded.html` instead. Note: When using `- include` the prototype context of the included syntax needs to be included explicitly. see: sublimehq/sublime_text#1062)
This commit introduces an intermediate `embedded-css` context to avoid applying the `source.css` scope of the embedded syntax as we want to scope the section `source.css.embedded.html` instead. Note: When using `- include` the prototype context of the included syntax needs to be included explicitly. see: sublimehq/sublime_text#1062)
If we want keep going with the current solution of an intermediate contexts to avoid a syntaxes main scope from being applied (see #2482), we definitly need something to optionally include a prototype without throwing errors. The embedded syntax may change, thus the including syntax can't know whether prototype exists or not. See how sublimehq/Packages#2397 needs to handle CSS and JavaScript differently to satisfy the CI syntax test engine. |
Build 4075 adds the option It also respects the custom |
Thanks for the fix.
Agreed, it seems quite superficial and exactly equivalent to:
Considering it's not been mentioned anywhere before and probably entirely unused in the wild, I'm not even going to add it to PackageDev. |
I would the context specified by |
What is a "subsequent context"? |
Any contexts pushed onto the current context. |
So it would be similar to Either way, that isn't how it has been implemented (for a very long time). |
Something like this. Would propably just be an alternative syntax for the contexts:
main:
- include: context1
- include: context2
prototype:
- match: something
scope: whatever
my_custom_prototype_of_subcontext1:
- match: something-else
scope: whatever-you-want
context1:
- match: foo
scope: foo
push: sub-context1
sub-context1:
- meta_prototype: my_custom_prototype_of_subcontext1
- match: bar
scope: baz
push:
# includes my_custom_prototype_of_subcontext1
- match: baz
scope: haha
push:
# includes my_custom_prototype_of_subcontext1
- match: haha
scope: hmmm
context2:
- match: bar
scope: baz
push: sub-ocntext2
sub-context2:
# includes prototype
- match: bar
scope: baz
push:
# includes prototype
- match: baz
scope: haha
push:
# includes prototype
- match: haha
scope: hmmm Note: This is not a feature request, but just the idea of how I would have expected it to work. Don't see a practical use for it at this point. |
Imagine this change then.
|
* [Makefile] Fix embedded ShellScript prototypes Fixes #2318 Problem Description The Makefile.sublime-syntax includes the Bash.sublime-syntax. The `scope:source.shell#prototype` is injected into the embedded Bash.sublime-syntax using `with_prototype` maybe as workaround for sublimehq/sublime_text#1062 The `with_prototype` command ignores `meta_include_prototype: false`, which is heavily used by Bash.sublime-syntax to prevent the `prototype` context from being included into a bunch of contexts such as strings. Fix Description As the prototype context is not included into source.shell's main context only, it is not necessary to inject it via `with_protoype`. Hence it is moved to the `shell-body` together with `source.shell`, which is suggested by the core issue as proper workaround. Notes: The `prototype` context of the Bash.sublime-syntax also includes proper rules to pop off all contexts at eol with respect of line continuation. Hence those don't need to be part of the `with_proptype` statement as well. They are moved to just pop off the Bash's main context as soon as the eol is reached. The `source.shell.embedded` scope is applied to all embedded shell syntax regions. * [Makefile] Fix embedded comment scope Fixes an oversight with regards of the changed `source.shell.embedded` scope, which is used for embedded ShellScript syntax. * [Makefile] Use ST4077 syntax features This commit uses `apply_prototype` to optionally include the prototype if present but keep calm if it was not defined by the included syntax. Add some tests for embedded shell scopes as well.
* [HTML] Fix embedded JavaScript main scope This commit introduces an intermediate `embedded-javascript` context to avoid applying the `source.js` scope of the embedded syntax as we want to scope the section `source.js.embedded.html` instead. Note: When using `- include` the prototype context of the included syntax needs to be included explicitly. see: sublimehq/sublime_text#1062) * [HTML] Fix embedded JavaScript event attribute meta scope This commit removes duplicated `meta.attribute-with-value.event` scopes from `event` tag attributes. The opening single quote was even scoped 3 times. * [HTML] Add embedded JavaScript event attribute interpolation This commit applies `meta.string.html meta.interpolation.html` to the `event` tag attribute value. * [HTML] Add embedded CSS style attribute interpolation This commit applies `meta.string.html meta.interpolation.html` to the `style` tag attribute value. * [HTML] Fix embedded CSS main scope This commit introduces an intermediate `embedded-css` context to avoid applying the `source.css` scope of the embedded syntax as we want to scope the section `source.css.embedded.html` instead. Note: When using `- include` the prototype context of the included syntax needs to be included explicitly. see: sublimehq/sublime_text#1062) * [HTML] Add tag attribute interpolation This commit adds `meta.string.html` to the remaining tag attribute values for consistency reasons with the former commits which address string interpolation. It addresses: - class tag attribute - generic tag attributes - id tag attribute * [HTML] Prepare for merge This commit replaces the quotes in order to reduce the number and complexity of merge conflicts with the assumption of quotes-vs-escapes being merged before. * [HTML] Remove source.css#prototype Avoid error messages as CSS doesn't provide a prototype context. * [HTML] Convert to sublime-syntax version 2 To avoid possible issues with none-existing prototype contexts in embedded syntaxes update to sublime-syntax version 2 a) with a minimal set of required changes to fix some syntax test failures and b) use the normal `embed: scope:...` again, which now omits the main scope of the embedded syntax if `embed_scope` is provided. * [HTML] Cleanup Syntax Header `scope` and `version` feel better placed right next to the `name` while file_extensions and first_line_match belong together as separate fields.
* [Makefile] Fix embedded ShellScript prototypes Fixes sublimehq#2318 Problem Description The Makefile.sublime-syntax includes the Bash.sublime-syntax. The `scope:source.shell#prototype` is injected into the embedded Bash.sublime-syntax using `with_prototype` maybe as workaround for sublimehq/sublime_text#1062 The `with_prototype` command ignores `meta_include_prototype: false`, which is heavily used by Bash.sublime-syntax to prevent the `prototype` context from being included into a bunch of contexts such as strings. Fix Description As the prototype context is not included into source.shell's main context only, it is not necessary to inject it via `with_protoype`. Hence it is moved to the `shell-body` together with `source.shell`, which is suggested by the core issue as proper workaround. Notes: The `prototype` context of the Bash.sublime-syntax also includes proper rules to pop off all contexts at eol with respect of line continuation. Hence those don't need to be part of the `with_proptype` statement as well. They are moved to just pop off the Bash's main context as soon as the eol is reached. The `source.shell.embedded` scope is applied to all embedded shell syntax regions. * [Makefile] Fix embedded comment scope Fixes an oversight with regards of the changed `source.shell.embedded` scope, which is used for embedded ShellScript syntax. * [Makefile] Use ST4077 syntax features This commit uses `apply_prototype` to optionally include the prototype if present but keep calm if it was not defined by the included syntax. Add some tests for embedded shell scopes as well.
…limehq#2397) * [HTML] Fix embedded JavaScript main scope This commit introduces an intermediate `embedded-javascript` context to avoid applying the `source.js` scope of the embedded syntax as we want to scope the section `source.js.embedded.html` instead. Note: When using `- include` the prototype context of the included syntax needs to be included explicitly. see: sublimehq/sublime_text#1062) * [HTML] Fix embedded JavaScript event attribute meta scope This commit removes duplicated `meta.attribute-with-value.event` scopes from `event` tag attributes. The opening single quote was even scoped 3 times. * [HTML] Add embedded JavaScript event attribute interpolation This commit applies `meta.string.html meta.interpolation.html` to the `event` tag attribute value. * [HTML] Add embedded CSS style attribute interpolation This commit applies `meta.string.html meta.interpolation.html` to the `style` tag attribute value. * [HTML] Fix embedded CSS main scope This commit introduces an intermediate `embedded-css` context to avoid applying the `source.css` scope of the embedded syntax as we want to scope the section `source.css.embedded.html` instead. Note: When using `- include` the prototype context of the included syntax needs to be included explicitly. see: sublimehq/sublime_text#1062) * [HTML] Add tag attribute interpolation This commit adds `meta.string.html` to the remaining tag attribute values for consistency reasons with the former commits which address string interpolation. It addresses: - class tag attribute - generic tag attributes - id tag attribute * [HTML] Prepare for merge This commit replaces the quotes in order to reduce the number and complexity of merge conflicts with the assumption of quotes-vs-escapes being merged before. * [HTML] Remove source.css#prototype Avoid error messages as CSS doesn't provide a prototype context. * [HTML] Convert to sublime-syntax version 2 To avoid possible issues with none-existing prototype contexts in embedded syntaxes update to sublime-syntax version 2 a) with a minimal set of required changes to fix some syntax test failures and b) use the normal `embed: scope:...` again, which now omits the main scope of the embedded syntax if `embed_scope` is provided. * [HTML] Cleanup Syntax Header `scope` and `version` feel better placed right next to the `name` while file_extensions and first_line_match belong together as separate fields.
Specifying an include like so:
seems to ignore prototype matches for the 'main' context. Sub-contexts seem to have the syntax's prototype applied however. This is inconsistent.
In order to produce the desired result, one has to include the syntax and additionally the syntax's prototype context like so:
The text was updated successfully, but these errors were encountered: