使用这个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函数中指定的范围信息吗?
发布于 2018-05-09 23:13:18
为了解决这个问题,我在返回的对象的arguments属性中添加了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 }
}, '');https://stackoverflow.com/questions/50188534
复制相似问题