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

feat(lsp): will save #8952

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Conversation

matoous
Copy link
Contributor

@matoous matoous commented Nov 30, 2023

@the-mikedavis the-mikedavis added A-language-server Area: Language server client S-waiting-on-review Status: Awaiting review from a maintainer. labels Nov 30, 2023
@pascalkuthe
Copy link
Member

This should be using the infrastructure from #8949. You need to fully respect the capabilities set and send these noticatuons to all servers. I intentionally did not implement didSaven and willSave (and all the other non-rename) operations as I wanted to wait for #8021

@matoous matoous marked this pull request as draft November 30, 2023 23:49
@the-mikedavis the-mikedavis added S-waiting-on-pr Status: This is waiting on another PR to be merged first and removed S-waiting-on-review Status: Awaiting review from a maintainer. labels Dec 1, 2023
@matoous matoous marked this pull request as ready for review February 1, 2024 22:13
@the-mikedavis the-mikedavis added S-waiting-on-review Status: Awaiting review from a maintainer. and removed S-waiting-on-pr Status: This is waiting on another PR to be merged first labels Feb 1, 2024
@matoous
Copy link
Contributor Author

matoous commented Feb 1, 2024

@pascalkuthe rebased. I don't think #8949 affects this PR as this isn't covered under the file interest.

Comment on lines 254 to 258
// DocumentSynchronization
Save,
WillSave,
Copy link
Member

Choose a reason for hiding this comment

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

these should not be manually configurable, the fact athat we crruntly don't send these is a bug and there should be no option to turn this off (its not an optional part of the spec)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I am not sure if I follow. These are not configurable but used to request only LSPs support specific features. In this case we are checking for support of TextDocumentSyncOptions under https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_didRename.

Copy link
Member

Choose a reason for hiding this comment

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

these are config options that allow users to disable/enable only certain LSP features. For convenience when also use these to check capabilities but you can check capabilities without this. You should only add something to this enum if you want the user to be able to turn an LSP feature off

Comment on lines 997 to 995
pub fn text_document_will_save_wait_until(
&self,
text_document: lsp::TextDocumentIdentifier,
) -> Option<impl Future<Output = Result<Vec<lsp::TextEdit>>>> {
let request =
self.call::<lsp::request::WillSaveWaitUntil>(lsp::WillSaveTextDocumentParams {
text_document,
reason: TextDocumentSaveReason::MANUAL,
});

Some(async move {
let json = request.await?;
let response: Option<Vec<TextEdit>> = serde_json::from_value(json)?;
Ok(response.unwrap_or_default())
})
}
Copy link
Member

Choose a reason for hiding this comment

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

this should have a 1s timeout simiar to willrename

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use 5s there, added the same here and extracted it into static DOCUMENT_OPS_TIMEOUT. I don't think it's worth it adding to config but having the same timeouts on all document-related calls seems sensible.

Comment on lines +1045 to +1030
// -------------------------------------------------------------------------------------------
// Language features
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#languageFeatures
// -------------------------------------------------------------------------------------------
Copy link
Member

Choose a reason for hiding this comment

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

this seems unrelated

@@ -870,6 +870,31 @@ impl Document {
// We encode the file according to the `Document`'s encoding.
let future = async move {
use tokio::{fs, fs::File};

if let Some(identifier) = &identifier {
Copy link
Member

Choose a reason for hiding this comment

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

this should definitly4 be handeled by the even t system and what I meant with my previous comments. We essentially want to keep LSP out of the main code and move it all behind events. So there should be a willsave event here and the lsp stuff should be moved to a hook. Same with didsave

helix-view/src/document.rs Outdated Show resolved Hide resolved
helix-view/src/document.rs Outdated Show resolved Hide resolved
@matoous matoous force-pushed the md/lsp-will-save branch 2 times, most recently from cf558bf to acf9986 Compare February 4, 2024 09:55
@pascalkuthe pascalkuthe added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from a maintainer. labels Apr 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-language-server Area: Language server client S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants