cursor plugin develop

Hello, I am developing a vscode plug-in. The basic function of this plug-in is to automatically call the cursor’s chat, and then automatically trigger the cursor’s submit button according to the prompt assembled in the background, and then obtain the cursor’s output.

At present, during the development process, I cannot obtain the chat window editor corresponding to the cursor through composer.openChatAsEditor, which makes it impossible for me to automatically input the prompt. Is there any solution to this problem?

my code:

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {
    // 创建一个自定义日志通道
    const outputChannel = vscode.window.createOutputChannel('c2d2reval');
    outputChannel.appendLine('插件已激活!');

    const disposable = vscode.commands.registerCommand('c2d2reval.chat', async () => {
        // 触发 Cursor AI 聊天窗口
        await vscode.commands.executeCommand('composer.openChatAsEditor');

        // 等待并监听编辑器切换事件
        vscode.window.onDidChangeActiveTextEditor((editor) => {
            if (editor) {
                console.log('检测到活动编辑器变化');
                // 输出编辑器相关信息,帮助确认是期望的编辑器
                console.log(`活动编辑器URI: ${editor.document.uri.toString()}`);
                console.log(`编辑器文件名: ${editor.document.fileName}`);

                // 假设期望的编辑器文件名包含某个特定的标识符
                if (editor.document.fileName.includes('chat')) {
                    outputChannel.appendLine('检测到聊天框编辑器!');
                    // 获取光标位置并插入prompt文本
                    const position = editor.selection.active;  // 获取当前光标位置
                    const prompt = '这是你要输入的prompt文本'; // 替换为您实际的prompt
                    editor.edit(editBuilder => {
                        // 在光标处插入文本
                        editBuilder.insert(position, prompt);
                    });
                    console.log(`已在光标位置输入: ${prompt}`);
                    outputChannel.show(true); // 强制显示日志通道
                } else {
                    outputChannel.appendLine('活动编辑器不是聊天框编辑器');
                    console.log('活动编辑器不是聊天框编辑器');
                }
            }
        });
    });

    context.subscriptions.push(disposable);
}

export function deactivate() {}

1 Like

Hey @yulinniuzhi !
it’s really interesting, have you got this to work ?

I have some questions my self :slight_smile:
[email protected]