-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[ty] Configure check mode for all projects #23121
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 from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ use lsp_types::notification::DidOpenTextDocument; | |
| use lsp_types::{DidOpenTextDocumentParams, TextDocumentItem}; | ||
|
|
||
| use crate::TextDocument; | ||
| use crate::document::LanguageId; | ||
| use crate::server::Result; | ||
| use crate::server::api::diagnostics::publish_diagnostics_if_needed; | ||
| use crate::server::api::traits::{NotificationHandler, SyncNotificationHandler}; | ||
|
|
@@ -30,10 +31,12 @@ impl SyncNotificationHandler for DidOpenTextDocumentHandler { | |
| }, | ||
| } = params; | ||
|
|
||
| let document = session.open_text_document( | ||
| TextDocument::new(uri, text, version).with_language_id(&language_id), | ||
| ); | ||
| let text_doc = TextDocument::new(uri, text, version).with_language_id(&language_id); | ||
| if matches!(text_doc.language_id(), Some(LanguageId::Other)) { | ||
| return Ok(()); | ||
| } | ||
|
|
||
| let document = session.open_text_document(text_doc); | ||
|
Comment on lines
-33
to
+39
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this sounds correct but it would be useful to have a E2E test case for this scenario if it doesn't already exists. What do you think?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is what the |
||
| publish_diagnostics_if_needed(&document, session, client); | ||
|
|
||
| Ok(()) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -326,8 +326,6 @@ def foo() -> str: | |
| }, | ||
| }; | ||
| server.send_notification::<DidOpenTextDocument>(params); | ||
| let _close_diagnostics = server.await_notification::<PublishDiagnostics>(); | ||
|
|
||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if it was intentional to have the diagnostics send back twice, but this is no longer the case. It was happening previously because:
The end result is that the test got no diagnostics which was what was expected, but it got for a reason other than respecting the change in language ID. Once I fixed the I ended up fixing this by checking the language ID of the file in the |
||
| let diagnostics = server.await_notification::<PublishDiagnostics>(); | ||
|
|
||
| insta::assert_debug_snapshot!(diagnostics); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,5 @@ PublishDiagnosticsParams { | |
| fragment: None, | ||
| }, | ||
| diagnostics: [], | ||
| version: Some( | ||
| 1, | ||
| ), | ||
| version: None, | ||
| } | ||
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 check does seem to be causing some confusion because if this is true then the document won't be opened and the following notifications for this document would result in "Document ... is not open in the session" logs (astral-sh/ty#2824 (comment), astral-sh/ty#2937).
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.
Yeah, we should probably move it below line 39 (I'm also not entirely sure why it's needed)
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 the idea was to mirror what we do in
ty_project/src/walk.rs: #23121 (comment)I think I was thinking about this in particular: https://github.com/astral-sh/ruff/blob/f8d1d29ec7f1ff0da7e0272c8388036f35e815b7/crates/ty_project/src/walk.rs#L240-L228
But it's possible I misinterpreted what that code is doing. @MichaReiser Can you say why this should be moved? Or would it make sense to emit a log or something in this case?
Specifically, this was my attempt at fixing the
changing_language_of_file_without_extensiontest, which started failing after I unwound the check mode configuration stuff.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.
The issue with not opening the document in the session is that any LSP action on any document with
LanguageId::Otherwill fail to look up the document (e.g.,didChange,didClose, etc.), and they'll log a warning on every request.That's why I think that we always need to add the document to
Index(let handle = self.index_mut().open_text_document(document);), but we may want to skip callingproject.open_file(db, file);if the document is a non Python file inopen_document_in_db.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.
OK, I put up a PR for that change here: #23704