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

Grammar detection at startup broken for open files #481

Closed
captbaritone opened this issue Feb 13, 2018 · 1 comment · Fixed by #482
Closed

Grammar detection at startup broken for open files #481

captbaritone opened this issue Feb 13, 2018 · 1 comment · Fixed by #482

Comments

@captbaritone
Copy link

If you (re)start Atom with some JS files already open, Babel ES6 JavaScript does not get applied.

Regressed here: #473

Since packages (and thus grammars) are loaded async, when a new grammar is added, Atom checks all open files to see if the new grammar should trump the one it currently has.

https://github.com/atom/atom/blob/1dc700182171ae2fe8773bed703a62104aad0b8e/src/grammar-registry.js#L330

The addition of injectionSelector seems to cause this process to short circuit. I can't seem to find much documentation for how injectionSelector is supposed to be used, but I it looks to me (based on the Atom code and this discussion) like it's only intended for grammars that apply to scopes, not entire files.

CC @wbinnssmith @Aerijo @gandm

@Aerijo
Copy link
Contributor

Aerijo commented Feb 13, 2018

My apologies, I believe that is a bug. My forum question was answered by @50Wliu, and I got the impression it was a property designed to inject the current grammar into another when the other gained the specified scope. For example, the ideal use case in a Markdown file is when the user types

```js

```

Using injectionSelector, the code within the code block will get proper syntax highlighting. I got no impression it was solely for grammars for scopes.

However, there is a workaround that has the same effect as the embedding, but without this bug. Making a new grammar file (e.g., called embeddedBabel.json) and filling it out like so:

{
  "scopeName": "source.embedded.js.jsx",
  "injectionSelector": "source.embedded.jsx",
  "patterns": [{ "include": "source.js.jsx" }]
}

Turns the injecting part into a standalone grammar, which prevents the glitch.

FYI, I also have another forum post where I go through all the valid properties I could find.

@Aerijo Aerijo mentioned this issue Feb 14, 2018
@gandm gandm closed this as completed in eb9222c Feb 14, 2018
gandm pushed a commit that referenced this issue Feb 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants