如何在本地安装的IDE中为Google Apps脚本启用自动完成功能 [英] How to enable autocomplete for Google Apps Script in locally-installed IDE

查看:161
本文介绍了如何在本地安装的IDE中为Google Apps脚本启用自动完成功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 clasp 在本地构建GAS项目.

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

任何本地安装的IDE都比Google的脚本编辑器有很大的改进,因此该工具看起来非常有前途.不幸的是,GAS服务的自动完成功能似乎并未包含在包装中.

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.

文档说:

在开发过程中,Apps Script CLI使用TypeScript提供自动补全功能.使用诸如Visual Studio Code之类的IDE进行TypeScript自动补全.

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

完成这些步骤并安装了所有必需的依赖项之后,我仍然无法使自动完成功能起作用.当我对现有项目执行clasp pull命令时,它将".gs"扩展名转换为".js".自动完成建议只是解析现有代码的结果.

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

例如,如果我在代码中的某个地方调用sheet.getRange(),则getRange()方法将在建议中弹出,但是我无法列出例如PropertiesService的可用选项,除非已在PropertiesService中使用了该选项.我的代码.

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.

有人为Google Apps脚本启用自动完成功能感到幸运吗?

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

推荐答案

我找到了部分可行的解决方案,但它可能不适用于其他软件.以下步骤适用于Visual Studio代码:

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. 使用以下方法安装包含GAS类型定义的NPM软件包

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

https://www.npmjs.com/package/@types/google-apps-script

  • 在本地保存的脚本中,创建一个".js"文件并输入

  • In your locally-saved script, create a '.js' file and type

    import 'google-apps-script';
    

  • 这篇关于如何在本地安装的IDE中为Google Apps脚本启用自动完成功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆