Search code examples
webstormcommonjs

Webstorm helper for requiring module


I'm looking for a way to require module easily with Webstorm (shortcut, plugin, intention, ...). Here is my use case :

  • Given my cursor located at the end of a unknown variable myVar somewhere in my JS file.
  • When I press a shortcut, I jump at the top of the file and var myVar = require('') is inserted with the cursor inside the empty string.
  • Then I type the name of the module and I press enter.
  • Then the cursor go back at the end of the variable.

Is there a way to do that ?


Solution

  • Please vote for WEB-14430. You can try developing a custom intention - code intentions use the regular API for intentions. The intention classes need to implement the IntentionAction interface and to be registered using the bean in the plugin.xml (http://confluence.jetbrains.com/display/IDEADEV/Developing+Custom+Language+Plugins+for+IntelliJ+IDEA) See https://github.com/JetBrains/intellij-community/blob/master/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/control/SplitIfIntention.java - intention sample for Groovi.

    See also http://confluence.jetbrains.com/display/IDEADEV/PluginDevelopment, http://devnet.jetbrains.com/message/5298765.

    Live Templates is another option, but it just allows expanding certain abbreviation into a code snippet - no jumping, etc. - snippet will be expanded 'in-place'