atom-community / atom-languageclient

Provide integration support for adding Language Server Protocol servers to Atom.
https://www.npmjs.com/package/atom-languageclient
MIT License
45 stars 13 forks source link

feat: support resource operations #140

Closed cdaguerre closed 3 years ago

cdaguerre commented 3 years ago

This is my first experience with typescript, feedback much appreciated ;)

UziTech commented 3 years ago

Can you give some explanation of why this is needed? Examples of what this enables that doesn't currently work?

cdaguerre commented 3 years ago

@UziTech Sure!

This enables resource operations (basically file and directory operations) as part of workspaceEdits, which is currently not implemented at all. I came across this while working on the rename functionality for the ide-intelephense package. If this PR makes it, i'll open another one to improve the rename functionality aswell (which to my understanding doesn't work at all right now).

From https://microsoft.github.io/language-server-protocol/specification#workspaceEdit:

Since version 3.13.0 a workspace edit can contain resource operations (create, delete or rename files and folders) as well. If resource operations are present clients need to execute the operations in the order in which they are provided. So a workspace edit for example can consist of the following two changes: (1) create file a.txt and (2) a text document edit which insert text into file a.txt. And:


export interface WorkspaceEdit {
/**
* Holds changes to existing resources.
*/
changes?: { [uri: DocumentUri]: TextEdit[]; };
/**
 * Depending on the client capability
 * `workspace.workspaceEdit.resourceOperations` document changes are either
 * an array of `TextDocumentEdit`s to express changes to n different text
 * documents where each text document edit addresses a specific version of
 * a text document. Or it can contain above `TextDocumentEdit`s mixed with
 * create, rename and delete file / folder operations.
 *
 * Whether a client supports versioned document edits is expressed via
 * `workspace.workspaceEdit.documentChanges` client capability.
 *
 * If a client neither supports `documentChanges` nor
 * `workspace.workspaceEdit.resourceOperations` then only plain `TextEdit`s
 * using the `changes` property are supported.
 */
documentChanges?: (
    TextDocumentEdit[] |
    (TextDocumentEdit | CreateFile | RenameFile | DeleteFile)[]
);

/**
 * A map of change annotations that can be referenced in
 * `AnnotatedTextEdit`s or create, rename and delete file / folder
 * operations.
 *
 * Whether clients honor this property depends on the client capability
 * `workspace.changeAnnotationSupport`.
 *
 * @since 3.16.0
 */
changeAnnotations?: {
    [id: string /* ChangeAnnotationIdentifier */]: ChangeAnnotation;
};

}

UziTech commented 3 years ago

@aminya looks like linting is failing because of an issue with pnpm. Could you look into that?

aminya commented 3 years ago

@aminya looks like linting is failing because of an issue with pnpm. Could you look into that?

Yes, I will fix that. https://github.com/atom-community/atom-ide-hyperclick/issues/132#issuecomment-818310509

cdaguerre commented 3 years ago

@UziTech I implemented handling of resource operation options and added tests. Rollbacks of applied resource operations in case of error are not handled for now but I think it should ok for a first iteration.

aminya commented 3 years ago

@aminya looks like linting is failing because of an issue with pnpm. Could you look into that?

145 and #144 will fix the linting errors.

cdaguerre commented 3 years ago

I changed the code to use fs.stats and fixed linting/format errors. Build is green! 🎉

github-actions[bot] commented 3 years ago

:tada: This PR is included in version 1.7.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket: