Code Monkey home page Code Monkey logo

vscode-glimmer's Introduction

vscode-glimmer

VSCode extension for glimmer js components.

Features

Syntax Highlighting

This extension adds syntax highlighting for embedded Glimmer templates in JavaScript and TypeScript. It supports two types of embedded template syntaxes:

  1. Template strings, using hbs to denote that they are Handlebars templates:

template strings demo

  1. Template tags, using a custom <template> syntax

template tag demo

It also adds support for the .gjs and .gts file extensions, which are aliases to JavaScript and TypeScript respectively.

Note: Syntax highlighting for handlebars requires installing the Handlebars VSCode extension

Developing

What's in the folder

  • package.json - this is the manifest file in which you declare your language support and define the location of the grammar file that has been copied into your extension.
  • syntaxes/inline-hbs.json - this is the Text mate grammar file that is injected into javascript and typescript languages.

Get up and running straight away

  • Press F5 to open a new window with your extension loaded.
  • Create a new file with a file name suffix matching either javascript or typescript.
  • Verify that syntax highlighting works and that the language configuration settings are working.

Make changes

  • You can relaunch the extension from the debug toolbar after making changes to the files in the extension.
  • You can also reload (Ctrl+R or Cmd+R on Mac) the VS Code window with your extension to load your changes.

vscode-glimmer's People

Contributors

chiragpat avatar ignacemaes avatar dfreeman avatar

Stargazers

Slimane Amiar avatar  avatar Abhas Bhattacharya avatar Jeff Hertzler avatar Scott Ames-Messinger avatar Mehul Kar avatar  avatar eduscrakozabrus avatar Ilya Radchenko avatar Alex Kanunnikov avatar

Watchers

Jarek Radosz avatar James Cloos avatar  avatar Hank Majoros avatar

vscode-glimmer's Issues

Differences to standard JS/TS

Somehow creating a new syntax for glimmer-ts and glimmer-js causes slight differences even though they extend from js and ts. I attempted to port the changes made by @dfreeman here to https://github.com/lifeart/vsc-ember-syntax and saw the same issues appear.

What I've spotted so far and if a fix is found

  • Decorators are incorrectly highlighted
  • Arrow functions are incorrectly highlighted
  • Code folding only on template tag
  • HBS Comment Highlighting
  • eslint does not run
    • solved with settings change
  • Missing functionality

Decorators are incorrectly highlighted

I believe this is when used with the glint-language-server, I don't think it provides the semanticTokenScopes required to apply the correct colours ontop of the syntax highlighting.

Typescript Language Server provides semantic tokens here https://github.com/microsoft/vscode/blob/main/extensions/typescript-language-features/src/languageFeatures/semanticTokens.ts
@dfreeman Do you have any idea why they would not get passed down from TS -> Glint?

Incorrect Correct
image image
image image

Solution
Not sure


Arrow functions are incorrectly highlighted (✅ solved)

Incorrect Correct
image image
Solution

PR #13

So, given this file

// syntaxes/glimmer-ts.json
{
  "scopeName": "source.gts",
  "patterns": [{ "include": "source.ts" }]
}

If I make it so source.ts is broken like source.bla all highlighting except for some suspect characters is removed.
image

These extra colours come from having this setting turned on.
image

The arrow function > being red is down to that setting and gives a reason for #5 occuring

To fix that we need to add the following to the glimmer-ts and glimmer-js grammars in the package.json.

"unbalancedBracketScopes": [
  "keyword.operator.relational",
  "storage.type.function.arrow",
  "keyword.operator.bitwise.shift",
  "meta.brace.angle",
  "punctuation.definition.tag",
  "keyword.operator.assignment.compound.bitwise.ts"
]

Code folding only on template tag (✅ partially solved)

If I reload the window, very breifly I can see the code folding arrows I'd expect then it switches to only offering folding for the template tag and it's contents.

This seems to be related to running ember-language-server. Tracking lifeart/vscode-ember#43

Incorrect Correct
image image
Partial Solution

Set editor.foldingStrategy to indentation in settings.

"[glimmer-js]": {
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "editor.foldingStrategy": "indentation"
},
"[glimmer-ts]": {
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "editor.foldingStrategy": "indentation"
},

Solution
Ember Language Server to provide a js/ts folding


HBS Comment Highlighting (✅ solved)

If a comment includes an @ symbol, the highlighting changes for that word

Incorrect Correct
image image
Solution

PR #15

The handlebars extension was causing this, merging #15 and disabling that extension will fix the issue.


eslint does not run (✅ solved)

I think since the files are glimmer-ts files and not typescript files, eslint doesn't know to run

Incorrect Correct
image image
Solution

Need to add glimmer-ts and glimmer-js to eslint.validate.

// .vscode/settings.json
{
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact",
    "html",
    "vue",
    "markdown",
    "glimmer-ts",
    "glimmer-js"
  ],
  "eslint.rules.customizations": [
    { "rule": "*", "severity": "warn" },
  ]
}

Missing functionality

  • With remove-unused-imports installed any unused imports should be automatically removed, updating the code to run on glimmer-ts or glimmer-js files results in an error becaue of the template tag being passed to babel/typescript. A fix would need to happen in that plugin.
  • Code natively offers an Organise Imports option from typescript which is not available on glimmer-* files.
  • Auto-closing tags do not work inside <template> tags, possibly because html-language-server is not running for embedded handlebars

@dfreeman @chiragpat any ideas?

Perculiar syntax highighting of template imports

Template Only Component

Color stops after the closing template tag and only starts after I use console.log (I assume other function usage would do the same)

image
image

Class Component

Template highlighting just seems broken, decorators are not highlighted
image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.