Skip to content

Provide support for commands - #21

Merged
akosyakov merged 1 commit into
TypeFox:masterfrom
gatesn:ngates/lsp-commands
Aug 30, 2017
Merged

Provide support for commands#21
akosyakov merged 1 commit into
TypeFox:masterfrom
gatesn:ngates/lsp-commands

Conversation

@gatesn

@gatesn gatesn commented Aug 11, 2017

Copy link
Copy Markdown
Contributor

This implements a basic applyEdit operation (more advanced ones would accept the editor and preserve / manipulate the current selections), as well as registering commands against a given editor.

Fixes #11
Fixes #12

@gatesn
gatesn force-pushed the ngates/lsp-commands branch from 2011a25 to 7471a0c Compare August 11, 2017 13:30
@gatesn

gatesn commented Aug 11, 2017

Copy link
Copy Markdown
Contributor Author

Actually, having looked at that disgusting applyEdit function, we should iterate over the changes and then apply them all in bulk. Otherwise the undo stack looks a bit odd.

@akosyakov akosyakov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into it. Please see comments.

Most important to have a proof that it is working, e.g. with the JSON example server. Please add a command that does workspace edits to demonstrate it.

Comment thread src/workspace.ts Outdated

public applyEdit(workspaceEdit: WorkspaceEdit): Thenable<boolean> {
let applied = true;
if (workspaceEdit.documentChanges) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use asWorkspaceEdit, applying documentChanges is not enough

Comment thread src/workspace.ts Outdated
return this.onDidChangeTextDocumentEmitter.event;
}

public applyEdit(workspaceEdit: WorkspaceEdit): Thenable<boolean> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please return Promise

Comment thread src/workspace.ts Outdated
let applied = true;
if (workspaceEdit.documentChanges) {
for (const change of workspaceEdit.documentChanges) {
if (change.textDocument.version && change.textDocument.version >= 0) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these checks necessary?

Comment thread src/workspace.ts Outdated
applied = false;
}
} else {
applied = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not the whole change should be applied or rejected? It seems that changes can be applied partially by this method.

Comment thread src/workspace.ts Outdated
if (change.textDocument.version && change.textDocument.version >= 0) {
const textDocument = this.documents.get(change.textDocument.uri);
if (textDocument && textDocument.version === change.textDocument.version) {
monaco.editor.getModel(monaco.Uri.parse(textDocument.uri)).pushEditOperations(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not you check that the model is defined?

Comment thread src/commands.ts Outdated

export class MonacoCommands implements Commands {

public constructor(private _editor: monaco.editor.IStandaloneCodeEditor) { }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protected readonly editor

Comment thread src/commands.ts Outdated
public constructor(private _editor: monaco.editor.IStandaloneCodeEditor) { }

public registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): Disposable {
return (this._editor as any)._commandService.addCommand(command, {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please introduce augmenting typings for internals instead of using any

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain what you mean here? Not sure I'm familiar with this technique.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that you should add d.ts. file that augments monaco module add exposes _commandService, look at https://github.com/theia-ide/theia/blob/master/packages/monaco/src/typings/monaco/index.d.ts.

Comment thread src/commands.ts Outdated
public registerCommand(command: string, callback: (...args: any[]) => any, thisArg?: any): Disposable {
return (this._editor as any)._commandService.addCommand(command, {
handler: (id: string, ...args: any[]) => {
console.log("Executing command", command, id, args);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't it pollute console?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, left in from testing!

Comment thread src/workspace.ts Outdated
} else {
applied = false;
}
return Promise.resolve(applied);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use high-level functions as reduce to get rid of if-else cascade?

@gatesn
gatesn force-pushed the ngates/lsp-commands branch from 7471a0c to 47cc839 Compare August 11, 2017 14:44
@gatesn

gatesn commented Aug 11, 2017

Copy link
Copy Markdown
Contributor Author

I've made the changes but not written an example. Any ideas on what to use as an example?!

@akosyakov

Copy link
Copy Markdown
Contributor

@gatesn the same here please use rebase instead of merge

@akosyakov

Copy link
Copy Markdown
Contributor

I like changes but there should be a proof that it is working: tests or use of it in the example.

What if the JSON server provides:

  • a command that converts a property name at the position to the lower via applyEdit
  • some way to trigger it for example via the code action

It should not be sophisticated, but only demonstrate that everything works together.

@gatesn
gatesn force-pushed the ngates/lsp-commands branch 2 times, most recently from 5800486 to 6679516 Compare August 27, 2017 21:47
@gatesn

gatesn commented Aug 27, 2017

Copy link
Copy Markdown
Contributor Author

@akosyakov I created an example that provides a code action for any document in all positions. This action triggers a server-side command that upper cases the entire document.

@gatesn
gatesn force-pushed the ngates/lsp-commands branch 2 times, most recently from 1573c3d to fad66e0 Compare August 28, 2017 14:56
@akosyakov

Copy link
Copy Markdown
Contributor

@gatesn I've tested this PR and it works nicely, thank you! I've opened a new PR against your, please merge it and after that, I will approve this PR.

Next time you can work in the branch directly in this repo since you have the write access instead of working on the fork. It makes easy to push new commits to PRs.

…age server

Signed-off-by: Nicholas Gates <ngates@palantir.com>
@gatesn
gatesn force-pushed the ngates/lsp-commands branch from 4e2162c to 0cd9823 Compare August 29, 2017 15:32
@gatesn

gatesn commented Aug 29, 2017

Copy link
Copy Markdown
Contributor Author

@akosyakov merged your changes, thanks

@gatesn

gatesn commented Aug 29, 2017

Copy link
Copy Markdown
Contributor Author

Do you think we could cut a release after this merges?

@akosyakov
akosyakov merged commit efe943c into TypeFox:master Aug 30, 2017
@akosyakov

Copy link
Copy Markdown
Contributor

@gatesn LGTM, thank you again!

@akosyakov

Copy link
Copy Markdown
Contributor

Do you think we could cut a release after this merges?

yes, we can make a release. Should we migrate to monaco 0.10.0 before the release?

@akosyakov

Copy link
Copy Markdown
Contributor

btw i wonder why github cannot recognize your account as an author, see: https://github.com/TypeFox/monaco-languageclient/commits/master

@gatesn

gatesn commented Aug 30, 2017

Copy link
Copy Markdown
Contributor Author

Probably no 0.10.0 given the breaking changes around Code actions. We might need to investigate to see what that means.

@gatesn

gatesn commented Aug 30, 2017

Copy link
Copy Markdown
Contributor Author

And it seems my git setup is different on different laptop :/

@akosyakov

Copy link
Copy Markdown
Contributor

@gatesn 0.2.0 is published with 0.10.0 Monaco support thanks to @rcjsuen

rcjsuen added a commit to rcjsuen/monaco-languageclient that referenced this pull request Feb 11, 2018
Pull request TypeFox#21 added support for the workspace/applyEdit capability
so it should be stated as such in the WorkspaceClientCapabilities.

Signed-off-by: Remy Suen <remy.suen@gmail.com>
rcjsuen added a commit to rcjsuen/monaco-languageclient that referenced this pull request Feb 12, 2018
Pull request TypeFox#21 added support for the workspace/applyEdit capability
so it should be stated as such in the WorkspaceClientCapabilities.

Signed-off-by: Remy Suen <remy.suen@gmail.com>
rcjsuen added a commit that referenced this pull request Feb 12, 2018
Pull request #21 added support for the workspace/applyEdit capability
so it should be stated as such in the WorkspaceClientCapabilities.

Signed-off-by: Remy Suen <remy.suen@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants