Skip to content
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

Highlighting breaks if no semicolon after type expressions #309

Closed
StreetStrider opened this issue Feb 23, 2017 · 31 comments
Closed

Highlighting breaks if no semicolon after type expressions #309

StreetStrider opened this issue Feb 23, 2017 · 31 comments

Comments

@StreetStrider
Copy link

When using something from Flow syntax, highlighting may break if no semicolons used.
For sample, put something like:

export type A = string
type B = number

The second one would not be properly highlighted if the first one losses semicolon at the end. However, the syntax is correct.

My linting rules encourages to evade semicolons where possible, so I can't use semicolon at the end of the line.

import type statements works good.
This would be highlighted properly:

import type { A } from './A'
@bdefore
Copy link

bdefore commented Mar 2, 2017

I've also encountered this. Interesting that the type declaration would have any impact on semicolons.

@bdefore
Copy link

bdefore commented Mar 2, 2017

See also #298

@mareksuscak
Copy link

Not sure if it's related but same for static class properties:

screen shot 2017-04-14 at 01 12 54

class Component extends React.Component {
  static propTypes = {
    config: PropTypes.object
  }

  static defaultProps = {
    config: {}
  }
}

@StreetStrider
Copy link
Author

@mareksuscak seemes related

@JemarJones
Copy link

Same issues as @mareksuscak

@miyabi
Copy link

miyabi commented May 11, 2017

Same as @mareksuscak.
It is fixed by inserting semicolon after closing brace, but it is unwanted.

@Xazzzi
Copy link

Xazzzi commented May 11, 2017

You are welcome to test if it works for you.

@michaelcarter
Copy link

@Xazzzi I've googled around but am struggling, how can I install this fixed version in Sublime 3?

@mareksuscak
Copy link

@michaelcarter It hasn't been released yet. So you have to go the ~/Library/Application Support/Sublime Text 3/Packages/Babel and edit the file JavaScript (Babel).sublime-syntax accordingly:

screen shot 2017-05-15 at 14 02 12

@michaelcarter
Copy link

@mareksuscak This is all I have in ~/Library/Application Support/Sublime Text 3/Packages/:

screen shot 2017-05-16 at 14 41 30

@Xazzzi
Copy link

Xazzzi commented May 16, 2017

Unfortunately i don't own any apple pc, so i can't really tell how to fix it on Mac.
What i suggest though is to try modifying JavaScript (Babel).tmLanguage in a similar way.

@JemarJones
Copy link

JemarJones commented May 16, 2017

@Xazzzi It does not work for me. Instead the issue happens for all declarations in the class (after the constructor) instead of just the one.

@mareksuscak
Copy link

@michaelcarter that's odd, here's mine:

screen shot 2017-05-17 at 00 05 19

How did you install babel package? Via Package Control, right? I use Babel package v8.6.3. Make sure you use the latest version.

screen shot 2017-05-17 at 00 04 54

@michaelcarter
Copy link

@mareksuscak @Xazzzi Ok, I've got the file there now but editing it does nothing to improve my syntax highlighting. I'm left with code like this:

screen shot 2017-05-17 at 10 30 53

Drop in a ; at the end of the type declaration and I get this (much better!):

screen shot 2017-05-17 at 10 31 41

Thanks for all your help so far.

@mareksuscak
Copy link

@michaelcarter Have you got it working yet? I did not have much time to dig in. I'm currently not very familiar with this project and there doesn't seem to be a whole lot of documentation (i.e. what's the preferred way to convert *.tmLanguage to *.sublime-syntax).

One thing I can say for sure is that it doesn't work for you because @Xazzzi's solution only fixes missing semicolon for class properties. Your code is breaking on flowtype-declaration so a similar patch is necessary for those.

@michaelcarter
Copy link

@mareksuscak No. I'm afraid not. I've tried modifying the flowtype-declaration section of my sublime-syntax document but have had no success in getting something working (I have no idea what I'm doing, so that's unsurprising).

I don't usually work with flow, so I'll probably just hop over to Atom for this project so I have something that works and then check back periodically on whether this is working in newer versions.

Thanks for all your help! 🙏

@sankarravi
Copy link

I got this working using @Xazzzi's rough change in the flowtype-declaration section. Notably, I had to the change the sublime-syntax file, not the tmLanguage file:
~/Library/Application Support/Sublime Text 3/Packages/Babel/JavaScript (Babel).sublime-syntax

My final flowtype-declaration looks like:

flowtype-declaration:
  - match: (?<!\.)\b(declare)\b
    scope: support.type.declare.flowtype.js

  - match: (?<!\.)\b(type)\b(?=\s*[_$a-zA-Z])
    scope: support.type.type.flowtype.js
    push:
      - meta_scope: meta.type.flowtype.js
      - match: (?=\s*(;|from))
        pop: true
      - include: flowtype-tokens
      - match: $
        pop: true

  - match: (?<!\.)\b(type)\b(?=\s*{)
    scope: support.type.type.flowtype.js
    push:
      - meta_scope: meta.type.flowtype.js
      - match: (?<=})
        pop: true
      - include: flowtype-brackets
      - include: flowtype-polymorph
      - match: ([_$a-zA-Z][$\w]*)
        scope: entity.name.type.js
      - match: $
        pop: true

starting at L207

Screenshot:
image

@Mottoweb
Copy link

Mottoweb commented Jun 7, 2017

Thanks @Xazzzi @sankarravi, this has to be a PR.
I almost switched to atom, but then found this.

@amsul
Copy link

amsul commented Jul 15, 2017

@Xazzzi @sankarravi you two are legends! Saved me the effort of switching to vscode 😅

@StreetStrider
Copy link
Author

Can someone help on converting to tmLanguage? I'd found analogous definition in tmLanguage file and I'm trying to port changes.
Looks like the key is:

- match: $
    pop: true

However, I can't find analogue in tmLanguage. Maybe it's encoded in some combination of beginCaptures/begin indirectly?
I haven't got any experience in theese DSLs, so I would glad to get any help.

@breadadams
Copy link

NICE @sankarravi @Xazzzi 👏

Any word on getting this merged into a release?

@Xazzzi
Copy link

Xazzzi commented Nov 4, 2017

I wonder if it could be merged. I dont have any experience in language defs DSL's either and found this fix by trying different things (and failing a lot).
This repo seems pretty much abandoned, as last update was 9 month ago.
We can ask @zertosh maybe ?

@StreetStrider
Copy link
Author

It would be awesome if someone ports this change to tmLanguage as well. I use babel-sublime tmLanguage with my own fixes in conjunction with my own theme. I tried to do port myself, but have not enough experience with theese themes, failed to do it in simple manner. It's much to ask, but it would be cool to see this happen.

@borela
Copy link

borela commented Jan 15, 2018

For sublime, try https://github.com/borela/naomi

@emwalker
Copy link

emwalker commented Apr 23, 2018

Curious what the status of this is. In an earlier PR by @Xazzzi, the fix was placed in the tmLanguage file, and that seems to have caused problems. In @sankarravi's comment above, by contrast, the fix was placed in the sublime-syntax file, and this worked for me and at least one other person without causing any obvious issues.

This bug makes it hard to want to use flow if your repo doesn't use semicolons, and the fix seems to be an easy one. @zertosh, are there further considerations we should be aware of, or would you be open to a PR?

@webbuyrich
Copy link

webbuyrich commented Nov 3, 2018

After installing Babel in sublime packages I followed the readme instructions in the package control webpage
https://packagecontrol.io/packages/Babel

Setting as the default syntax
To set it as the default syntax for a particular extension:

  1. Open a file with that extension
  2. Select View from the menu
  3. Then Syntax -> Open all with current extension as... -> Babel -> JavaScript (Babel).
  4. Repeat this for each extension (e.g.: .js and .jsx)

@mcissel
Copy link

mcissel commented Nov 21, 2018

To get the static keyword highlighting again, I modified the JavaScript (Babel).sublime-syntax (like in
@sankarravi's comment). But instead I only added this at the top of the flowtype-declaration (line 207)

- match: (?<!\.)\b(static)\b
  scope: storage.modifier.js

Oddly, it didn't work if I put that down by the other scope.storage.modifier tagger

@emwalker
Copy link

Does anyone know of a fork of this repo that is up to date and being maintained?

@Thom1729
Copy link
Contributor

JS Custom provides JSX highlighting and more. It's based directly on the core JavaScript syntax, so it will never be left behind as the core syntax continues to improve.

@StreetStrider
Copy link
Author

@emwalker use Naomi (above in thread).

@Thom1729
Copy link
Contributor

This should be fixed in v10.0.0-beta.1. See #379 for more information on the new release. Please report any problems with v10 in a new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests