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

Glimmer grammar updates #7064

Merged
merged 24 commits into from
Aug 31, 2024
Merged

Conversation

NullVoxPopuli
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli commented Aug 20, 2024

This is stemming from an effort to move <template> support out of tree-sitter-javascript.
See this discussion: tree-sitter/tree-sitter-typescript#308

These 3 grammars are related

I tested this locally with packer, via
  use {
    -- 'nvim-treesitter/nvim-treesitter',
    '~/Development/OpenSource/nvim-treesitter',
    branch = "glimmer-updates",
    config = function()
      require("nvim-treesitter.install").prefer_git = true
      require 'nvim-treesitter.configs'.setup {
        autotag = {
          enable = true,
          filetypes = {
            "html",
            "javascript", "typescript",
            "typescript.glimmer", "javascript.glimmer",
            "javascriptreact", "typescriptreact",
            "markdown",
            "glimmer", "handlebars", "hbs", "svelte", "vue"
          }
        },
        ensure_installed = {
          -- Web Languages
          -- "javascript", "typescript",
          "html", "css", "regex",
          "ejs",
          -- Web Framework Languages
          "svelte",
          "glimmer", "glimmer_javascript", "glimmer_typescript",
          -- Web Transport Languages
          "graphql",
          -- Documentation Languages
          "markdown", "markdown_inline",
          -- "help", -- missing?
          -- "comment", -- slow?
          "jsdoc",
          -- Configuration Languages
          "toml", "jsonc", "yaml",
          "dockerfile",
          "lua", "vim",
          -- Scripting Languages
          "commonlisp",
          "bash",
          "jq",
          -- Systems Languages
          "c", "cmake",
          "rust",
          "go",
          -- Specifically for the treesitter AST
          "query",
          -- Utility Syntaxes
          "diff",
          "jq",
          "git_rebase", "gitcommit", "gitignore"
        },
        ignore_install = {
          "json" -- jsonc is better
        },
        highlight = {
          enable = true,
        },
        indent = {
          enable = true
        },
      }

      require('ts_context_commentstring').setup({})
      vim.g.skip_ts_context_commentstring_module = true
    end
  }

queries/glimmer/highlights.scm Outdated Show resolved Hide resolved
lua/nvim-treesitter/parsers.lua Outdated Show resolved Hide resolved
queries/glimmer/highlights.scm Outdated Show resolved Hide resolved
queries/glimmer_javascript/tags.scm Outdated Show resolved Hide resolved
@NullVoxPopuli NullVoxPopuli force-pushed the glimmer-updates branch 3 times, most recently from e868bc0 to b03f025 Compare August 20, 2024 21:14
@NullVoxPopuli NullVoxPopuli marked this pull request as ready for review August 21, 2024 01:44
@clason clason marked this pull request as draft August 21, 2024 07:06
@clason
Copy link
Contributor

clason commented Aug 21, 2024

Missing lockfile entries.

@NullVoxPopuli NullVoxPopuli marked this pull request as ready for review August 21, 2024 13:12
lua/nvim-treesitter/parsers.lua Outdated Show resolved Hide resolved
@clason clason requested a review from lucario387 August 22, 2024 08:10
NullVoxPopuli and others added 2 commits August 22, 2024 07:40
Co-authored-by: Christian Clason <c.clason@uni-graz.at>
Co-authored-by: Christian Clason <c.clason@uni-graz.at>
@ribru17
Copy link
Member

ribru17 commented Aug 25, 2024

Sorry for my ignorance: I am having trouble understanding glimmer and in what files it should apply, should something like the following be valid?

import { useStore } from '@builder.io/mitosis';

export default function SpecialTags() {
  const state = useStore({
    get scriptStr(): string {
      return `console.log('hello from script tag.')`;
    },
    styleStr: '.wrap { background-color: rgb(255, 0, 0); }',
  });
  return (
    <div>
      <template>
        <div>Template Tag Div</div>
      </template>
      <style data-testid="wrap-style" innerHTML={state.styleStr} />
      <div className="wrap">red content</div>
      <script data-testid="special-script" innerHTML={state.scriptStr} />
    </div>
  );
}

would this be a typescript.glimmer because of the <template> tag? Because right now the parser errors a bit for this ft. I may be misunderstanding in this PR in which case I think I don't have the expertise required to review it 😂

@NullVoxPopuli
Copy link
Contributor Author

should something like the following be valid?

it would not, that is more JSX, and JSX is not allowed.

would this be a typescript.glimmer because of the <template> tag?

If the <template> is used in one of two ways: as a regular expressoin, and as a class body property/expression (I don't know the exact name of things that go in the class body)

  • an expression
    e.g.:

    const example = 1;
    const Demo = <template>{{example}}</template>;
    const Demo2 = <template>
      <Demo />
      <div>{{example}}</div>
    </template>;
  • as a class body expression

    const example = 1;
    
    class Demo {
      property = 2;
    
      <template>
         <p>{{this.property}}</p>
         <div>{{example}}</div>
      </template>       
    }

For more information,
GitHub already supports this if you want to look at the linguist grammars:

```gjs
code here
```

And the TS variant:

```glimmer-ts

// Linguist already bound gts to Gnome something, so we couldn't use the shorthand

```

Here is the community RFC where we explored several other grammars/syntaxes for having something with the benefits with both JSX and Static templates while also not having the downsides of those tools: emberjs/rfcs#779

@ribru17
Copy link
Member

ribru17 commented Aug 25, 2024

Ah, that makes sense. Thanks for clarifying!

@clason clason merged commit 628f53e into nvim-treesitter:master Aug 31, 2024
9 checks passed
@NullVoxPopuli NullVoxPopuli deleted the glimmer-updates branch August 31, 2024 17:25
austincummings pushed a commit to austincummings/nvim-treesitter that referenced this pull request Sep 9, 2024
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 this pull request may close these issues.

5 participants