Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/visual-studio-code/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript VS代码-内部扩展命令调用_Typescript_Visual Studio Code_Vscode Extensions - Fatal编程技术网

Typescript VS代码-内部扩展命令调用

Typescript VS代码-内部扩展命令调用,typescript,visual-studio-code,vscode-extensions,Typescript,Visual Studio Code,Vscode Extensions,我正在开发一个VS代码扩展,它可以自动配置许多项 阅读此链接后,我不清楚的是: 是在我的TypeScript代码中调用同一扩展名内的另一个命令的正确方法 例如,点击CTRL+Shift+p,激活并运行我的主要面向用户的命令,它通过适当的逻辑运行,等等 // The module 'vscode' contains the VS Code extensibility API // Import the module and reference it with the alias vscode i

我正在开发一个VS代码扩展,它可以自动配置许多项

阅读此链接后,我不清楚的是:

是在我的TypeScript代码中调用同一扩展名内的另一个命令的正确方法

例如,点击CTRL+Shift+p,激活并运行我的主要面向用户的命令,它通过适当的逻辑运行,等等

// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import fs = require('fs');
import path = require('path');
const ini = require('ini');

export function activate(context: vscode.ExtensionContext) {

    // install check name to match package.json
    const myCommand = 'extension.myCommandName';

    // command handler
    const myCommandHandler = async (name?: 'MyCommand: Do Things') => {
        // Check if a local path exists
        function checkDirectorySync(directory: fs.PathLike) {
            try {
                fs.statSync(directory);
                return true;
            } catch (e) {
                return false;
            }
        }

        let isDirectoryValid = checkDirectorySync('C:\\Users\myusername\someFolder');

        // now call another command to launch an input box
        if (isDirectoryValid === false) {
            var secondCommand = vscode.extensions.getExtension('extension.MyOtherCommand');
            // is the ext loaded and ready?
            if (secondCommand.isActive == false) {
                secondCommand.activate().then(
                    function () {
                        console.log("Extension activated");
                        vscode.extensions.findCommand();
                        vscode.commands.executeCommand("extension.MyOtherCommand");
                    },
                    function () {
                        console.log("Extension activation failed");
                    }
                );
            } else {
                vscode.commands.executeCommand("extension.MyOtherCommand");
            }
        }
    };

    // push directory check command to command registry
    context.subscriptions.push(vscode.commands.registerCommand(myCommand, myCommandHandler));
}

// this method is called when your extension is deactivated
export function deactivate() { }
只是想通过这个简单的例子来了解这是否是正确的方法。另一个帖子似乎有点让人困惑


非常感谢任何快速建议

另一篇文章有什么让人困惑的地方?您的代码有什么问题(或者工作正常吗)?在不调用其他命令的情况下,我的代码运行正常。在浏览显示输入框的示例时,MS示例似乎在
window.showInputBox()
构建方法周围使用了一个包装类,该方法添加了一些示例扩展性。我意识到我可能必须使用他们的示例包装器,并根据我的需要对其进行定制。看起来,如果我将该功能包装到一个独立的命令中,我应该能够在我的“master”命令中调用它。只是需要挖掘大量的API代码through@Gama11另一个令人困惑的部分是,另一篇文章显示了调用.xml文件作为扩展名。我不知道该对象是如何获得其
.isActive
属性的?也许您应该查看API文档中
getExtension()
的功能-该代码不“调用.xml文件”。为此干杯。我得用几种不同的方法来解决这个问题。感谢你的指点:另一篇文章有什么让人困惑的地方?您的代码有什么问题(或者工作正常吗)?在不调用其他命令的情况下,我的代码运行正常。在浏览显示输入框的示例时,MS示例似乎在
window.showInputBox()
构建方法周围使用了一个包装类,该方法添加了一些示例扩展性。我意识到我可能必须使用他们的示例包装器,并根据我的需要对其进行定制。看起来,如果我将该功能包装到一个独立的命令中,我应该能够在我的“master”命令中调用它。只是需要挖掘大量的API代码through@Gama11另一个令人困惑的部分是,另一篇文章显示了调用.xml文件作为扩展名。我不知道该对象是如何获得其
.isActive
属性的?也许您应该查看API文档中
getExtension()
的功能-该代码不“调用.xml文件”。为此干杯。我得用几种不同的方法来解决这个问题。欣赏指针