Skip to content

chore(pglt_lsp): add lifecycle test #214

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

Merged
merged 2 commits into from
Feb 21, 2025
Merged

Conversation

psteinroe
Copy link
Collaborator

adds a basic lifecycle test to the lsp server. will expand on it later. maybe we can even have a "recording" of the users actions via logs, parse these recordings and replay them.

Copy link
Collaborator

@juleswritescode juleswritescode left a comment

Choose a reason for hiding this comment

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

Just suggestions/nits 👍👍

Comment on lines 23 to 31
use tower_lsp::lsp_types::DidCloseTextDocumentParams;
use tower_lsp::lsp_types::DidOpenTextDocumentParams;
use tower_lsp::lsp_types::InitializeResult;
use tower_lsp::lsp_types::InitializedParams;
use tower_lsp::lsp_types::PublishDiagnosticsParams;
use tower_lsp::lsp_types::TextDocumentContentChangeEvent;
use tower_lsp::lsp_types::TextDocumentIdentifier;
use tower_lsp::lsp_types::TextDocumentItem;
use tower_lsp::lsp_types::VersionedTextDocumentIdentifier;
Copy link
Collaborator

Choose a reason for hiding this comment

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

the use statements look a bit odd? something wrong with your nvim config?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

copy-pasta 😂 fixed it

Comment on lines +41 to +49
macro_rules! url {
($path:literal) => {
if cfg!(windows) {
lsp::Url::parse(concat!("file:///z%3A/workspace/", $path)).unwrap()
} else {
lsp::Url::parse(concat!("file:///workspace/", $path)).unwrap()
}
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

pretty cool

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

9l0d7o

.context("call() returned an error")
.and_then(|res| {
if let Some(res) = res {
bail!("shutdown returned {:?}", res)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are we shutting down here?

.await
.map_err(Error::msg)
.context("call() returned an error")
.and_then(|res| {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, would it be more flexible to let test callers handle the response themselves?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah but every call will want to deserialise it I guess. but lets reiterate when we wrote a few tests 👍

Comment on lines 180 to 190
self.notify(
"textDocument/didOpen",
DidOpenTextDocumentParams {
text_document: TextDocumentItem {
uri: url!("document.js"),
language_id: String::from("javascript"),
version: 0,
text: text.to_string(),
},
},
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a feeling: I think we need to be careful about what we abstract away and what we force the tests to do themselves.

For methods that are always called like shutdown, initialize etc. I think it makes sense to provide convenience methods.

But I'm not super about e.g. open_document – a bug might slip in because our testing logic contains too much "business logic".

Also, this is javascript 🤣

But yeah, WDYT? I think it's a fine line

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah agreed. I removed some of the methods and we reiterate when we have added a few tests

@psteinroe psteinroe merged commit 9df9772 into main Feb 21, 2025
6 checks passed
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