在 VS Code 工作区中管理函数

本页面介绍了如何在单个工作区和多文件夹工作区中管理多项 Cloud Functions 配置,以及如何使用 Cloud Code 重新排列 Cloud Functions Explorer。

准备工作

本指南要求必须已设置工作区(一个 launch.json 文件,其中至少列出一项配置)。要开始使用示例,请参阅创建和部署函数快速入门。

在一个工作区中管理多个配置

如需将新的 Cloud Function 配置添加到 launch.json 文件中,请按以下步骤操作:

  1. 点击 Cloud Code,然后展开 Cloud Functions Explorer。

  2. 在 Cloud Functions Explorer 中,将指针悬停在工作区上,然后点击添加新的 Cloud Functions 函数配置

  3. 按照提示操作并执行以下操作:

    1. 输入函数名称
    2. 选择 Cloud Functions 环境
    3. 输入入口点(为此函数调用的方法的名称)
    4. 输入测试输入内容

    或者,您也可以在 launch.json 文件中手动输入这些值:

    {
        "configurations": [
          {
            "name": "Deploy Cloud Function",
            "type": "cloudcode.cloudfunctions",
            "request": "launch",
            "functionName": "hello-world-get",
            "gen": "GEN_2",
            "entryPoint": "helloGet"
          }
        ]
    }
    

    您的 Cloud Functions 工作区对应于 launch.json 文件中列出的第一个配置。工作区名称反映了 launch.json 文件中列出的第一个配置的 functionName

    {
        "configurations": [
          {
            "name": "Deploy Cloud Function",
            "type": "cloudcode.cloudfunctions",
            "request": "launch",
            "functionName": "hello-world-pub-sub",
            "gen": "GEN_2",
            "entryPoint": "helloPubSub"
          },
          {
            "name": "Deploy Cloud Function",
            "type": "cloudcode.cloudfunctions",
            "request": "launch",
            "functionName": "hello-world-get",
            "gen": "GEN_2",
            "entryPoint": "helloGet"
          }
        ]
    }
    
  4. (可选)如需从 launch.json 文件中部署其他配置,请将要部署的配置移至 launch.json 文件的顶部,然后点击刷新 刷新 Cloud Functions Explorer

管理多文件夹工作区

如果每个函数都包含自己的 launch.json 文件,则 Cloud Code 支持在一个 Cloud Functions 工作区中包含多个文件夹。

Cloud Functions Explorer 中的多文件夹工作区

显示的每个 Cloud Functions 工作区文件夹都以其相应 launch.json 文件中的第一个配置 functionName 命名。

如需为项目安排多文件夹工作区,请参阅 VS Code 的多根工作区

将 Cloud Functions Explorer 重新排列到 IDE 的文件资源管理器中

您可以通过执行以下操作,将 Cloud Functions Explorer 重新排列到 VS Code 的文件资源管理器中:

  1. 将 Cloud Functions Explorer 拖到 VS Code 的文件资源管理器中:

    重新排列了 Cloud Functions Explorer

    此布局会在文件资源管理器下显示 Cloud Functions Explorer,以便您在项目文件所在的窗格中查看已部署的函数和 Cloud Functions 工作区。

  2. (可选)如需撤消此安排,请右键点击 Cloud Code: Cloud Functions 资源管理器的标题,然后选择重置位置。这会将 Cloud Functions Explorer 移回 Cloud Code 标签页。

获取帮助

如需发送反馈,请在 GitHub 上报告问题,或者在 Stack Overflow 上提问。