gpt4 book ai didi

visual-studio-code - VS Code 扩展可以从其他程序获取 URI 请求吗?

转载 作者:行者123 更新时间:2023-12-04 01:45:32 28 4
gpt4 key购买 nike

我在官方文档上找到了onUri可以作为激活事件的信息。因此,可以通过调用 URI(例如 vscode://myextension/arg1=foo&arg2=bar)从用 C# 编写的 WPF 程序激活我的扩展程序。但它没有说明如何获取随 URI 请求传递的参数。或者甚至只是获取它的原始字符串。

我的问题是,是否可以这样做,如果不能,是否有任何其他方法可以使 VS Code 扩展与另一个程序交互?

最佳答案

是的,您可以使用 vscode.window.registerUriHandler()为此:

Registers a uri handler capable of handling system-wide uris. In case there are multiple windows open, the topmost window will handle the uri. A uri handler is scoped to the extension it is contributed from; it will only be able to handle uris which are directed to the extension itself. A uri must respect the following rules:

  • The uri-scheme must be the product name;

  • The uri-authority must be the extension id (eg. my.extension);

  • The uri-path, -query and -fragment parts are arbitrary. For example, if the my.extension extension registers a uri handler, it will only be allowed to handle uris with the prefix product-name://my.extension.

An extension can only register a single uri handler in its entire activation lifetime.

  • Note: There is an activation event onUri that fires when a uri directed for the current extension is about to be handled.

用法很简单:

vscode.window.registerUriHandler({
handleUri(uri:vscode.Uri) {
// do something with the URI
}
});

关于visual-studio-code - VS Code 扩展可以从其他程序获取 URI 请求吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55434556/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com