How to enable autocomplete for Google Apps Script in locally-installed IDE

后端 未结 5 1880
深忆病人
深忆病人 2020-12-01 01:42

I\'m trying to build GAS projects locally using clasp.

Any locally-installed IDE is a huge improvement over Google\'s Script Editor, so the tool looks very promising

相关标签:
5条回答
  • 2020-12-01 02:03

    This answer is a minor variation on the accepted one for IDEs/extensions which support Typescript auto completion based on tsc/tsserver:

    • Install TypeScript and @types/google-apps-script

      • https://www.npmjs.com/package/typescript
      • https://www.npmjs.com/package/@types/google-apps-script
    • Create a jsconfig.json file in your local project directory:

      { 
          "compilerOptions": {
              "checkJs": true
            }
      }    
      
    • Alternatively, If you're using typescript along with javascript, then create a tsconfig.json:

      { 
          "compilerOptions": {
              "allowJs": true,
              "checkJs": true,
              "types": ["google-apps-script"]
            }
      }    
      
    • Include both filenames in .claspignore, if you're using clasp and if the file is in your local directory.

    • You can also use any of this config globally, if the config is in your home/parent directory, as tsc searches for this config from project/local folder to root(in which case, you don't need to include it in .claspignore).

    0 讨论(0)
  • 2020-12-01 02:03

    Try including the file name, import.js in .claspignore.

    This should save some trouble deleting the file before each push every time.

    0 讨论(0)
  • 2020-12-01 02:06

    This is an answer provided by Google developers in the "TU17: Enhancing the Google Apps Script Developer Experience with clasp and TypeScript" video.

    Add a JavaScript file to your project like "appscript.js" and, in that file, add:

    import "google-apps-script";
    

    Save that file but make sure to ignore it when pushing files back to your project using a .claspignore file.

    0 讨论(0)
  • 2020-12-01 02:18

    I found the solution that partially works, but it may not be applicable to other software. The steps below are for Visual Studio Code:

    1. Install the NPM package containing type definitions for GAS using

      https://www.npmjs.com/package/@types/google-apps-script
      
    2. In your locally-saved script, create a '.js' file and type

      import 'google-apps-script';
      
    0 讨论(0)
  • 2020-12-01 02:23

    If you are using any JetBrains IDE:

    Go to Languages & Frameworks -> JavaScript -> Libraries -> Download... and download the library google-apps-script.

    0 讨论(0)
提交回复
热议问题