mirror of https://github.com/astral-sh/ruff
[ty] Fix outdated version in publish diagnostics after `didChange`
This commit is contained in:
parent
0138cd238a
commit
f72a5e64ad
|
|
@ -26,7 +26,7 @@ impl SyncNotificationHandler for DidChangeTextDocumentHandler {
|
||||||
content_changes,
|
content_changes,
|
||||||
} = params;
|
} = params;
|
||||||
|
|
||||||
let document = session
|
let mut document = session
|
||||||
.document_handle(&uri)
|
.document_handle(&uri)
|
||||||
.with_failure_code(ErrorCode::InternalError)?;
|
.with_failure_code(ErrorCode::InternalError)?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ impl SyncNotificationHandler for DidChangeNotebookHandler {
|
||||||
change: types::NotebookDocumentChangeEvent { cells, metadata },
|
change: types::NotebookDocumentChangeEvent { cells, metadata },
|
||||||
}: types::DidChangeNotebookDocumentParams,
|
}: types::DidChangeNotebookDocumentParams,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let document = session
|
let mut document = session
|
||||||
.document_handle(&uri)
|
.document_handle(&uri)
|
||||||
.with_failure_code(ErrorCode::InternalError)?;
|
.with_failure_code(ErrorCode::InternalError)?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1451,7 +1451,7 @@ impl DocumentHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn update_text_document(
|
pub(crate) fn update_text_document(
|
||||||
&self,
|
&mut self,
|
||||||
session: &mut Session,
|
session: &mut Session,
|
||||||
content_changes: Vec<TextDocumentContentChangeEvent>,
|
content_changes: Vec<TextDocumentContentChangeEvent>,
|
||||||
new_version: DocumentVersion,
|
new_version: DocumentVersion,
|
||||||
|
|
@ -1471,6 +1471,8 @@ impl DocumentHandle {
|
||||||
} else {
|
} else {
|
||||||
document.apply_changes(content_changes, new_version, position_encoding);
|
document.apply_changes(content_changes, new_version, position_encoding);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.set_version(document.version());
|
||||||
}
|
}
|
||||||
|
|
||||||
self.update_in_db(session);
|
self.update_in_db(session);
|
||||||
|
|
@ -1479,7 +1481,7 @@ impl DocumentHandle {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn update_notebook_document(
|
pub(crate) fn update_notebook_document(
|
||||||
&self,
|
&mut self,
|
||||||
session: &mut Session,
|
session: &mut Session,
|
||||||
cells: Option<lsp_types::NotebookDocumentCellChange>,
|
cells: Option<lsp_types::NotebookDocumentCellChange>,
|
||||||
metadata: Option<lsp_types::LSPObject>,
|
metadata: Option<lsp_types::LSPObject>,
|
||||||
|
|
@ -1496,6 +1498,8 @@ impl DocumentHandle {
|
||||||
new_version,
|
new_version,
|
||||||
position_encoding,
|
position_encoding,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
|
self.set_version(new_version);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.update_in_db(session);
|
self.update_in_db(session);
|
||||||
|
|
@ -1516,6 +1520,16 @@ impl DocumentHandle {
|
||||||
session.apply_changes(path, changes);
|
session.apply_changes(path, changes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn set_version(&mut self, version: DocumentVersion) {
|
||||||
|
let self_version = match self {
|
||||||
|
DocumentHandle::Text { version, .. }
|
||||||
|
| DocumentHandle::Notebook { version, .. }
|
||||||
|
| DocumentHandle::Cell { version, .. } => version,
|
||||||
|
};
|
||||||
|
|
||||||
|
*self_version = version;
|
||||||
|
}
|
||||||
|
|
||||||
/// De-registers a document, specified by its key.
|
/// De-registers a document, specified by its key.
|
||||||
/// Calling this multiple times for the same document is a logic error.
|
/// Calling this multiple times for the same document is a logic error.
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,42 @@ def foo() -> str:
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn on_did_change() -> Result<()> {
|
||||||
|
let workspace_root = SystemPath::new("src");
|
||||||
|
let foo = SystemPath::new("src/foo.py");
|
||||||
|
let foo_content = "\
|
||||||
|
def foo() -> str:
|
||||||
|
return 42
|
||||||
|
";
|
||||||
|
|
||||||
|
let mut server = TestServerBuilder::new()?
|
||||||
|
.with_workspace(workspace_root, None)?
|
||||||
|
.with_file(foo, foo_content)?
|
||||||
|
.enable_pull_diagnostics(false)
|
||||||
|
.build()
|
||||||
|
.wait_until_workspaces_are_initialized();
|
||||||
|
|
||||||
|
server.open_text_document(foo, foo_content, 1);
|
||||||
|
let _ = server.await_notification::<PublishDiagnostics>();
|
||||||
|
|
||||||
|
let changes = vec![lsp_types::TextDocumentContentChangeEvent {
|
||||||
|
range: None,
|
||||||
|
range_length: None,
|
||||||
|
text: "def foo() -> int: return 42".to_string(),
|
||||||
|
}];
|
||||||
|
|
||||||
|
server.change_text_document(foo, changes, 2);
|
||||||
|
|
||||||
|
let diagnostics = server.await_notification::<PublishDiagnostics>();
|
||||||
|
|
||||||
|
assert_eq!(diagnostics.version, Some(2));
|
||||||
|
|
||||||
|
insta::assert_debug_snapshot!(diagnostics);
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn message_without_related_information_support() -> Result<()> {
|
fn message_without_related_information_support() -> Result<()> {
|
||||||
let workspace_root = SystemPath::new("src");
|
let workspace_root = SystemPath::new("src");
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
---
|
||||||
|
source: crates/ty_server/tests/e2e/publish_diagnostics.rs
|
||||||
|
expression: diagnostics
|
||||||
|
---
|
||||||
|
PublishDiagnosticsParams {
|
||||||
|
uri: Url {
|
||||||
|
scheme: "file",
|
||||||
|
cannot_be_a_base: false,
|
||||||
|
username: "",
|
||||||
|
password: None,
|
||||||
|
host: None,
|
||||||
|
port: None,
|
||||||
|
path: "<temp_dir>/src/foo.py",
|
||||||
|
query: None,
|
||||||
|
fragment: None,
|
||||||
|
},
|
||||||
|
diagnostics: [],
|
||||||
|
version: Some(
|
||||||
|
2,
|
||||||
|
),
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue