osoco / sublimetext-grails

Grails support for Sublime Text
75 stars 21 forks source link

Formatting breaks with ternary operation #4

Closed dbromby closed 10 years ago

dbromby commented 11 years ago

The following ternary operation breaks formatting:

<g:formatNumber number="${val1 == 0 ? 0 : val2 / val3}" type="percent" />

gcrick commented 11 years ago

It looks like this is caused by the division sign (/) rather than the actual ternary operator. We'll take a look at it, thanks :)

dbromby commented 11 years ago

Here's another ternary operation that appears to break it too. If you remove the "?" the format looks fine.

${ ( var1 > var2 ? 'some text' : 'some more text' ) }

gcrick commented 11 years ago

This sample looks fine for me. Can you check that the file is displaying as "Grails Server Page (GSP)" and let us know what color scheme you are using?

dbromby commented 11 years ago

Hm yes, that does seem OK. Maybe there was something else going on in the file in question. I'll double check.

The only reproducible issue right now is using division in the ternary operator.

BTW - I'm using the Twilight theme.

dbromby commented 11 years ago

Any plans to fix the issue caused by "/" ?

gcrick commented 11 years ago

I've taken a look at it, and it turns out that the groovy plugin's syntax highlighter is marking the text after the "/" as a regular expression. Groovy allows regular expressions to be written /regex/, and it is detecting " ${ a / b} " as the regex "/ b} </". So far I haven't been able to come up with any way to fix the problem. If anyone knows how to limit the groovy code matching so that it doesn't look beyond the "${}" (or <%= %> etc), I would love to hear it.... :P So to answer your question, yes, we still plan to fix it if possible, we just haven't been able to.

On Thu, May 23, 2013 at 12:26 AM, dylanbromby notifications@github.comwrote:

Any plans to fix the issue caused by "/" ?

— Reply to this email directly or view it on GitHubhttps://github.com/osoco/sublimetext-grails/issues/4#issuecomment-18312220 .

hayseed commented 10 years ago

I'm seeing highlighting errors with the following snippet:

<%= a.b == null ? "" : a.b.c %>

As soon as I remove the ? the highlighting works wonderfully!

Sadly, that's not going to resolve my problem. Also, every theme I have installed (just the ones that come with the default install) are all affected by this. The theme I'm currently using is the Espresso Libre.

gcrick commented 10 years ago

I'm currently trying to re-write the entire syntax highlighting rules, so I will add this case to my test file. I'm not too sure what trouble you are seeing though. For me, the only thing that doesn't show right when the ? is present is the final %>. Is it the same for you? If not, where in the page does your sample appear? (directly in the body, as a tag attribute, etc). Thanks!

On Tue, Oct 15, 2013 at 7:27 AM, hayseed notifications@github.com wrote:

I'm seeing highlighting errors with the following snippet:

<%= a.b == null ? "" : a.b.c %>

As soon as I remove the ? the highlighting works wonderfully!

Sadly, that's not going to resolve my problem. Also, every theme I have installed (just the ones that come with the default install) are all affected by this. The theme I'm currently using is the Espresso Libre.

— Reply to this email directly or view it on GitHubhttps://github.com/osoco/sublimetext-grails/issues/4#issuecomment-26310155 .

hayseed commented 10 years ago

Ok, annoyingly I'm now seeing two different results from two different .gsp files. One is the main layout file and the other is one of the views.

Both instances have the ternary operator as part of the body of the file. I have attached two screenshots of the the behaviour I'm seeing.

main-gsp show-gsp

On Tuesday, 15 October 2013 6:36:14 PM, gcrick wrote:

I'm currently trying to re-write the entire syntax highlighting rules, so I will add this case to my test file. I'm not too sure what trouble you are seeing though. For me, the only thing that doesn't show right when the ? is present is the final %>. Is it the same for you? If not, where in the page does your sample appear? (directly in the body, as a tag attribute, etc). Thanks!

  • Geli
gcrick commented 10 years ago

Ok, thanks for the screenshots, hopefully that'll let me duplicate the problem. Oh, the joys of regular expressions! ;)

On Wed, Oct 16, 2013 at 2:08 AM, hayseed notifications@github.com wrote:

Ok, annoyingly I'm now seeing two different results from two different .gsp files. One is the main layout file and the other is one of the views.

Both instances have the ternary operator as part of the body of the file. I have attached two screenshots of the the behaviour I'm seeing.

On Tuesday, 15 October 2013 6:36:14 PM, gcrick wrote:

I'm currently trying to re-write the entire syntax highlighting rules, so I will add this case to my test file. I'm not too sure what trouble you are seeing though. For me, the only thing that doesn't show right when the ? is present is the final %>. Is it the same for you? If not, where in the page does your sample appear? (directly in the body, as a tag attribute, etc). Thanks!

  • Geli

Reply to this email directly or view it on GitHubhttps://github.com/osoco/sublimetext-grails/issues/4#issuecomment-26383404 .

gcrick commented 10 years ago

I think these problems should be fixed in the latest version (1.0.1). Please re-open if you still see the issues after updating.

dbromby commented 10 years ago

They're not fixed - that's why I emailed you.

Sent from my iPhone

On Oct 20, 2013, at 10:26 AM, gcrick notifications@github.com wrote:

I think these problems should be fixed in the latest version (1.0.1). Please re-open if you still see the issues after updating.

— Reply to this email directly or view it on GitHub.

gcrick commented 10 years ago

I'm sorry you are still having trouble. I didn't receive any email, so I'm not sure if I'm missing some details. I just checked, and you are right that your original case () still breaks :( I'm sorry, I'll take a look at it again.

gcrick commented 10 years ago

Ok, I think I got it fixed this time!

dbromby commented 10 years ago

I just took a look at our codebase and so far this looks good - thank you!


Generate additional income renting on eRENT.com.

Dylan Bromby Co-Founder dylan@eRENT.com

eRENT.com twitter.com/eRENT facebook.com/eRENT

On Oct 25, 2013, at 8:39 AM, gcrick notifications@github.com wrote:

Closed #4.

— Reply to this email directly or view it on GitHub.

dbromby commented 10 years ago

Really appreciate your commitment to this - the aesthetics of code formatting are so important to workflow!

-- Dylan


Generate additional income renting on eRENT.com.

Dylan Bromby Co-Founder dylan@eRENT.com

eRENT.com twitter.com/eRENT facebook.com/eRENT

On Oct 25, 2013, at 8:39 AM, gcrick notifications@github.com wrote:

Ok, I think I got it fixed this time!

— Reply to this email directly or view it on GitHub.

gcrick commented 10 years ago

You're welcome :) Sorry it took me so long to get it fixed!

On Fri, Oct 25, 2013 at 6:06 PM, dylanbromby notifications@github.comwrote:

Really appreciate your commitment to this - the aesthetics of code formatting are so important to workflow!

-- Dylan


Generate additional income renting on eRENT.com.

Dylan Bromby Co-Founder dylan@eRENT.com

eRENT.com twitter.com/eRENT facebook.com/eRENT

On Oct 25, 2013, at 8:39 AM, gcrick notifications@github.com wrote:

Ok, I think I got it fixed this time!

— Reply to this email directly or view it on GitHub.

— Reply to this email directly or view it on GitHubhttps://github.com/osoco/sublimetext-grails/issues/4#issuecomment-27104757 .

hayseed commented 10 years ago

Hmm, looks like I'm having issues again with the highlighting. The following is what's causing the problems of the syntax 'bleeding'. It's the second ? that's causing the bleed problem. I am using ST2 (build 2221) and v1.0.3 of the plugin.

${one?.two?}

Edit: Now my illustrious colleagues tell me to remove the second ? and she'll be apples. Honestly. Apologies for opening this up again! :D

gcrick commented 10 years ago

Thanks for keeping your eyes open anyway hayseed. Yeah, as far as I know, leaving a ? at the end of an expression isn't valid Groovy syntax. In theory, I could mark it as an error so that it stands out with special highlighting, but given the way syntax highlighting works in sublime and the number of possible error cases, it really isn't practical.

hayseed commented 10 years ago

I do believe I've discovered another one (and the syntax is correct this time!).

<g:each in="${schedules.groupBy{it.lcRequest}.sort{it.key.title}}" var="request">

gsp-hilite

Screenshot included to show where it's looking funky.

gcrick commented 10 years ago

That does look bad. It looks fine to me in my normal working setup, but I'll look into it further. I've created a new issue to track it: #13. Thanks!