-
Notifications
You must be signed in to change notification settings - Fork 328
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
Changes for supporting resource level operations #295
Conversation
Thanks a lot for the proposal. When creating a new file shouldn't we provide an option for the content. I would ensure that we can create a file with a predefined content. Since stuff is async we couldn't otherwise. And do we need to change something for the response to provide better error information. For example a file couldn't be created? |
_resourceChanges_ | ||
|
||
A workspace edit can optionally provide resource changes. If present resource changes are applied before the `changes/documentChanges` has been applied | ||
allowing the `change/documentChanges` to work on affected files. The changes are applied in the order that they are supplied. |
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.
This changes/documentChanges
confused me as it made it seem like a notification or a request (like a textDocument/didOpen
). Perhaps it might be better to spell it out specifically with "changes
or documentChanges
" instead?
export interface ResourceChange{ | ||
|
||
/** | ||
* The resource change operation type |
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.
Period at the end?
* The resource. | ||
* | ||
* If change type is CREATE a new file is created on the uri. | ||
* This operation will not overwrite any existing resources and will fail. |
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.
I think this needs to be cleared up to state that the operation will fail if the path conflicts with an existing resource.
* This operation will not overwrite any existing resources and will fail. | ||
* | ||
* If change type is DELETE the resource is deleted if it exists. If the | ||
* uri is a folder this operation deletes all its children. |
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.
Is it considered a success or a failure if you try to delete a file or folder that does not exist?
* The new uri for the resource pointed by path. | ||
* Required only if change type is MOVE. Must be compatible with the path | ||
* uri ie. must be a file uri if path is a file uri. | ||
* |
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.
Unnecessary extra space.
export interface ResourceChange{ | ||
|
||
/** | ||
* The resource change operation type |
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.
See above.
* The resource. | ||
* | ||
* If change type is CREATE a new file is created on the uri. | ||
* This operation will not overwrite any existing resources on this uri. |
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.
See above.
* This operation will not overwrite any existing resources on this uri. | ||
* | ||
* If change type is DELETE the resource is deleted if it exists. If the | ||
* uri is a folder this operation deletes all its children. |
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.
See above.
* The new uri for the resource pointed by path. | ||
* Required only if change type is MOVE. Must be compatible with the path | ||
* uri ie. must be a file uri if path is a file uri. | ||
* |
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.
See above.
workspace: { | ||
workspaceEdit?: { | ||
/** | ||
* The client supports resource changes in `WorkspaceEdit`s |
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.
Need a period at the end.
|
||
_Client Capabilities_: | ||
|
||
The client sets the following capability if it is supporting resource Changes. |
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.
Is there a particular reason as to why "Changes" is capitalized?
/** | ||
* A resource change type | ||
*/ | ||
export declare namespace ResourceChangeType{ |
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.
Same as above.
* ------------------------------------------------------------------------------------------ */ | ||
'use strict' | ||
|
||
export interface ResourceChange{ |
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.
Same as above.
/** | ||
* A resource change type | ||
*/ | ||
export declare namespace ResourceChangeType{ |
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.
Should add a space after ResourceChangeType to be consistent with the other files.
Changes to a folder or file on the workspace. | ||
|
||
```ts | ||
export interface ResourceChange{ |
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.
Should add a space after ResourceChange to be consistent with the other files.
```ts | ||
interface WorkspaceEdit{ | ||
|
||
resourceChanges?: ResourceChange[] |
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.
Since we talk about changes
and documentChanges
in a WorkspaceEdit
, would it be better to also list those properties again here? I'm not sure what would be best since we're extending the interface here (by adding optional properties) without actually creating a new interface. Thoughts, @dbaeumer?
allowing the `change/documentChanges` to work on affected files. The changes are applied in the order that they are supplied. | ||
|
||
```ts | ||
interface WorkspaceEdit{ |
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.
Should add a space after WorkspaceEdit to be consistent with the other files.
@dbaeumer I thought the initial content could be provided via |
d8bc061
to
9f6df8f
Compare
Thanks @rcjsuen very helpful review. I think I have addressed most of them. |
@dbaeumer On error information with the response: I think we need to address that on |
9f6df8f
to
a85d858
Compare
Updated the proposed |
@gorkem @rcjsuen thanks again for providing this. Please note that VS Code 1.20 will not ship with a resource change API due to problems we discovered with the API during the test pass (see the corresponding vscode issue). We discussed in detail the order issue and it is our belief that we need one array describing all changes to make the behavior correct. For the LSP I would do the following: if resource changes are supported the workspace edit result has a property resourceChanges which are either a rename, move, delete or content change. |
a85d858
to
e790be9
Compare
@dbaeumer did a small change to allow ordered |
The type
is hard to realize in Java because both ResourceChange and TextDocumentEdit are objects, so the only way to create the correct class instance is to look ahead in the JSON token stream, which means we cannot use the default stream parsing approach of the Gson library. See eclipse-lsp4j/lsp4j#173. I'd propose to split this:
|
@gorkem regarding: #295 (comment). I think that is not a good idea (e.g. assuming that resource changes are applied before text edits). This would mean it is harder to express to modify the content of a file and then move. The statement should be that at the edits should be one array (but we need to address @spoenemann concern) and that they are executed in order in which they are provided. |
@dbaeumer I am not sure if there is a great benefit of having a single ordered list of resource changes and text edits. A WorkspaceEdit is essentially a single unit and it should be fully applied or failed. I think the proposed two arrays is equivalent to having a single array. |
The case is you create a file and then afterwards want to edit its content. |
The original proposal was to execute the resource changes before |
Agree that this would work as well. But why making it more complicated to explain to end users. Having one array which is executed from 0..n is pretty simple to explain. I agree it needs more work on the implementation side. |
An alternative solution for the Java problem would be to let ResourceChange extend
|
...or simply redeclare the properties of TextDocumentEdit as optional in ResourceChange. |
Add resourceChanges to WorkspaceEditor to allow manipulation of files and folders.
Let's give this another try; uploaded a new change. Now |
I see the problem with mapping JSON to Java however the current proposal requires IMO a lot of documentation since it is not obvious what it does. Problems I see:
Would a type attribute on the resource chnage help the Java library to implement the right switch early instead if having to check properties ? |
But then we would still need to parse the type attribute before we can decide which class instance to create? To be clear: parsing based on attributes / properties is possible also in Java / LSP4J, it just increases the effort for implementing such a parser and is slower at runtime. If the best solution in terms of LSP data structure design requires this, we'll manage to implement it, but it would be good to avoid it if there are acceptable alternatives for the data structure design. |
@spoenemann thanks for the clarification. |
Since this has stalled a bit because I got new responsibilities, @tsmaeder will be taking over this PR, so stay tuned |
@dbaeumer @gorkem @tsmaeder I found a solution for parsing object type alternatives in eclipse-lsp4j/lsp4j#230 that is acceptable in terms of additional required code for each such case. From the perspective of LSP4J, we can leave the original declaration
as it is, since we can now parse it correctly. |
@spoenemann thanks |
Closing PR. Resource edit support is available in latest next releases. |
LSP proposal that adds resourceChanges to WorkspaceEditor to allow manipulation of files and folders. This pull request only includes the proposed changes. It is not possible to implement these changes for vscode due to lack of APIs. This PR addresses microsoft/language-server-protocol#272