-
Notifications
You must be signed in to change notification settings - Fork 213
add version support to textDocument/publishDiagnostics #1382
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
base: main
Are you sure you want to change the base?
Conversation
kinto0
left a comment
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.
Thanks for contributing! A few tests for this behavior would make us confident it works really well.
Could you add some tests in the lsp_interaction folder where each version for a diagnostics response is correct?
Thanks!!
pyrefly/lib/lsp/non_wasm/server.rs
Outdated
| } | ||
| self.connection.publish_diagnostics(diags); | ||
| self.connection | ||
| .publish_diagnostics(diags, &*self.version_info.lock()); |
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.
nit: by aqcuiring the lock here, we won't be able to make updates to the version info. maybe we should clone it instead?
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.
cloning the hashtable might be kind of heavy too? I prefer lock. let me know if otherwise.
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.
publish_diagnostics_for_uri takes an i32 so maybe we can change the API to only call these functions with that?
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'm not sure I follow you, publish_diagnostics_for_uri takes an Option<i32> as version, also the change API part.
7028101 to
77eb1c0
Compare
I added a small test for this, however I can't figure out why it won't work, might need a little help here. : ( |
50c3750 to
9313fb2
Compare
kinto0
left a comment
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.
could you paste the test failure? it should show the messages back/forth.
pyrefly/lib/lsp/non_wasm/server.rs
Outdated
| } | ||
| self.connection.publish_diagnostics(diags); | ||
| self.connection | ||
| .publish_diagnostics(diags, &*self.version_info.lock()); |
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.
publish_diagnostics_for_uri takes an i32 so maybe we can change the API to only call these functions with that?
|
hmm that test looks like the behavior you want. like the other comments say, you're looking for the publishDiagnostic notification, not the textDocument/diagnostic response. the first one happens because of the type error then the next one happens because of the didChange. you can remove the document diagnostic requests and make a similar method to |
f982a09 to
32c4548
Compare
Now the test always fails with Timeout error, idk why. |
32c4548 to
a201c98
Compare
a201c98 to
3624c06
Compare
|
bumping some old PRs: if you still want a review on this, please re-request review |
3624c06 to
2e27f24
Compare
2e27f24 to
17c375e
Compare
| interaction.initialize(InitializeSettings { | ||
| configuration: Some(None), | ||
| capabilities: Some(serde_json::json!({ | ||
| "textDocument": { | ||
| "publishDiagnostics": { | ||
| "versionSupport": true, | ||
| }, | ||
| }, | ||
| })), | ||
| ..Default::default() | ||
| }); |
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.
any reason not to keep these default?
| interaction.initialize(InitializeSettings { | |
| configuration: Some(None), | |
| capabilities: Some(serde_json::json!({ | |
| "textDocument": { | |
| "publishDiagnostics": { | |
| "versionSupport": true, | |
| }, | |
| }, | |
| })), | |
| ..Default::default() | |
| }); | |
| interaction.initialize(InitializeSettings::Default) |
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.
any reason not to keep these default?
Sorry I'm not familiar with this, is version support enabled by default?
| move |msg: &Message| { | ||
| let Message::Notification(Notification { method, params }) = msg else { | ||
| return ValidationResult::Skip; | ||
| }; | ||
| let Some(uri_val) = params.get("uri") else { | ||
| return ValidationResult::Skip; | ||
| }; | ||
| let Some(expected_uri) = uri_val.as_str() else { | ||
| return ValidationResult::Skip; | ||
| }; | ||
| if expected_uri == actual_uri && method == "textDocument/publishDiagnostics" { | ||
| if let Some(actual_version) = params.get("version") { | ||
| if let Some(actual_version) = actual_version.as_i64() { | ||
| assert!( | ||
| actual_version <= expected_version, | ||
| "expected version: {}, actual version: {}", | ||
| expected_version, | ||
| actual_version | ||
| ); | ||
| return match actual_version.cmp(&expected_version) { | ||
| std::cmp::Ordering::Less => ValidationResult::Skip, | ||
| std::cmp::Ordering::Equal => ValidationResult::Pass, | ||
| std::cmp::Ordering::Greater => ValidationResult::Fail, | ||
| }; | ||
| } | ||
| } | ||
| } | ||
| ValidationResult::Skip | ||
| } | ||
| }; |
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.
nit: can this be a match sothe skips are combined?
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.
nit: can this be a match sothe skips are combined?
it either this or nested if let I think.
| ); | ||
| return match actual_version.cmp(&expected_version) { | ||
| std::cmp::Ordering::Less => ValidationResult::Skip, | ||
| std::cmp::Ordering::Equal => ValidationResult::Pass, |
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 this expected?
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 this expected?
I think we should skip lower version, right? I'm not sure I understand this correctly though.
| ..Default::default() | ||
| }); | ||
|
|
||
| let gen_validator = |expected_version: i64| { |
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.
what does gen mean here? could we name this better?
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.
what does gen mean here? could we name this better?
generate, is create_version_validator a better name?
Co-authored-by: Kyle Into <kyleatyahoo@gmail.com>
Co-authored-by: Kyle Into <kyleatyahoo@gmail.com>
f1bfc8f to
d49f787
Compare
close #794
PS: I know little about LSP or this project