VS Code Git扩展API [英] VS Code Git Extension API

查看:199
本文介绍了VS Code Git扩展API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某处可以获取更多有关如何创建使用Git Extension API的扩展的文档吗?

Is there somewhere one can obtain more documentation on how to create an extension that uses the Git Extension API?

https://github.com/microsoft/vscode/blob/master/extensions/git/README.md 微软提供的唯一文档是:

At https://github.com/microsoft/vscode/blob/master/extensions/git/README.md the only documentation Microsoft provides is this:

注意::此扩展程序与Visual Studio Code捆绑在一起.可以禁用它,但不能将其卸载.

Notice: This extension is bundled with Visual Studio Code. It can be disabled but not uninstalled.

请参见 VS Code中的Git支持,以了解这些功能的扩展名.

See Git support in VS Code to learn about the features of this extension.

Git扩展公开了任何其他扩展都可以访问的API.

The Git extension exposes an API, reachable by any other extension.

  1. src/api/git.d.ts复制到扩展程序的源中;
  2. 在扩展程序的编译中包含git.d.ts.
  3. 使用以下代码段获取API:

  1. Copy src/api/git.d.ts to your extension's sources;
  2. Include git.d.ts in your extension's compilation.
  3. Get a hold of the API with the following snippet:

const gitExtension = vscode.extensions.getExtension<GitExtension>('vscode.git').exports;
const git = gitExtension.getAPI(1);

这真的没有帮助,当我尝试使用这两行时,扩展会运行,但是如果我尝试检查,例如git.repositories [0],它将返回未定义. Idk,如果我做错了什么? :(

It really doesn't help and when I try to use those 2 lines the extension runs but if I try to check, for example, git.repositories[0] it returns undefined. Idk if I'm doing something wrong? :(

推荐答案

您可以查看 eamodio/vscode-gitlens ,它是基于Git扩展的主要扩展.

You can have a look at eamodio/vscode-gitlens, the main extension based on Git extension.

src/git/gitService.ts 确实调用了GIt扩展名:

Its src/git/gitService.ts does call the GIt extension:

static async getBuiltInGitApi(): Promise<BuiltInGitApi | undefined> {
    try {
        const extension = extensions.getExtension('vscode.git') as Extension<GitExtension>;
        if (extension !== undefined) {
            const gitExtension = extension.isActive ? extension.exports : await extension.activate();

            return gitExtension.getAPI(1);
        }
    } catch {}

    return undefined;
}

这篇关于VS Code Git扩展API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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