Skip to content
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

Services (Commands, Workspace) implementations for the standalone editor #12

Closed
rcjsuen opened this issue Jul 23, 2017 · 5 comments
Closed

Comments

@rcjsuen
Copy link
Collaborator

rcjsuen commented Jul 23, 2017

Ignoring the fact that textDocument/codeActions doesn't seem to be working for me (#11), I can't find any references to the workspace/executeCommand request in the code. Is this supported?

@akosyakov
Copy link
Contributor

One should subclass MonacoWorkspace and implement applyEdit.

If you use only one editor, you can pass your editor to your subclass and apply changes directly.

@rcjsuen
Copy link
Collaborator Author

rcjsuen commented Jul 24, 2017

It seems like the commands that a server exposes aren't getting registered with the command registry. Every command that the server exposes in the capabilities.executeCommandProvider.commands array should be registered on the client with a callback to send a workspace/executeCommand request to the server.

simpleServices.ts:246 Error: command 'docker.command.convertToUppercase' not found
    at StandaloneCommandService.executeCommand (simpleServices.ts:299)
    at Action._actionCallback (quickFixWidget.ts:41)
    at Action.run (actions.ts:213)
    at ActionRunner.runAction (actions.ts:242)
    at ActionRunner.run (actions.ts:234)
    at ActionItem.BaseActionItem.onClick (actionbar.ts:165)
    at actionbar.ts:144
```

@akosyakov
Copy link
Contributor

You should implement Commands interface and provide it as part of service to the language client.

@akosyakov akosyakov changed the title workspace/executeCommand doesn't seem to be supported Provide a simple Commands implementation Jul 24, 2017
@akosyakov akosyakov changed the title Provide a simple Commands implementation Provide a standalone Commands implementation Jul 24, 2017
@akosyakov
Copy link
Contributor

akosyakov commented Jul 24, 2017

We should have Commands and Workspace implementations for a standalone editor which accept a standalone editor and register commands or apply changes on it.

@akosyakov akosyakov changed the title Provide a standalone Commands implementation Commands and Workspace implementations for the standalone editor Jul 24, 2017
@akosyakov akosyakov changed the title Commands and Workspace implementations for the standalone editor Services (Commands, Workspace) implementations for the standalone editor Jul 24, 2017
@gatesn
Copy link
Collaborator

gatesn commented Aug 10, 2017

In fact, because Monaco modifies the command ID, the MonacoLanguages class also needs to take an editor instance and prefix the command IDs with the editor ID:

https://github.com/Microsoft/vscode/blob/875144b25bf95197aff9ed0a8229ae322701bdd1/src/vs/editor/standalone/browser/standaloneCodeEditor.ts#L170

e.g.

    protected createCodeActionProvider(selector: DocumentSelector, provider: CodeActionProvider): monaco.languages.CodeActionProvider {
        return {
            provideCodeActions: (model, range, context, token) => {
                if (!this.matchModel(selector, MonacoModelIdentifier.fromModel(model))) {
                    return [];
                }
                const params = this.m2p.asCodeActionParams(model, range, context);
                return provider.provideCodeActions(params, token).then(
                    (result: Command[]) => this.p2m.asCodeActions(result)
                ).then((codeActions: monaco.languages.CodeAction[]) => codeActions.map(codeAction => {
                    codeAction.command['id'] = this._editor.getId() + ':' + codeAction.command.id
                    return codeAction;
                }))
            }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants