Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Conversation

@Alhadis
Copy link
Contributor

@Alhadis Alhadis commented Mar 10, 2017

Follow-up of an issue I noticed after the responsible PR was merged.

Cons: It's left the patterns looking hairier than I am.

Pros: The output looks good enough to eat:

Figure 1 & 2

  • Top: My hand-rolled, deliberately-plain and undistracting syntax theme
  • Bottom: The beautifully-elegant, almost palpably paper-like DuoTone Light

EDIT 14/03: Okay, a few more additions... I feel bad piling them onto an unrelated PR, but I figure it'll probably get things reviewed quicker (since this already needs revisiting).

  1. HTML highlighting added to embedded <caption> tags:

Figure 3

  1. <caption> tags will now match on a newline following the opening @example tag

3 @api and @internal added to recognised JSDoc tags; see comment below

@Alhadis
Copy link
Contributor Author

Alhadis commented Mar 10, 2017

@50Wliu I also noticed JSDoc drops any text that's touching the closing bracket of a default @param value, so I've highlighted it as an error:

Figure 2

Specs included, of course. =)

@Alhadis
Copy link
Contributor Author

Alhadis commented Mar 10, 2017

Okay, aaand I noticed incomplete highlighting of @see {@link http://url.com/} (only the opening { was being highlighted). I remember I meant to get back to that... sorry! :( I've added a fix for it to this PR.

@Alhadis
Copy link
Contributor Author

Alhadis commented Mar 11, 2017

@50Wliu Is it okay to add @api and @internal as highlighted tags? They're not part of JSDoc, but they are used in-the-wild for similar API-generation systems.

E.g.:

EDIT: Never mind, I figure if it isn't appropriate, you'd bring it up in review.

Alhadis added 2 commits March 14, 2017 21:21
* Embedded HTML is now highlighted correctly
* <caption> tags will match after the opening @example line
Not part of the official JSDoc spec, yet occasionally used in-the-wild.
'end': '\\]|(?=\\*/)'
'beginCaptures':
'0':
'name': 'variable.other.jsdoc'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use name here instead of contentName if the begin and end captures should get the same scopes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's to keep invalid.illegal.syntax.jsdoc from being nested inside variable.other.jsdoc. For themes that prioritise the former over the latter, we don't want invalid text being highlighted as valid.

Copy link
Contributor Author

@Alhadis Alhadis Mar 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a theme which doesn't highlight invalid.illegal.syntax.jsdoc:

Subtle detail, I admit.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this. I feel like it introduces complexities in the grammar, and I've noticed that while it's unnoticeable while writing code, internally the scopes are still separated (such as in specs).

As you know I really value correct highlighting, but I think in this case it's better to use name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you wish.

'default-value':
'patterns': [
# Double-quoted string
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we special-casing strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To stay consistent with JavaScript. Furthermore, some themes might colour double-quoted strings differently to single-quoted strings (such as seti-syntax).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here. The double string.quoted.double.js capture/contentName feel extremely hacky to me, and is actually why it's taken me so long to get back to reviewing this PR.

Is there any other way to do this without the double capture?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you prefer I simply embed source.js in the captured match, then? Unless you want no string highlighting whatsoever...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, scratch that suggestion. That's only gonna make things even more complex, because care will need to be taken to stop source.js from consuming the closing quote-character.

Is there any logical, practical reasoning for this, other than the old "it seems too hacky to me"...? Heck, for all you know, you could be ditching this grammar in six months in favour of Tree-Sitter or Bush-Croucher or something... =)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this isn't that different from the hacks I used in atom/language-xml#54 to circumvent runaway highlighting with </script> tags and stuff. Heck, that PR's hacks are a hell of a lot worse, and the results aren't even gonna be appreciated on the level that consistent JSDoc highlighting will.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That also happens to be why I haven't finished reviewing the XML PR. This probably won't make it into either the linguist or Atom releases as I'll need time to reflect and think about your questions.

And also, would it be feasible to include all of source.js in here after atom/first-mate#90 is merged?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@50Wliu If it's really this much of an issue, I'll drop it for you. I'm not going to let this be delayed on something this trivial.

Hold on.

Copy link
Contributor Author

@Alhadis Alhadis Apr 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, it's done. I've merged both string-matching blocks, and used string.quoted.js for the applied scope.

If there's anything else that's blocking this, please speak up.

EDIT: Oh, and regarding your question: I believe so, yes. It would also warrant a full (and cleaner/simpler) rewrite of the XML/SVG PR, which I'm not that proud of anyway (I recently looked through the expressions I wrote last year for it, and couldn't figure out what the hell I was thinking...)

}
]
}
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly is this for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stuff like @param {Object} [value = {key: [ [0], [1] ] }] Description

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So will this be needed after language-javascript switches to using begin/end captures for square brackets?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because it's used to balance all that weird, noisy syntax Google use for Closure Compiler tags, which combine < [ { brackets with nesting and all sorts of weird-looking rubbish.

@Alhadis
Copy link
Contributor Author

Alhadis commented Apr 5, 2017

@50Wliu Any chance we could get this looked at soon?

Linguist is probably due for another release soon, so it'd be great to get this working across GitHub...

I wouldn't be nagging if I didn't believe there isn't much left to do here. =)

@winstliu
Copy link
Contributor

winstliu commented Apr 5, 2017

I was actually reminding myself to look at this again last night, also because a new Atom release is approaching.

I have mostly refrained from doing so because it's a surprisingly large PR, which I haven't had the appetite to review. I'll try to get to it soon, but like usual, no guarantees.

@Alhadis
Copy link
Contributor Author

Alhadis commented Apr 5, 2017

If it helps, I kept my last commits atomic and documented to ameliorate any hassle. =)

Copy link
Contributor

@winstliu winstliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way at all to get rid of the capture + contentName thing you're doing?

'end': '\\]|(?=\\*/)'
'beginCaptures':
'0':
'name': 'variable.other.jsdoc'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like this. I feel like it introduces complexities in the grammar, and I've noticed that while it's unnoticeable while writing code, internally the scopes are still separated (such as in specs).

As you know I really value correct highlighting, but I think in this case it's better to use name.

'default-value':
'patterns': [
# Double-quoted string
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here. The double string.quoted.double.js capture/contentName feel extremely hacky to me, and is actually why it's taken me so long to get back to reviewing this PR.

Is there any other way to do this without the double capture?

Alhadis added 2 commits April 6, 2017 03:34
Requested in review.

See: #497
     files/7969d32c25d1ea4a2be45606a5b6c03f1a191ddf#r109976644 (comment)
@Alhadis
Copy link
Contributor Author

Alhadis commented Apr 9, 2017

@50Wliu Any chance of this making the next Atom release now that I've simplified the pattern/scope-matching?

@winstliu
Copy link
Contributor

winstliu commented Apr 9, 2017

I will take a look on Monday.

@Alhadis
Copy link
Contributor Author

Alhadis commented Apr 10, 2017

How's Monday going?

It's Tuesday here, hahah. Was already Monday here when you posted that, too. 😀

'name': 'source.embedded.js'
'captures':
'0':
'patterns': [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious what this is for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't figure out what was causing it, and it was giving me the shits, so I added a different rule.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give me a code example of what caused you to add this rule?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, sorry, I've completely forgotten what I was even working on when I encountered this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you waiting for me to remove this rule, or...?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you've realized by now that you and I sometimes disagree on what is shippable. I apologize for the long delays between reviews and comments; that's something I need to work on when something like this occurs.

If you would really like Linguist to include the new JSDoc highlighting, I would encourage you to submit a (hopefully temporary) PR that eliminates the embedded JS highlighting. Then, we can continue discussing.

I've been trying out different methods to avoid the scope-chopping that's occurring here. I've seen some success but it'll take more time and I don't want to delay your Linguist release or have it ship with buggy highlighting.

Copy link
Contributor Author

@Alhadis Alhadis May 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you've realized by now that you and I sometimes disagree on what is shippable.

What you're neglecting to do is explain to me why. So far, it seems like a case of "it doesn't feel right to me". That's what's disconcerting to me. I can handle being disagreed with... but not in the absence of a reason why.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once I'm back in front of a computer, I'm replacing this grammar with a fork until you've come to a resolution.

Copy link
Contributor Author

@Alhadis Alhadis May 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, never mind. I explained the issue to Linguist's maintainer and he believes the best the thing to do at this point is to avoid updating the JavaScript grammar with the next release, so the grammar's current state won't affect GitHub.

Fix this whenever. No hurry now.

Doesn't look like this will be sorted any time soon, so I've undone my removal of the embedded HTML highlighting.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. So I didn't explain why because it was getting late last night but I still wanted to respond to let you know I got the notification.

Here's why I think this PR is unmergeable as-is, or even with an explanatory comment.

  • These changes result in certain parts of language-javascript being spliced up such that the pattern begins matching but is interrupted before the end match.
  • Therefore you had to add some out-of-context rules in an attempt to balance out the mismatched rules. This is very prone to breakage as scopes or matches change.
  • Inconsistent scopes. Let's look at https://github.com/atom/language-javascript/pull/497/files#diff-c4166255a13782b6557ec1da0f4a6ef3R467 for an example. Why is "b" not tokenized as embedded JavaScript, while it should be? The whole default value should be embedded JS, yet there are portions when that scope disappears. This of course is partly due to my insistence that double-matching should be avoided where possible, but that also brings me to my next point:
  • Duplication of rules found in javascript.cson. Again, this is very hard to keep in sync.
  • Considerably, as you described it, "hairier" patterns for comparably small highlighting gains.

Overall, after reviewing this PR I am unconvinced that embedded Javascript highlighting for default values is worth it if it cannot be done in a clean manner that is easy to understand and requires minimal maintenance upkeep.


describe "HTML captions", ->
###
NOTE: Loading the HTML grammar triggers an inexplicable case of infinite recursion during the following two specs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. That is quite odd.

@winstliu
Copy link
Contributor

9:07pm over here 😀. I'm going to take a look at the HTML recursion.

@winstliu
Copy link
Contributor

Also: I think I'm going to change the update schedule for grammars in Atom. Instead of updating all the grammars right before a new release, I'm going to update them right after, so that they get the full benefit of Atom's release pattern. That also means that there will be very minimal language updates for 1.17.

@Alhadis
Copy link
Contributor Author

Alhadis commented Apr 11, 2017

Eh... okay...

Wasn't the first buggy JSDoc PR I submitted merged in a release used by the next Atom version?

@winstliu
Copy link
Contributor

winstliu commented Apr 11, 2017

Nope: #496 hasn't been included in a language-javascript release yet.

Also, I can reproduce the infinite recursion in a production environment. The repro case is as simple as having the caption element, as in the first spec, and then trying to disable and then re-enable language-html. That will need to be fixed.

EDIT: Or even just reloading the window?
EDIT2: Yup, reloading the window will reliably trigger it if you're using the second spec

@Alhadis
Copy link
Contributor Author

Alhadis commented Apr 11, 2017

Nope: #496 hasn't been included in a language-javascript release yet.

Well, thankfully Linguist doesn't need a tagged release to pick up the latest changes to a grammar. :D

As for Atom, I'm not fussed about getting this shipped soon. I have enough to worry about with keeping File-Icons stable until the 5 PRs are dealt with.

@Alhadis
Copy link
Contributor Author

Alhadis commented Apr 20, 2017

@50Wliu There's very likely going to be a new Linguist release soon. What else is there that I have to do?

I'd rather not have the bugs from the first PR plague every documented JS file throughout GitHub.

@winstliu
Copy link
Contributor

The infinite recursion issue with language-html needs to be fixed.

@Alhadis
Copy link
Contributor Author

Alhadis commented Apr 20, 2017

Would you prefer I remove the embedded HTML highlighting for the time being, then?

@winstliu
Copy link
Contributor

I'm not opposed to that. It can always be added later.

@Alhadis
Copy link
Contributor Author

Alhadis commented Apr 20, 2017

Precisely my line of thinking as well. Hold on.

@Alhadis
Copy link
Contributor Author

Alhadis commented Apr 20, 2017

Righto, done. =)

Damn strange I can't reproduce the recursion error outside of the spec-runner, though.

@winstliu
Copy link
Contributor

Did you see my reproduction steps above?

@Alhadis
Copy link
Contributor Author

Alhadis commented Apr 20, 2017

Ah, I missed the part about disabling and reenabling. Sorry, never mind.

@winstliu
Copy link
Contributor

I will try to give a final review within the next few days.

'end': '\\1|(?=\\*/)'
'endCaptures':
'0':
'name': 'punctuation.definition.string.end.js'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that in bd688cc you simplified the string rules, but shouldn't name still differentiate between single and double quoted strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How am I expected to do that without duplicating the rule?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with the rule being duplicated. Just like how it already is in the main javascript grammar (

'begin': '\''
'beginCaptures':
'0':
'name': 'punctuation.definition.string.begin.js'
'end': '\''
'endCaptures':
'0':
'name': 'punctuation.definition.string.end.js'
'name': 'string.quoted.single.js'
'patterns': [
{
'include': '#string_escapes'
}
{
'match': "[^']*[^\\n\\r'\\\\]$"
'name': 'invalid.illegal.string.js'
}
]
}
{
'begin': '"'
'beginCaptures':
'0':
'name': 'punctuation.definition.string.begin.js'
'end': '"'
'endCaptures':
'0':
'name': 'punctuation.definition.string.end.js'
'name': 'string.quoted.double.js'
'patterns': [
{
'include': '#string_escapes'
}
{
'match': '[^"]*[^\\n\\r"\\\\]$'
'name': 'invalid.illegal.string.js'
}
]
).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

'name': 'source.embedded.js'
'captures':
'0':
'patterns': [
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you give me a code example of what caused you to add this rule?

lildude added a commit to github-linguist/linguist that referenced this pull request May 3, 2017
The current grammar has a known issue and is pending the fix in atom/language-javascript#497
lildude added a commit to github-linguist/linguist that referenced this pull request May 3, 2017
* Update all grammars

* Update atom-language-clean grammar to match

* Don't update reason grammer

There seems to be a problem with the 1.3.5 release in that the conversion isn't producing a reason entry so doesn't match whats in grammar.yml

* Bump version to 5.0.9

* Update grammars

* Don't update javascript grammar

The current grammar has a known issue and is pending the fix in atom/language-javascript#497
@Alhadis
Copy link
Contributor Author

Alhadis commented May 3, 2017

I won't waste your time anymore. Sorry.

I'll leave it to you to revert the embedded highlighting in my other PR.

@Alhadis
Copy link
Contributor Author

Alhadis commented May 3, 2017

Going forward, I think the best thing for me to do is refrain from submitting future PRs to grammar packages, as it's obvious our opinions of grammar structure are too different for these things to be tolerable for either of us.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants