Turbo87 / intellij-emberjs

Ember.js support for JetBrains IDEs (IntelliJ, WebStorm, ...)
Apache License 2.0
218 stars 33 forks source link

Snippets for new modules api #151

Open vlascik opened 7 years ago

vlascik commented 7 years ago

How about some snippets similar to https://atom.io/packages/ember-module-snippets ? This could help with the learning curve for new modules api layout a lot.

Turbo87 commented 7 years ago

@vlascik to be honest I'd rather just have the IDE suggest the right import automatically instead of adding snippets that you would have to manually invoke

dwickern commented 7 years ago

I would much rather have auto imports like in JVM languages, but not sure if that will ever happen...

I noticed IntelliJ supports javascript auto-import already in some cases. If you have this module

// foo.js
export function foo() {}

and in another file you type foo then Ctrl-Space, it will autocomplete to

import {foo} from "./foo";
foo()

Maybe all we need is typescript definitions for the new ember modules

Turbo87 commented 7 years ago

Maybe all we need is typescript definitions for the new ember modules

Not sure if those are auto-imported in JS files too, but for TS files that should probably work

vlascik commented 7 years ago

Hm typescript definitions seem to be doable, https://www.typescriptlang.org/docs/handbook/modules.html#working-with-other-javascript-libraries . Maybe these could be generated from data at https://github.com/ember-cli/ember-rfc176-data with a script similar to ones that are there already.

You can use TS definitions in JS too, just go to Settings -> Languages & Frameworks -> Javascript -> Libraries -> Download.

dwickern commented 7 years ago

The auto imports work for typescript...

screen shot 2017-07-19 at 6 36 44 pm

I can't get it working for javascript sources. It autocompletes global declarations but won't import from an ambient module.

Turbo87 commented 7 years ago

@denofevil any clue how we can make this work in JS files?

anstarovoyt commented 7 years ago

@Turbo87 @vlascik can you please share the typescript definitions?

dwickern commented 7 years ago

@anstarovoyt this is what I'm testing with:

// ember.d.ts
declare module "@ember/component" {
  export class Component {}
}
vlascik commented 7 years ago

So, got bored, and created a script to generate ember.d.ts based on RFC 176 data: https://github.com/ember-cli/ember-rfc176-data/pull/25

Generated file here: https://gist.github.com/vlascik/678b7163f2cd62241b3ede0a0fe66c87

Module name completion should work, but as said previously, in JS files, auto imports don't.

nadnoslen commented 6 years ago

I just recently upgraded my main project to Ember-2.16 and would love my JetBrains IDE to auto-import. I'm speculating that we've still got many things to figure out.

I've hacked some Live Templates together; over in this Gist: https://gist.github.com/nadnoslen/82e29fae98d12bbc81e6614abdd211dd

I'd be happy to put a PR together that includes this new template file. Might need to settle on naming conventions; I've used i[TYPE]; e.g. icomputed.

Here's an example, it's manual and it kind of auto-completes for you:

ember-2 16-imports-demo

nadnoslen commented 6 years ago

Until the IDE can do this better, I've packaged up my live templates for just these Ember-2.16+ imports. The attached live-templates.zip that contains only the one live template group: "Ember.js-2.16+ Import Templates"...and it looks like this:

default_preferences

live-templates.zip