graphql / graphiql

GraphiQL & the GraphQL LSP Reference Ecosystem for building browser & IDE tools.
MIT License
16.01k stars 1.72k forks source link

[vscode-graphql-syntax] Syntax for markdown should re-use js embed rules #3151

Open acao opened 1 year ago

acao commented 1 year ago

Current Behavior

Currently, we have a markdown implementation that applies it's own logic for detecting graphql tags inside markdown blocks.

In LSP terms, that is a three times embedded language, haha! Vue and Svelte, markdown, all are examples of languages that embeds js/ts, which users expect to highlight embedded markdown for.

Expected Behaviour

Any improvements to the javascript implementation should happen for markdown. We just need to tweak the grammar json files to do so.

acao commented 1 year ago

@AaronMoat for any issues related to markdown, it all traces back to this fix we need to make

I'm pretty sure with tweaking of these begin and end statements this would work, and the same would follow for each language (php, python, scala, etc)

{
  "fileTypes": [],
  "scopeName": "markdown.graphql.codeblock",
  "injectionSelector": "L:markup.fenced_code.block.markdown",
  "patterns": [
    {
      "contentName": "meta.embedded.block.graphql",
      "begin": "```(gql|graphql)?$",
      "end": "```",
      "patterns": [{ "include": "source.graphql" }]
    },
    {
      "contentName": "meta.embedded.block.js",
      "begin": "```(js|ts|jsx|tsx|svelte|vue)",
      "end": "```",
      "patterns": [{ "include": "source.graphql.js" }]
    }
  ]
}

microsoft LSP spec calls this "embedded language" behavior, not to be confused with actual embedded languages 😆 , this is three or four times embedded 😆

acao commented 1 year ago

3125 is related. the current approach is a blanket highlighting of everything that looks like a graphql tag, including outside of code blocks