diff --git a/Cargo.lock b/Cargo.lock index e2ac9031572a4..868cb2053a278 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1275,9 +1275,9 @@ dependencies = [ [[package]] name = "gen-lsp-types" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cd635c5206acd03ea024d6b5902539e5c903de3afa220fdb5c94b583af77f4f" +checksum = "b64887ac3a8083427ae935a7296db876871582cd57eac077564f8bc18fa49116" dependencies = [ "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 36a52565a62c7..d0775eb89006b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -131,7 +131,7 @@ libc = { version = "0.2.153" } libcst = { version = "1.8.4", default-features = false } log = { version = "0.4.17" } lsp-server = { version = "0.10.0" } -lsp-types = { package = "gen-lsp-types", version = "0.10.0", features = ["url"] } +lsp-types = { package = "gen-lsp-types", version = "0.11.0", features = ["url"] } matchit = { version = "0.9.0" } memchr = { version = "2.7.1" } mimalloc = { version = "0.1.49", features = ["v2"] } diff --git a/crates/ruff_server/src/edit/notebook.rs b/crates/ruff_server/src/edit/notebook.rs index ba15031389484..d3a6c3f32db24 100644 --- a/crates/ruff_server/src/edit/notebook.rs +++ b/crates/ruff_server/src/edit/notebook.rs @@ -63,25 +63,32 @@ impl NotebookDocument { let cells = self .cells .iter() - .map(|cell| match cell.kind { - NotebookCellKind::Code => ruff_notebook::Cell::Code(ruff_notebook::CodeCell { - execution_count: None, - id: None, - metadata: CellMetadata::default(), - outputs: vec![], - source: ruff_notebook::SourceValue::String( - cell.document.contents().to_string(), - ), - }), + .filter_map(|cell| match cell.kind { + NotebookCellKind::Code => { + Some(ruff_notebook::Cell::Code(ruff_notebook::CodeCell { + execution_count: None, + id: None, + metadata: CellMetadata::default(), + outputs: vec![], + source: ruff_notebook::SourceValue::String( + cell.document.contents().to_string(), + ), + })) + } NotebookCellKind::Markup => { - ruff_notebook::Cell::Markdown(ruff_notebook::MarkdownCell { + Some(ruff_notebook::Cell::Markdown(ruff_notebook::MarkdownCell { attachments: None, id: None, metadata: CellMetadata::default(), source: ruff_notebook::SourceValue::String( cell.document.contents().to_string(), ), - }) + })) + } + NotebookCellKind::Custom(_) => { + // Ignore unsupported cell kinds. This arm should never be reached unless a + // client sends a value which is not mentioned/supported in the LSP. + None } }) .collect(); diff --git a/crates/ty_server/src/document/notebook.rs b/crates/ty_server/src/document/notebook.rs index c538a7b7c65ff..946bdbfe2002c 100644 --- a/crates/ty_server/src/document/notebook.rs +++ b/crates/ty_server/src/document/notebook.rs @@ -72,7 +72,7 @@ impl NotebookDocument { let cells = self .cells .iter() - .map(|cell| { + .filter_map(|cell| { let cell_text = if let Ok(document) = index.document(&DocumentKey::from_uri(&cell.uri)) { if let Some(text_document) = document.as_text() { @@ -89,23 +89,30 @@ impl NotebookDocument { let source = ruff_notebook::SourceValue::String(cell_text); match cell.kind { - NotebookCellKind::Code => ruff_notebook::Cell::Code(ruff_notebook::CodeCell { - execution_count: cell - .execution_summary - .as_ref() - .map(|summary| i64::from(summary.execution_order)), - id: None, - metadata: CellMetadata::default(), - outputs: vec![], - source, - }), + NotebookCellKind::Code => { + Some(ruff_notebook::Cell::Code(ruff_notebook::CodeCell { + execution_count: cell + .execution_summary + .as_ref() + .map(|summary| i64::from(summary.execution_order)), + id: None, + metadata: CellMetadata::default(), + outputs: vec![], + source, + })) + } NotebookCellKind::Markup => { - ruff_notebook::Cell::Markdown(ruff_notebook::MarkdownCell { + Some(ruff_notebook::Cell::Markdown(ruff_notebook::MarkdownCell { attachments: None, id: None, metadata: CellMetadata::default(), source, - }) + })) + } + NotebookCellKind::Custom(_) => { + // Ignore unsupported cell kinds. This arm should never be reached unless a + // client sends a value which is not mentioned/supported in the LSP. + None } } }) diff --git a/crates/ty_server/src/server/api/notifications/did_change_watched_files.rs b/crates/ty_server/src/server/api/notifications/did_change_watched_files.rs index a04b19cdad2a2..b0e866838df06 100644 --- a/crates/ty_server/src/server/api/notifications/did_change_watched_files.rs +++ b/crates/ty_server/src/server/api/notifications/did_change_watched_files.rs @@ -59,6 +59,8 @@ impl SyncNotificationHandler for DidChangeWatchedFiles { path: system_path, kind: DeletedKind::Any, }, + // Custom file change types are not supported and should be ignored. + FileChangeType::Custom(_) => continue, }; changes.push(change_event); diff --git a/crates/ty_server/tests/e2e/workspace_folders.rs b/crates/ty_server/tests/e2e/workspace_folders.rs index 0fa0fc9839bbb..874e72a4ab215 100644 --- a/crates/ty_server/tests/e2e/workspace_folders.rs +++ b/crates/ty_server/tests/e2e/workspace_folders.rs @@ -759,7 +759,7 @@ fn condensed_full_document_diagnostic_report(report: FullDocumentDiagnosticRepor Some(DiagnosticSeverity::Warning) => "WARNING", Some(DiagnosticSeverity::Information) => "INFORMATION", Some(DiagnosticSeverity::Hint) => "HINT", - None => "unknown", + Some(DiagnosticSeverity::Custom(_)) | None => "unknown", }; let Message::String(message) = d.message else { panic!(