Thom1729 / Sublime-JS-Custom

Customizable JavaScript syntax highlighting for Sublime Text.
MIT License
137 stars 9 forks source link

`custom_template_tags` fails when including a syntax that in turn includes `source.js`. #17

Closed elquimista closed 6 years ago

elquimista commented 6 years ago

I tried to use this plugin to highlight react-pug syntax, using custom_tagged_literals option.

return pug`
  header
    p Hello
`;

This is my settings:

{
  "configurations": {
    "My Config": {
      "custom_tagged_literals": {
        "pug": "scope:text.pug"
      }
    }
  }
}

But it doesn't work. I've been using babel-sublime, and it looked like this plugin was based in default ST JavaScript syntax, so I tried switching to that, but didn't work either.

What am I missing here?

Thom1729 commented 6 years ago

I'll give it a try right on my machine. What package are you using for pug highlighting?

elquimista commented 6 years ago

https://github.com/davidrios/pug-tmbundle

elquimista commented 6 years ago

FYI, I couldn't even get the following working using your example in README.

style`div { display: block; }`
Thom1729 commented 6 years ago

Hmm. The "style": "scope:source.css" example works for me (I just tested it), but I can't get Pug to work. I checked the View -> Syntax menu and there's no Pug syntax listed, nor is it available via the command palette. I have the same Pug bundle installed. I think it might be a problem on that bundle's end. Is the Pug bundle working for you in any capacity?

Thom1729 commented 6 years ago

Ah, I see the problem. The custom_tagged_literals option embeds a modified version of the inner syntax inside your JS Custom syntax. However, the Pug syntax embeds your default JavaScript syntax inside itself. This causes unbounded recursion when Sublime tries to process the syntax definitions.

This problem most likely applies to any other syntax that includes the source.js scope. I think that modifying the custom_tagged_literals option to use Sublime's new embed feature might fix the problem. However, the feature is only available in Sublime dev builds at this time. I'll look further into this and see what can be done in the short term.

elquimista commented 6 years ago

Okay I see.

When I said "style": "scope:source.css" didn't work for me, it was actually "pug": "scope:source.css" that I tried (with pug tagged template string that contains css contents inside it). I switched language to default JavaScript as well. And the syntax highlighting didn't work.

Thom1729 commented 6 years ago

To clarify, you're still having problems with highlighting CSS in template tags? To isolate that issue from the recursion issue with Pug:

  1. Make sure that "scope:text.pug" isn't anywhere in your configuration.
  2. Run JS Custom: Rebuild Syntaxes from the command palette.
  3. Restart Sublime.

This should make sure than any residual weirdness from the known Pug-related issue should be gone. Then, if it's not doing what you expect, post your JS Custom.sublime-settings file and the code you're trying to highlight. I should be able to exactly reproduce the issue from there and fix it today.

elquimista commented 6 years ago

There's nothing popping out when I type JS Custom: Rebuild Syntaxes (or JSCustom: Rebuild Syntaxes) in the command palette.

Thom1729 commented 6 years ago

Related: https://github.com/SublimeTextIssues/Core/issues/1534

Thom1729 commented 6 years ago

This should be fixed now. By default, the new embed_configuration introduced in 1.0.15 disables custom_template_tags. Please let me know if the problem recurs.

Thom1729 commented 6 years ago

See also: https://github.com/sublimehq/Packages/issues/179