小编Man*_*nta的帖子

vscode.commands.executeCommand 不起作用

我正在写VS代码扩展到帮助迁移React.createClass类扩展React.Component。这里的问题是,我无法vscode.commands.executeCommand('vscode.executeFormatDocumentProvider', ...)上班。

请注意,下面的代码是纯 JavaScript,而不是 TypeScript。

function activate(context) {
    context.subscriptions.push(vscode.commands.registerCommand('migrate-to-react-es6-class', () => {
        const editor = vscode.window.activeTextEditor
        const document = editor.document

        try {
            const originalCode = document.getText()
            const modifiedCode = 'do something and return new code'

            if (originalCode === modifiedCode) {
                vscode.window.showInformationMessage('Nothing is to be migrated.')

            } else {
                editor.edit(edit => {
                    const editingRange = document.validateRange(new vscode.Range(0, 0, Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER))
                    edit.replace(editingRange, modifiedCode)
                })

                if (document.isUntitled === false) {
                    vscode.commands.executeCommand('vscode.executeFormatDocumentProvider', document.uri, { insertSpaces: true, tabSize: 2 …
Run Code Online (Sandbox Code Playgroud)

javascript visual-studio-code vscode-extensions

5
推荐指数
1
解决办法
686
查看次数