如何在 vscode 上的一个扩展中调用其他扩展 [英] How to call other extensions in a extension on vscode

查看:59
本文介绍了如何在 vscode 上的一个扩展中调用其他扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的需求,我想用一些动态参数启动一个调试会话.所以我首先需要开发一个收集参数的扩展,然后向 vscode 注册一个调试器包装器,然后我必须找到一种方法来用我的参数调用目标扩展的调试器.

Here is my demand, I want to startup a debug session with some dynamic arguments. So I need to develop a extension that collect the arguments at first and register a debugger wrapper to vscode, after that I have to find a way to call the target extension's debugger with my arguments.

vscode.extensions.getExtension 可以获取扩展的信息,并且只能激活它.

vscode.extensions.getExtension can get extension's informations and be able to active it only.

我在 vscode 的源代码中发现了一个名为debug.startFromConfig"的命令,因此我可以使用 vscode.commands.executeCommand 以我自己的配置执行它.但不幸的是我不能在调试适配器上使用 vscode 的 api,因为它不是一个扩展主机,它只是一个单节点程序.

I found a command named "debug.startFromConfig" in vscode's sources, so I can use vscode.commands.executeCommand to execute it with my own configuration. But unfortunately I can't use vscode's api on a debug adapter, since it's not a extension host which just a single node programe.

以下是我所期望的,我有一个名为 asd 的调试器包装器

The follow is what I expected, I have a debugger wrapper named asd

我将用我自己的调试器覆盖一些 python 调试器的配置.(下面这些代码不起作用,我在上面解释过)

And I'm going to override some configurations of python debugger by my own debugger.(These codes following can't work, I explained that on above)

之后我可以运行我的自定义调试器来调用 python 调试器

After that I can run my custom debugger to call the python debugger

推荐答案

为什么不使用官方的 startDebugging 扩展 API?请参阅 https://https://github.com/microsoft/vscode/blob/31221e62995c7040400051c2353c3c7c8b303c16/src/vs/vscode.d.ts#L8874微软/vscode/blob/31221e62995c7040400051c2353c3c7c8b303c16/src/vs/vscode.d.ts#L8874.

Why are you not using the official startDebugging extension API? Please see https://github.com/microsoft/vscode/blob/31221e62995c7040400051c2353c3c7c8b303c16/src/vs/vscode.d.ts#L8874.

或者,您可以为您感兴趣的调试类型注册一个 DebugConfigurationProvider,并拦截resolveDebugConfiguration"方法以动态调整启动配置.请参阅 https://https://github.com/microsoft/vscode/blob/31221e62995c7040400051c2353c3c7c8b303c16/src/vs/vscode.d.ts#L8544微软/vscode/blob/31221e62995c7040400051c2353c3c7c8b303c16/src/vs/vscode.d.ts#L8544.

Alternatively you could register a DebugConfigurationProvider for the debug types you are interested in and intercept the "resolveDebugConfiguration" method in order to adapt the launch configuration dynamically. Please see https://github.com/microsoft/vscode/blob/31221e62995c7040400051c2353c3c7c8b303c16/src/vs/vscode.d.ts#L8544.

是的,vscode.d.ts 是你的朋友...

Yes, vscode.d.ts is your friend...

这篇关于如何在 vscode 上的一个扩展中调用其他扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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