microsoft / microsoft/monaco-editor
Provider APIs and addCommand don't work well together
Open
@alexdima is already working on this.
Since Nov 14, 2017.
debt
editor-api
- Dominant language
- JavaScript
- Stars
- 46.8k
- Forks
- 4.1k
- Avg merge
- 17h 58m
- Merged PRs (30d)
- 1
Description
monaco-editor version: 0.10.1
Providers are registered globally on monaco.languages. However, editor.addCommand returns a commandId that is unique and only applies to one editor. This means if you have multiple editors, they'll all be affected by a provider, but this provider can't work adequately. For example:
const commandHandler = () => { /* whatever */ };
const commandId0 = editor0.addCommand(0, commandHandler, "");
const commandId1 = editor1.addCommand(0, commandHandler, "");
export const codeLensProvider: monaco.languages.CodeLensProvider = {
provideCodeLenses: (model, cancelToken) => ([
{
range: someRange,
command: {
id: "???" // which commandId should we use?
title: "A Command",
arguments: [],
}
}
])
};
monaco.languages.registerCodeLensProvider("*", codeLensProvider);
The easiest solution here is likely to allow addCommand to take an optional id?: string which could be used as the id.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.