Site icon 峰哥分享

Make VScode Auto completion and definition jump work on Google Apps Script Clasp

If you have ever developed Google Apps script with its default online IDE, you may have noticed that auto completion is not there for easy access of functions.

Google provide a CLI tool “Clasp” which can pull Google Apps Scritp .gs files onto your local converted to .js files.

Then you can version control these files and edit them in your favorite editor. Then you can push your edited files back to Google.

I use Visual Studio code as my Google Apps script IDE. By default, the auto completion only works within the same files. If you defined a function or variable in another file, the auto completion will not work. And you cannot jump to function definition by pressing F12.

To make the auto completion works, some configurations are needed.

The following is what I do to enable auto completion for Google Apps Script in VScode.

1. Run npm init to convert it to a nodejs project. A package.json file will be created.
2. Install google apps script type npm install –save @types/google-apps-script
3. Install typescript type npm install –save @types/google-apps-script
4. Create a jsconfig.json with following content:

{ 
    "compilerOptions": {
        "checkJs": true
      }
}  

5. Create a tsconfig.json file with following content:

{ 
    "compilerOptions": {
        "allowJs": true,
        "checkJs": true,
        "types": ["google-apps-script"]
      }
}  

6. Create a .claspignore file contains following content:

jsconfig.json
tsconfig.json
.gitignore
node_modules/**

Once you have done the above steps, you will find the auto completion works magically.

Exit mobile version