intellij-emberjs icon indicating copy to clipboard operation
intellij-emberjs copied to clipboard

Snippets for new modules api

Open vlascik opened this issue 7 years ago • 11 comments

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.

vlascik avatar Jul 19 '17 23:07 vlascik

@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

Turbo87 avatar Jul 19 '17 23:07 Turbo87

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

dwickern avatar Jul 20 '17 00:07 dwickern

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

Turbo87 avatar Jul 20 '17 00:07 Turbo87

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.

vlascik avatar Jul 20 '17 01:07 vlascik

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.

dwickern avatar Jul 20 '17 01:07 dwickern

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

Turbo87 avatar Jul 20 '17 06:07 Turbo87

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

anstarovoyt avatar Jul 21 '17 08:07 anstarovoyt

@anstarovoyt this is what I'm testing with:

// ember.d.ts
declare module "@ember/component" {
  export class Component {}
}

dwickern avatar Jul 21 '17 15:07 dwickern

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.

vlascik avatar Jul 26 '17 22:07 vlascik

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 avatar Jan 19 '18 21:01 nadnoslen

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

nadnoslen avatar Jan 25 '18 21:01 nadnoslen