Получить Monaco Editor CodeLens информацию о клике - PullRequest
0 голосов
/ 05 мая 2018

Используя этот пример поставщика CodeLens в качестве отправной точки, я пытался выяснить, как получить информацию о диапазоне, связанную с CodeLens, при нажатии на ссылку.

var commandId = editor.addCommand(0, function() {
    // services available in `ctx`
    alert('my command is executing!');

}, '');

monaco.languages.registerCodeLensProvider('json', {
    provideCodeLenses: function(model, token) {
        return [
            {
                range: {
                    startLineNumber: 1,
                    startColumn: 1,
                    endLineNumber: 2,
                    endColumn: 1
                },
                id: "First Line",
                command: {
                    id: commandId,
                    title: "First Line"
                }
            }
        ];
    },
    resolveCodeLens: function(model, codeLens, token) {
        return codeLens;
    }
});

Я не уверен, к чему относится комментарий ctx. Я попытался добавить это как параметр к этому параметру анонимной функции в addCommand, но у меня ничего нет. Можно ли вообще получить информацию о диапазоне, указанную в функции provideCodeLenses?

1 Ответ

0 голосов
/ 10 мая 2018

Чтобы исправить это, я добавил свойство arguments к свойству command возвращаемого объекта в provideCodeLenses:

provideCodeLenses: function(model, token) {
    return [
        {
            range: {
                startLineNumber: 1,
                startColumn: 1,
                endLineNumber: 2,
                endColumn: 1
            },
            id: "First Line",
            command: {
                id: commandId,
                title: "First Line",
                arguments: { from: 1, to: 2 },
            }
        }
    ];
}

Затем можно получить доступ в анонимной функции addCommand:

var commandId = editor.addCommand(0, function(ctx, args) {
    console.log(args); // { from: 1, to: 2 }
}, '');
...