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
[ASP] remember ASP context block scope after embedded HTML #367
Conversation
[ASP] add class name to symbol list [ASP] add indentation rules
' ^^^^^^ text.html.asp text.html.basic meta.tag.block.any.html meta.attribute-with-value.class.html string.quoted.double.html meta.class-name.html source.asp.embedded.html keyword.control.flow.asp | ||
' ^^ text.html.asp text.html.basic meta.tag.block.any.html meta.attribute-with-value.class.html string.quoted.double.html meta.class-name.html source.asp.embedded.html punctuation.section.embedded.end.asp - meta.if.block.asp | ||
<script type="text/javascript"> | ||
<% If True Then %>var hello = "world";<% End If %> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currently the scope inside the ASP If
block in the JavaScript is text.html.asp text.html.basic source.js.embedded.html source.asp.embedded.html meta.if.block.asp text.html.basic
, which means it is not highlighted as JS, but as HTML currently. I would welcome suggestions on DRY ways of fixing this - I had the idea of changing the html
context inside HTML-ASP.sublime-syntax
to include a match for <script
in the prototype, but then I think it would be necessary to duplicate all the contexts in ASP.sublime-syntax
to push the JavaScript scope instead of HTML - and we would have the same problem about remembering the JS block scope here too...
In my opinion, it is bad coding practice to mix server side and client side code in this way, but I can see that it would have its uses...
to more closely match the way other syntaxes work - one shouldn't really encounter invalid scopes after the cursor while they are typing code
[ASP] fix Randomize Timer scope
If I'm understanding this correctly, you've added the closing transitionary punctuation ( I expected to make |
that's correct - it's the easiest way I could think of doing it. I guess an alternative to making any changes to the main language definition file would be to have a prototype in the supporting HTML syntax definition that will look ahead for where the control flow blocks start (and end) and hmm..haven't really thought this through - it would need to push a new context onto the stack that would somehow magically include the current context (or maybe just the statements context or equivalent?) and also look for the transitionary punctuation. Not sure if that makes sense? |
Rather than add extra rules to the C# syntax, I modeled the block_cs:
- match: '<%[=#:]?'
scope: punctuation.section.embedded.begin.cshtml
push:
- meta_scope: source.cs.embedded.html
- match: '%>'
scope: punctuation.section.embedded.end.cshtml
pop: true
- match: ''
scope: punctuation.definition.tag.end.html
push:
- meta_content_scope: source.cs.embedded.html
- include: 'scope:source.cs'
with_prototype:
- match: '(?=%>)'
pop: true This seems to work with Update: Now publicly viewable with a couple changes since the excerpt above. I notice that the closing brace in the test file ( |
58c18c8
to
fd48024
Compare
3356a84
to
6b71e3c
Compare
bef0aeb
to
986e7a4
Compare
- match: '^\s*((?i:function|sub))\s*' | ||
captures: | ||
1: storage.type.function.asp | ||
- include: root_asp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From experience, adding a pop
to the main
context can lead to funny interactions when embedding the syntax in another. It may make more sense to have the HTML ASP use a construct such as:
- match: '<%'
push:
- match: '(?=%>)'
pop: true
- include: 'scope:source.asp'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I have added a new commit to implement this suggestion :)
@keith-hall It seems like you've been following work on the various syntaxes pretty closely. Based on that, are you happy with this current implementation? The number of test assertions you have seems to be pretty good. Do you think this PR needs a light review, or something a little more in depth? |
@wbond I plan to go over this with a fine toothcomb myself first, because I think I learned a few things about scope conventions since submitting this PR. After which, I believe a light review will be sufficient :) I will let you know when it's ready :) |
3c257cf
to
944fa4f
Compare
944fa4f
to
bf4c46a
Compare
@wbond ready for review :) I am happy with this implementation, but I plan to study the changes you recently made to the PHP syntax, just in case we will later decide to mirror those changes in the ASP syntax definition. If you want me to squash this before you merge, let me know - I had quite a few scope names to correct ;) |
- match: '\b(?i:Randomize\s+Timer){{whitespace_or_end_of_statement}}' | ||
scope: storage.type.asp | ||
- match: '\b(?i:Call|Set){{whitespace_or_end_of_statement}}' | ||
scope: storage.type.asp # maybe this should be a keyword instead? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is one scope that I am not sure about. In ASP, to set a variable to an object, as opposed to a number or string, it is necessary to use set var_name = obj_reference
instead of just var_name =
...
also, Call
is completely optional, but if used, must be followed by a method name (i.e. a callable object)
so far I have kept the scope as it was previously, but I believe that a keyword
scope would be more appropriate. As far as I know, these are unique to VB and ASP. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keyword
sounds more appropriate to me too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated. I've made the scopes unique, and in the same style as some PHP keywords, so that users can modify their color scheme if they don't like the new coloring.
we can't reliably determine when parens refer to a method or an array except when the array is declared/redeclared
...to not show parens or anything afterwards, and to remove line continuation characters
cba0acd
to
9488c49
Compare
082a7e1
to
e5ec406
Compare
@keith-hall The new clear_scopes feature will probably be useful to you to implement reasonable HTML embedding. It will be part of build 3115. In summary, it is applied like The PHP pull request uses it to erase all of the scopes when literal HTML is encountered, and then uses I'll look through this PR soon, but I figured I'd mention that now. Perhaps we wait until 3115 is released so you can test against that, or perhaps I'll pull in your changes into another PR and test it locally. |
As per the discussion here, this PR is to ensure that ASP correctly remembers what scope it should be in after embedded HTML.
Performance
Using the syntax test file from this PR, which is 32 KiB:
ASP syntax definitions before the changes in this PR:
ASP syntax definitions after the changes in this PR: