8

Is there a way to get autocompletion for Google Apps Script in Webstorm or any Jetbrains IDE?

I have read, that it's possible for ecplise.

Can i get the GAS library somehow into Webstorm? Or what exactly would I have to do, to get the autocompletion to work? :)

JohnRW
  • 748
  • 7
  • 22

4 Answers4

7

A similar question you can refer to:
How do I use WebStorm for Chrome Extension Development?, the only difference to the referred answer is in step 5, try to search for google-apps-script (instead of chrome).

Install the library and open gs files as JavaScript.

Then you are going to have grammar highlighting and autocompletion.

Kos
  • 4,890
  • 9
  • 38
  • 42
Mingzhong
  • 223
  • 4
  • 6
  • to find out how to use `clasp` locally, which will convert your project gs files to js, see https://stackoverflow.com/questions/24739294/does-google-apps-script-support-external-ides for example – Kos Dec 10 '20 at 17:27
5

How about using TypeScript instead of pure JavaScript?

Definition file for GAS is available here. https://github.com/DefinitelyTyped/DefinitelyTyped/pull/6723

I haven't tried it yet but I'm planning to try it. I've just started using GAS and am exploring GAS now.

P.S In order to code GAS, this article may be helpful. http://googleappsdeveloper.blogspot.jp/2015/12/advanced-development-process-with-apps.html

2

WebStorm (and any JetBrains IDE with the JavaScript plugin) can now handle this automatically by using TypeScript community stubs. The details are in Configuring JavaScript Libraries - Help - WebStorm.

Follow the instructions on that page under To download TypeScript definitions in the Settings/Preferences dialog. Search for the TypeScript community stub named google-apps-script.

WebStorm will try to guess the type of variables based on the context, but you can also tell it explicitly. For example this tells WebStorm that thread is a GmailThread. So getLabels could be autocompleted.

/**
 * @param {GoogleAppsScript.Gmail.GmailThread} thread
 */
function getThreadInfo(thread) {
  thread.getLabels()
}

FYI, You can search for TypeScript community stubs and get more information on each one at https://microsoft.github.io/TypeSearch/.

studgeek
  • 14,272
  • 6
  • 84
  • 96
1

I've looked around as well but haven't found anything yet. I don't think so, but I could be wrong. In order to get it to work, you could reverse engineer the Eclipse plugin, which I'm guessing won't be straightforward.

Sujay Phadke
  • 2,145
  • 1
  • 22
  • 41