Enabling autocomplete for Google Apps Script in locally-installed IDE

三世轮回 提交于 2019-12-28 05:23:39

问题


I'm trying to build GAS projects locally using clasp

https://github.com/google/clasp

Any locally-installed IDE is a huge improvement over Google's Script Editor, so the tool looks very promising. Unfortunately, the autocomplete feature for GAS services doesn't seem to be included in the package.

The documentation says:

The Apps Script CLI uses TypeScript to provide autocompletion and linting when developing. Use an IDE like Visual Studio Code for TypeScript autocompletion.

After going through the steps and installing all required dependencies, I'm still unable to get the autocomplete feature to work. When I execute "clasp pull" command for the existing project, it converts ".gs" extension to ".js". The autocomplete suggestions are simply the result of parsing existing code.

For example, if I call sheet.getRange() somewhere in my code, then the 'getRange()' method will pop up in suggestions, but I can't list available options for, say, PropertiesService, unless it's already used in my code.

Has anybody had any luck with enabling autocomplete feature for Google Apps Script?


回答1:


I found the solution that kind of 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

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';

The only issue is imports must be removed before pushing updates to the server.




回答2:


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).




回答3:


How about:

Including the file name (e.g. import.js) in .claspignore.

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




回答4:


this is an answer provided by google developers at the following video:

TU17: Enhancing the Google Apps Script Developer Experience with clasp and TypeScript

add a .js file to your project like appscript.js and in that file add the following code:

import "google-apps-script";

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




回答5:


If you are using any JetBrains IDE:

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



来源:https://stackoverflow.com/questions/49015874/enabling-autocomplete-for-google-apps-script-in-locally-installed-ide

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!