Thom1729 / Sublime-JS-Custom

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

Embedded markdown recursion error #144

Open bcomnes opened 11 months ago

bcomnes commented 11 months ago

Sublime Text build number

4152

Example Code

n/a

JS Custom Preferences

{
  "defaults": {
    "custom_template_tags": false,
    "eslint_directives": true,
    "jsx": false,
    "custom_templates": {
      "styled_components": true,
      "tags": {
          "SQL": "scope:source.sql",
          "css": "scope:source.css",
          "html": "scope:text.html.basic",
          "svg": "scope:text.html.basic",
          "this.html": "scope:text.html.basic",
          "md": "scope:text.html.markdown"
      },
      "comments": {
        "GraphQL": "scope:source.graphql",
        "gql": "scope:source.graphql",
        "css": "scope:source.css",
        "html": "scope:text.html.basic",
        "xml": "scope:text.xml"
      }
    }
  },
  "configurations":
  {
    "Default": {},
    "React": {"file_extensions": ["js", "jsx"], "flow_types": true, "jsx": true, "scope": "source.jsx"},
    "TypeScript": {"file_extensions": ["ts"], "scope": "source.ts", "typescript": true},
    "TypeScript (JSX)": {"file_extensions": ["tsx"], "jsx": true, "scope": "source.tsx", "typescript": true}}

}

Configuration name

Default/React (any of them).

Description

When I add a md tag to the list, and set the scope:text.html.markdown scope, I get the following error:

Screenshot 2023-11-02 at 2 02 27 PM
Error loading syntax file
"Packages/User/JS Custom/ Syntaxes/React.sublime-syntax": Apparent recursion within a with_prototype action:
25000 context sanity limit hit

Maybe I am doing something wrong? Is there a workaround for this error?

Thom1729 commented 11 months ago

This is a known issue — when two syntaxes embed each other, and one injects escaping behavior, it loops when trying to compile them. The custom template code in JS Custom injects escaping behavior, so it would break if you embedded Markdown, which in turn embeds JS.

To avoid this, the default behavior is to also build an extra configuration for embedding that disables custom templates. So your JS Custom syntax would embed Markdown, which would in turn embed the special embed configuration, which doesn't embed Markdown.

I'm not sure exactly what's gone wrong in this case. Is that your exact entire settings file? The error message refers to a React.sublime-syntax, not to a Default syntax.

bcomnes commented 11 months ago

Sorry, bad copy past. I updated it to the full settings. I understand the suggestion conceptually, but do you have an example of setting up the embed config?

The error message refers to a React.sublime-syntax, not to a Default syntax.

Sorry, the error was throwing on any of them immediately after rebuilding the syntax.

Thom1729 commented 11 months ago

I've been playing around with this without luck. Either it's a cycle between JS Custom and Markdown (and I don't see how that's happening) or it's somehow hitting the context limit without cycling (which seems implausible). I think later today I'll have to play around with a stripped-down Markdown syntax and see if I can isolate it.