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

WorkspaceEdit is incompatible with the protocol #173

Closed
KalitaAlexey opened this issue Feb 22, 2017 · 11 comments
Closed

WorkspaceEdit is incompatible with the protocol #173

KalitaAlexey opened this issue Feb 22, 2017 · 11 comments

Comments

@KalitaAlexey
Copy link

KalitaAlexey commented Feb 22, 2017

https://github.com/Microsoft/vscode-languageserver-node/blob/master/types/src/main.ts#L366

export interface WorkspaceEdit {
	changes: TextDocumentEdit[];
}

In the protocol it described as follows:

interface WorkspaceEdit {
    /**
     * Holds changes to existing resources.
     */
    changes: { [uri: DocumentUri]: TextEdit[]; };
}

Also asWorkspaceEdit is wrong.

This is cause of the problem in my extension.

It worked on "vscode-languageclient": "^2.6.3", but it doesn't on "vscode-languageclient": "3.0.4".

@gorkem
Copy link

gorkem commented Feb 24, 2017

@dbaeumer 73d3500 seems to have broken the asWorkspaceEdit. This is now a blocker for redhat-developer/vscode-java#99 since we can not move to the 3.x version of the library.

@dbaeumer
Copy link
Member

@gorkem I will have a look. I know that we discussed this but I need to refresh my memory.

@dbaeumer
Copy link
Member

Reading through the code I remember why we changed this for the 3.0 version of the protocol. The reason was that the old WorkspaceEdit was a map from URI to edit. The problem was that this didn't allow to specify on which version of a document an edit is applicable. This is why we changed this from a map to an array where the TextDocumentEdit contains a textDocument property pointing to a VersionedTextDocumentIdentifier.

I know this is breaking but to support proper version checking when applying text edits this was the best way to go forward. Now users of the protocol have to think about this.

So bottom line is that the spec is incorrect. I will fix this. Would you be able to adopt this?

@gorkem
Copy link

gorkem commented Feb 28, 2017

I am concerned that this will break all the existing implementations, not all clients are able to move as quick. I think we need a migration path on this. Perhaps we can leave the changes as a deprecated field and use something like edits for the TextDocumentEdit.

I think we should consider microsoft/language-server-protocol#41 before making changes to WorkspaceEditon the protocol.

The chaps on LSP4J @svenefftinge or @akosyakov can tell how quickly they can respond to such changes. It is pretty quick for jdt.ls once LSP4J has a build with adopting changes

@dbaeumer
Copy link
Member

I updated the documentation / spec of the protocol.

@dbaeumer
Copy link
Member

The old clients is a fair argument. Addressing this should be done like all the new features in 3.0.x. We should have a client capability property specifying which type of work space edit the client expects together. If the new format is not supported by the client then we should return the old structure. I missed this for this change but did it for all new features for 3.0.x. Don't know why I forgot it here. Will look into this this week.

@dbaeumer
Copy link
Member

dbaeumer commented Feb 28, 2017

What I will do is the following. I will declare WorkspaceEdit as follows:

/**
 * A workspace edit represents changes to many resources managed in the workspace. The edit
 * should either provide `changes` or `documentChanges`. If documentChanges are present
 * they are preferred over `changes` if the client can handle versioned document edits.
 */
export interface WorkspaceEdit {
	/**
	 * Holds changes to existing resources.
	 */
	changes?: { [uri: string]: TextEdit[]; };

	/**
	 * An array of `TextDocumentEdit`s to express changes to specific a specific
	 * version of a text document. Whether a client supports versioned document
	 * edits is expressed via `WorkspaceClientCapabilites.versionedWorkspaceEdit`.
	 */
	documentChanges?: TextDocumentEdit[];
}

and add a ClientCapability:

	versionedWorkspaceEdit?: boolean;

If set the by the client the server is allowed to send TextDocumentEdit arrays in the property documentChanges.

@dbaeumer
Copy link
Member

The correct client capability will look like:

export interface WorkspaceClientCapabilites {
        ...
	/**
	 * Capabilities specific to `WorkspaceEdit`s
	 */
	workspaceEdit?: {
		/**
		 * The client supports versioned document changes in `WorkspaceEdit`s
		 */
		documentChanges?: boolean;
	};
        ...
}

@dbaeumer
Copy link
Member

A fix is available on release/3.2.0-alpha.1. Need to review tomorrow and then deliver a next release.

@akosyakov
Copy link
Contributor

akosyakov commented Mar 1, 2017

@gorkem lsp4j is updated according to changes in the protocol: eclipse-lsp4j/lsp4j@46b8d7a

@dbaeumer
Copy link
Member

dbaeumer commented Mar 1, 2017

I pushed a 3.2.0-alpha.x version to npm under the next tag in case you want to give it a try.

@vscodebot vscodebot bot locked and limited conversation to collaborators Nov 21, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants