Skip to content

Provide completions for template globals #61

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

Merged
merged 2 commits into from
Mar 13, 2021
Merged

Conversation

dfreeman
Copy link
Member

I'm working on generating types for the built-in Ember intrinsics (which is the last remaining thing before "write a Getting Started and then publish"!) when I realized we weren't providing completion suggestions for global values. This includes intrinsics and, in the case of environment-ember-loose, everything user-defined as well.

The fundamental issue was a small bug in the template rewriting logic, but fixing that unearthed a thornier issue, which is that given the way the system works today, we can't simultaneously provide completions for both in-scope identifiers and global items.

Today when we see a mustache like {{foo}}, that might ultimately be emitted as foo (if foo is an in-scope identifier) or as Globals['foo'] if it's not. The transformation process takes a list of known static identifiers as input, which is how we know which version to emit, but if as a user I've only typed fo so far, we can't a priori know whether emitting fo or Globals['fo'] is going to yield the completion results we want.

The solution here gets the immediate issue unblocked and provide what's hopefully good-enough support for both loose-mode and strict-mode templates. When emitting an identifier, if it's a prefix of a something we statically know is in scope, we emit the prefix directly; otherwise we assume it's a global lookup.

For loose-mode, this should work fine as essentially nothing is ever statically in scope. For strict-mode, this means that you won't get e.g. a completion for each when you type ea if earlyRiser is in scope somewhere. That seems like an ok tradeoff to me, but we can always revisit down the line if it turns out to be a problem.

@dfreeman dfreeman added the bug Something isn't working label Mar 13, 2021
@dfreeman dfreeman merged commit 358fd94 into master Mar 13, 2021
@dfreeman dfreeman deleted the globals-completion branch March 13, 2021 19:37
@chriskrycho
Copy link
Member

Seems reasonable to me as well. In particular, because we can revise it later once the ecosystem has moved primarily to strict mode, in favor of not needing this kind of heuristic-ish approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants