Commit 41c7524
committed
Add Glint to the project
This adds basic [Glint]-powered capabilities to the project for anyone
using a Glint Language Server client (VS Code, NeoVim, IntelliJ, etc.).
Setup
-----
The setup to make that work involves adding some `devDependencies`:
- `@glint/core` to enable Glint and `@glint/environment-ember-loose` to
tell Glint how to interpret Ember's "loose-mode" templates, i.e.
"normal"
- `typescript`, which Glint requires to work at all. **This is _not_
adding TypeScript to the project.** It just exists to enable Glint to
run. (Glint doesn't ship its own copy because TypeScript is large and
it is important that Glint use the same version of TypeScript that an
app uses, or else it would give conflicting reports.)
- A number of `@types` packages, which are required so that Glint knows
what a `Controller` or Ember `Component` are, and so on. These will
all be able to go away as packages start shipping their own types,
including when this app is able to upgrade to at least Ember 4.8 and
start using the types that Ember ships itself.
It also configures Glint via tweaks to the existing `jsconfig.json`
file, with good defaults so that it never shows *errors*, but does
progressively enhance the experience for JS users.
Other changes
-------------
With the foundations in place, add some JSDoc comments and a single TS
file to the project.
- The JSDoc comments show how to make TS-powered tooling (like the
various Glint language servers) understand components in the app.
These comments, which build on the spec for both types and comments
defined in [Ember RFC 0748][rfc], work well to enhance the experience
of authoring JS backing classes even *without* Glint. With Glint
enabled, though, it also makes all of that information available in
templates.
- The TS file shows how to make Glint understand component references.
It is basically a hand-coded version of what the Ember resolver does
at runtime: translating string names like `MyComponent` into
references to the `MyComponent` class. There are limitations to how
much this can do in a purely JS project with loose mode templates,
but in this app it can cover *most* of the territory (and a move to
strict mode templates using `<template>` in the future will close
*all* of those gaps).
Both of these show the "progressive enhancement" model at work: out of
the box, you get a *very* minimal set of go-to-definition, refactoring,
etc. capabilities. Not none! But minimal. The more fino you put into
your JSDoc comments, though, and the more items you add to the template
registry, the more useful Glint becomes.
[rfc]: https://rfcs.emberjs.com/id/0748-glimmer-component-signature
Caveats
-------
This does not yet provide *all* the benefits that Glint can provide to
JS-only apps. For example, you won't be able to go-to-definition for
the `this.model` of route/controller templates unless you add a `model`
field on the `Controller` class with a JSDoc annotation. Similarly, you
will not be able to go-to-definition or see hover docs for a lot of the
data used in the application just yet: the app will need to add some
JSDoc annotations to tell the language server "this field here is that
data model class from over there".
However, it *does* already provide significant benefits for simple
things like being able to go to definition or rename items in component
files, and as the one JSDoc annotation added in this shows, you can get
more of these benefits with a very low level of effort.
[Glint]: https://github.com/typed-ember/glint1 parent db828db commit 41c7524
File tree
8 files changed
+441
-15
lines changed- app
- components
- templates
- components
8 files changed
+441
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
10 | 24 | | |
11 | 25 | | |
12 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
| 1 | + | |
4 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
5 | 23 | | |
6 | | - | |
7 | 24 | | |
8 | 25 | | |
9 | 26 | | |
10 | 27 | | |
11 | 28 | | |
12 | | - | |
| 29 | + | |
13 | 30 | | |
14 | 31 | | |
15 | 32 | | |
16 | 33 | | |
17 | 34 | | |
18 | 35 | | |
19 | | - | |
| 36 | + | |
20 | 37 | | |
21 | 38 | | |
22 | 39 | | |
23 | 40 | | |
24 | 41 | | |
25 | 42 | | |
26 | | - | |
| 43 | + | |
27 | 44 | | |
28 | 45 | | |
29 | 46 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
10 | 18 | | |
11 | 19 | | |
12 | 20 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
2 | 3 | | |
3 | 4 | | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
33 | 35 | | |
34 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
35 | 53 | | |
36 | 54 | | |
37 | 55 | | |
| |||
114 | 132 | | |
115 | 133 | | |
116 | 134 | | |
117 | | - | |
| 135 | + | |
| 136 | + | |
118 | 137 | | |
119 | 138 | | |
120 | 139 | | |
| |||
0 commit comments