如何在本地安装的IDE中启用Google Apps脚本的自动完成

发布于 2025-02-13 21:26:57 字数 614 浏览 1 评论 0 原文

我正在尝试使用 clasp

任何本地安装的IDE都对Google的脚本编辑器进行了巨大改进,因此该工具看起来非常有前途。不幸的是,包装中似乎不包含用于天然气服务的自动完成功能。

文档说:

应用程序脚本CLI使用TypeScript在开发时提供自动完成和覆盖。使用IDE之类的Visual Studio代码进行打字稿自动完成。

经过步骤并安装所有必需的依赖项后,我仍然无法使自动完成功能工作。当我为现有项目执行 clasp拉命令时,它将“ .gs”扩展名转换为“ .js”。自动完成建议仅仅是解析现有代码的结果。

例如,如果我调用 sheet.getRange()在我的代码中的某个地方,则 getRange()方法将在建议中弹出,但我无法列出可用的选项。因为,除非我的代码已经使用,否则 properieservice

有人对Google Apps脚本启用自动完成功能有任何好运吗?

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

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

听不够的曲调 2025-02-20 21:26:57

我找到了部分有效的解决方案,但可能不适用于其他软件。下面的步骤是为Visual Studio代码:

  1. 使用

    安装包含气体类型定义的NPM软件包

      https://www.npmjs.com/package/@types/google-apps-script
     
  2. 在本地保存的脚本中 ,创建一个'.js'文件和类型

     导入'google-apps-script';
     

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';
    
苍暮颜 2025-02-20 21:26:57

此答案是对IDE/扩展的接受的答案的较小变化,该变体基于 tsc / tsserver

  • install install themplent typescript和 @typess/google-- Apps-Script

  • 创建 jsconfig.json 您本地项目目录中的文件:

      { 
        “ compileroptions”:{
            “ checkjs”:true
          }
    }    
     

  • 另外,如果您正在使用 typef> typescript 与javascript一起,然后创建一个 tsconfig.json

      { 
        “ compileroptions”:{
            “允许J”:是的,
            “ checkjs”:是的,
            “类型”:[“ Google-Apps-script”]
          }
    }    
     

  • href =“ https://www.typescriptlang.org/docs/handbook/tsconfig-json.html” rel =“ noreferrer ” 在 .claspignore 中,如果您使用的是clasp,并且文件在您的本地目录中。

  • 如果配置在您的家中/父目录中,则可以在全球使用此配置在 .claspignore 中)。

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

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

浮萍、无处依 2025-02-20 21:26:57

如果您使用的是任何Jetbrains IDE:

转到语言&框架 - > JavaScript->图书馆 - >下载... 并下载库 Google-Apps-Script

If you are using any JetBrains IDE:

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

enter image description here

风月客 2025-02-20 21:26:57

尝试包括文件名, import.js in .claspignore (docs)

每次推动之前,这都应该节省一些麻烦在文件上删除。

Try including the file name, import.js in .claspignore (docs).

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

非要怀念 2025-02-20 21:26:57

这是Google开发人员在“ “视频。

将JavaScript文件添加到您的项目中,例如“ appscript.js”,在该文件中,添加:

import "google-apps-script";

保存该文件,但请确保使用 .claspignore 文件将文件推回项目时忽略它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文