How to use JSModuleReferenceContributor

I'm the author of the Ember.js plugin and I would like to make import references work properly. I'll give a few examples:

- `import foo from 'ember-cli-foobar'`: the ES6FromClause reference should point to `node_modules/ember-cli-foobar/addon/index.js` if it exists

- `import foo from 'ember-cli-foobar/mixins/some-mixin'`: the ES6FromClause reference should point to `node_modules/ember-cli-foobar/addon/mixins/some-mixin.js` if it exists

Also auto complection should work as expected in both cases.

I've experimented with the `JSModuleReferenceContributor` class and managed to solve the second example to some degree. I've adjusted the `ember-cli-foobar` part to point to `node_modules/ember-cli-foobar/addon` and auto completion and referencing for files inside that folder seem to work. 

What does not work though is making the first example work, and also, in the second example, having the `ember-cli-foobar` part to point to `node_modules/ember-cli-foobar`, but still provide completion for inside of the `addon` folder.

I'd be very happy if someone could point me in the right direction on this topic!


Could you please share your JSModuleReferenceContributor implementation for me to understand where you are now?

Basically, for the first case you may look at NodeFileModulePsiReference, it handles similar situation. For the second case I guess you should add ember-cli-foobar/addon as a context to the second reference (ember-cli-foobar/anyRefName), i.e. override FileReference.getContexts().


you can find my current approach at

as you can see I'm just prototyping at this point, not really knowing what I'm doing ;)


Please sign in to leave a comment.