-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Register show references command under the vscode known id. #4193
Conversation
Signed-off-by: Thomas Mäder <[email protected]>
There is already Monaco command expects 1-based position/locations, while VS Code expects 0-based. I would expect that we intercept
Update: No, actually i'm wrong, i've just checked Monaco register |
It leads to the infinity loop: To test I've registered the following command in this.registry.registerCommand({
id: 'lalala',
label: 'Lalala'
}, {
execute: editor => this.registry['commands'].executeCommand(EditorCommands.SHOW_REFERENCES.id, editor.uri.toString(), editor.cursor, [])
}); An implementation of I wonder whether it is generally sustainable approach. In this case Monaco does not contribute such command to our registry, but it does contribute other 150 commands started with |
/** | ||
* Show editor references | ||
*/ | ||
export const SHOW_REFERENCES_DEPRECATED: Command = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need constants for deprecated commands? There cannot be any clients for it.
Yes, it does; I was not expecting the monaco command registry to delegate back up to the theia command registry. But the same would apply when we register the command in plugin-vscod-commands-contribution.ts, right? |
It is done to support Monaco UI features from the command palette and menu items, for instance: find references, go to definition, redo, undo, copy, paste, and etc.
I am suggesting not to register but intercept calls from plugins and delegate to core or Monaco commands. |
Generally, i have following doubts with just renaming constants:
I would rather have one place where VS Code types/commands are converted to LSP/Monaco, something like: async $executeCommand<T>(id: string, ...args: any[]): Promise<T | undefined> {
if (id === 'editor.action.showReferences') {
// HERE convert args from VS Code to LSP/Monaco types
const result = await this.delegate.executeCommand(EditorCommands.SHOW_REFERENCES, ...args);
// HERE convert result from LSP/Monaco to VS Code types
return result;
}
return this.delegate.executeCommand(id, ...args);
} It would be a minimal backward compatible change, not requiring changes of command constants, signatures or implementations. |
@akosyakov but command ids are used in many places, for example code actions, code lenses, etc, etc. We would have to filter all those locations and adjust parameters (positions, in particular) to fit the monaco commands. |
It looks like we have to. We cannot use vscode types outside of the plugin extension. For example I wonder what VS Code does, they should have exactly the same issue. |
They apply type converters for exposed commands and language features. Generically: microsoft/vscode#67649 (comment) |
Btw, I found out why the "editor.action.showReferences" command is not found: the plugin engine delegates the execution of commands to the theia command registry. However, this command is registered in the monaco command registry, so it's not found. |
Could you try to register it here https://github.com/theia-ide/theia/blob/f54fc5c67232592e71bd65d5514fdbab8e90c51f/packages/monaco/src/browser/monaco-command.ts#L60 { id: 'editor.action.showReferences', delegate: 'editor.action.showReferences' } If it does not work then you can call it directly on the editor: const editor = MonacoEditor.getCurrent(editorManager);
if (editor) {
editor.commandService.executeCommand('editor.action.showReferences', ...args);
} |
I was able to register Monaco commands as is via by passing our command registry on the command invocation here: f482171#diff-9ddba23d7cd957a1a88b40636645c22bR365 I need it to fix VS Code api tests, they use commands like I can extract a commit in a separate PR if you need it. For |
Are these changes part of a PR? |
@tsmaeder can be closed? |
Registers the show references command from monaco editor both under the old theia id and the vs code "standard" id.
It's a fix for #4084
This is untested code to illustrate what I have in mind.