From d0466265a1a411a73ef5f24fc5add0ce4a0fdae1 Mon Sep 17 00:00:00 2001 From: Davis Vaughan Date: Thu, 5 Dec 2024 15:34:49 -0500 Subject: [PATCH 1/3] Address all obvious clippy complaints --- Cargo.toml | 1 - .../air_r_formatter/src/r/auxiliary/call_arguments.rs | 2 +- crates/lsp/src/config.rs | 8 +------- crates/lsp/src/documents.rs | 2 +- crates/lsp/src/encoding.rs | 2 +- crates/lsp/src/handlers_ext.rs | 2 +- crates/lsp/src/handlers_format.rs | 2 +- crates/lsp/src/handlers_state.rs | 2 +- crates/lsp/src/main_loop.rs | 11 +++++++---- crates/lsp/src/rust_analyzer/text_edit.rs | 2 +- crates/lsp/src/tower_lsp.rs | 7 +++++-- crates/lsp/src/tower_lsp_test_client.rs | 2 +- crates/lsp_test/src/lsp_client.rs | 2 +- crates/lsp_test/src/tower_lsp/codec.rs | 2 +- crates/lsp_test/src/tower_lsp/request.rs | 2 +- 15 files changed, 24 insertions(+), 25 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 433445e5..18c33eac 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -124,7 +124,6 @@ empty_drop = "warn" empty_enum_variants_with_brackets = "warn" float_cmp_const = "warn" get_unwrap = "warn" -infinite_loop = "warn" lossy_float_literal = "warn" rc_buffer = "warn" rc_mutex = "warn" diff --git a/crates/air_r_formatter/src/r/auxiliary/call_arguments.rs b/crates/air_r_formatter/src/r/auxiliary/call_arguments.rs index 6a43db61..10e8257c 100644 --- a/crates/air_r_formatter/src/r/auxiliary/call_arguments.rs +++ b/crates/air_r_formatter/src/r/auxiliary/call_arguments.rs @@ -923,7 +923,7 @@ struct FormatAllArgsBrokenOut<'a> { expand: bool, } -impl<'a> Format for FormatAllArgsBrokenOut<'a> { +impl Format for FormatAllArgsBrokenOut<'_> { fn fmt(&self, f: &mut Formatter) -> FormatResult<()> { let args = format_with(|f| { for (index, entry) in self.args.iter().enumerate() { diff --git a/crates/lsp/src/config.rs b/crates/lsp/src/config.rs index 33913774..43c5ae51 100644 --- a/crates/lsp/src/config.rs +++ b/crates/lsp/src/config.rs @@ -10,7 +10,7 @@ use serde::Serialize; use struct_field_names_as_array::FieldNamesAsArray; /// Configuration of the LSP -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Default)] pub(crate) struct LspConfig {} /// Configuration of a document. @@ -62,12 +62,6 @@ pub(crate) enum VscIndentSize { Size(usize), } -impl Default for LspConfig { - fn default() -> Self { - Self {} - } -} - impl Default for IndentationConfig { fn default() -> Self { Self { diff --git a/crates/lsp/src/documents.rs b/crates/lsp/src/documents.rs index 8f90063e..ecb5103d 100644 --- a/crates/lsp/src/documents.rs +++ b/crates/lsp/src/documents.rs @@ -159,7 +159,7 @@ mod tests { insta::assert_debug_snapshot!(original_syntax); let edit = TextEdit::replace( - TextRange::new(TextSize::from(4 as u32), TextSize::from(7)), + TextRange::new(TextSize::from(4_u32), TextSize::from(7)), String::from("1 + 2"), ); let edits = to_proto::doc_edit_vec(&doc.line_index, edit).unwrap(); diff --git a/crates/lsp/src/encoding.rs b/crates/lsp/src/encoding.rs index 13a18848..488b55cd 100644 --- a/crates/lsp/src/encoding.rs +++ b/crates/lsp/src/encoding.rs @@ -35,7 +35,7 @@ fn convert_character_from_utf16_to_utf8(x: &str, character: usize) -> usize { } log::error!("Failed to locate UTF-16 offset of {character}. Line: '{x}'."); - return 0; + 0 } /// Converts a character offset into a particular line from UTF-8 to UTF-16 diff --git a/crates/lsp/src/handlers_ext.rs b/crates/lsp/src/handlers_ext.rs index cfb325a3..45125222 100644 --- a/crates/lsp/src/handlers_ext.rs +++ b/crates/lsp/src/handlers_ext.rs @@ -67,7 +67,7 @@ fn format_ts_node(cursor: &mut tree_sitter::TreeCursor, depth: usize, output: &m let node = cursor.node(); let field_name = match cursor.field_name() { Some(name) => format!("{name}: "), - None => String::from(""), + None => String::new(), }; let start = node.start_position(); diff --git a/crates/lsp/src/handlers_format.rs b/crates/lsp/src/handlers_format.rs index 3569231d..ada97f36 100644 --- a/crates/lsp/src/handlers_format.rs +++ b/crates/lsp/src/handlers_format.rs @@ -82,7 +82,7 @@ mod tests { let edits = client.format_document_edits(&doc).await.unwrap(); assert!(edits.len() == 1); - let edit = edits.get(0).unwrap(); + let edit = &edits[0]; assert_eq!(edit.new_text, " + "); client diff --git a/crates/lsp/src/handlers_state.rs b/crates/lsp/src/handlers_state.rs index 6f2f2239..81f7e629 100644 --- a/crates/lsp/src/handlers_state.rs +++ b/crates/lsp/src/handlers_state.rs @@ -290,7 +290,7 @@ async fn update_config( // --- Documents // For each document, deserialise the vector of JSON values into a typed config - for uri in uris.into_iter() { + for uri in uris { let keys = document_keys.into_iter(); let items: Vec = configs.by_ref().take(n_document_items).collect(); diff --git a/crates/lsp/src/main_loop.rs b/crates/lsp/src/main_loop.rs index ba117f67..55944189 100644 --- a/crates/lsp/src/main_loop.rs +++ b/crates/lsp/src/main_loop.rs @@ -279,7 +279,7 @@ impl GlobalState { LspRequest::Initialize(params) => { respond(tx, handlers_state::initialize(params, &mut self.lsp_state, &mut self.world), LspResponse::Initialize)?; }, - LspRequest::Shutdown() => { + LspRequest::Shutdown => { out = LoopControl::Shutdown; respond(tx, Ok(()), LspResponse::Shutdown)?; }, @@ -411,7 +411,7 @@ impl AuxiliaryState { /// /// Takes ownership of auxiliary state and start the low-latency auxiliary /// loop. - async fn start(mut self) { + async fn start(mut self) -> ! { loop { match self.next_event().await { AuxiliaryEvent::Log(level, message) => self.log(level, message).await, @@ -474,7 +474,10 @@ pub(crate) fn log(level: lsp_types::MessageType, message: String) { // Check that channel is still alive in case the LSP was closed. // If closed, fallthrough. - if let Ok(_) = auxiliary_tx().send(AuxiliaryEvent::Log(level, message.clone())) { + if auxiliary_tx() + .send(AuxiliaryEvent::Log(level, message.clone())) + .is_ok() + { return; } @@ -500,7 +503,7 @@ where Handler: FnOnce() -> anyhow::Result>, Handler: Send + 'static, { - let handle = tokio::task::spawn_blocking(|| handler()); + let handle = tokio::task::spawn_blocking(handler); // Send the join handle to the auxiliary loop so it can log any errors // or panics diff --git a/crates/lsp/src/rust_analyzer/text_edit.rs b/crates/lsp/src/rust_analyzer/text_edit.rs index 5a844cc8..fa777e50 100644 --- a/crates/lsp/src/rust_analyzer/text_edit.rs +++ b/crates/lsp/src/rust_analyzer/text_edit.rs @@ -327,7 +327,7 @@ mod tests { let mut builder = TextEditBuilder::default(); builder.replace(range(1, 3), "au".into()); builder.replace(range(3, 5), "www".into()); - builder.replace(range(5, 8), "".into()); + builder.replace(range(5, 8), String::new()); builder.replace(range(8, 9), "ub".into()); let edit = builder.finish(); diff --git a/crates/lsp/src/tower_lsp.rs b/crates/lsp/src/tower_lsp.rs index 41ac46eb..c2591fc3 100644 --- a/crates/lsp/src/tower_lsp.rs +++ b/crates/lsp/src/tower_lsp.rs @@ -32,6 +32,7 @@ macro_rules! cast_response { }}; } +#[allow(clippy::large_enum_variant)] #[derive(Debug)] pub(crate) enum LspMessage { Notification(LspNotification), @@ -53,14 +54,16 @@ pub(crate) enum LspNotification { DidCloseTextDocument(DidCloseTextDocumentParams), } +#[allow(clippy::large_enum_variant)] #[derive(Debug)] pub(crate) enum LspRequest { Initialize(InitializeParams), DocumentFormatting(DocumentFormattingParams), - Shutdown(), + Shutdown, AirViewFile(ViewFileParams), } +#[allow(clippy::large_enum_variant)] #[derive(Debug)] pub(crate) enum LspResponse { Initialize(InitializeResult), @@ -130,7 +133,7 @@ impl LanguageServer for Backend { async fn shutdown(&self) -> Result<()> { cast_response!( - self.request(LspRequest::Shutdown()).await, + self.request(LspRequest::Shutdown).await, LspResponse::Shutdown ) } diff --git a/crates/lsp/src/tower_lsp_test_client.rs b/crates/lsp/src/tower_lsp_test_client.rs index 63cca470..6d423718 100644 --- a/crates/lsp/src/tower_lsp_test_client.rs +++ b/crates/lsp/src/tower_lsp_test_client.rs @@ -35,7 +35,7 @@ impl TestClientExt for TestClient { } async fn format_document_edits(&mut self, doc: &Document) -> Option> { - let lsp_doc = self.open_document(&doc).await; + let lsp_doc = self.open_document(doc).await; let options = lsp_types::FormattingOptions { tab_size: 4, diff --git a/crates/lsp_test/src/lsp_client.rs b/crates/lsp_test/src/lsp_client.rs index 3d94c800..c19047d6 100644 --- a/crates/lsp_test/src/lsp_client.rs +++ b/crates/lsp_test/src/lsp_client.rs @@ -86,7 +86,7 @@ impl TestClient { pub async fn initialize(&mut self) -> i64 { let params: Option = std::mem::take(&mut self.init_params); - let params = params.unwrap_or(Default::default()); + let params = params.unwrap_or_default(); self.request::(params).await } diff --git a/crates/lsp_test/src/tower_lsp/codec.rs b/crates/lsp_test/src/tower_lsp/codec.rs index 4b6326de..5c1068c2 100644 --- a/crates/lsp_test/src/tower_lsp/codec.rs +++ b/crates/lsp_test/src/tower_lsp/codec.rs @@ -219,7 +219,7 @@ fn decode_headers(headers: &[httparse::Header<'_>]) -> Result .find_map(|param| param.strip_prefix("charset=")); match charset { - Some("utf-8") | Some("utf8") => {} + Some("utf-8" | "utf8") => {} _ => return Err(ParseError::InvalidContentType), } } diff --git a/crates/lsp_test/src/tower_lsp/request.rs b/crates/lsp_test/src/tower_lsp/request.rs index 362939d9..d5c68773 100644 --- a/crates/lsp_test/src/tower_lsp/request.rs +++ b/crates/lsp_test/src/tower_lsp/request.rs @@ -148,7 +148,7 @@ impl Display for Request { inner: &'a mut Formatter<'b>, } - impl<'a, 'b> io::Write for WriterFormatter<'a, 'b> { + impl io::Write for WriterFormatter<'_, '_> { fn write(&mut self, buf: &[u8]) -> io::Result { fn io_error(_: E) -> io::Error { // Error value does not matter because fmt::Display impl below just From 1adefcb1077436ba33af10be72cbea1891bc8236 Mon Sep 17 00:00:00 2001 From: Davis Vaughan Date: Thu, 5 Dec 2024 15:35:11 -0500 Subject: [PATCH 2/3] Bump MSRV to 1.83 --- Cargo.toml | 1 + crates/air/Cargo.toml | 1 + crates/air_formatter_test/Cargo.toml | 23 ++++++++++++----------- crates/air_r_factory/Cargo.toml | 1 + crates/air_r_formatter/Cargo.toml | 1 + crates/air_r_parser/Cargo.toml | 23 ++++++++++++----------- crates/air_r_syntax/Cargo.toml | 23 ++++++++++++----------- crates/biome_ungrammar/Cargo.toml | 23 ++++++++++++----------- crates/lsp/Cargo.toml | 1 + crates/lsp_test/Cargo.toml | 1 + crates/tests_macros/Cargo.toml | 21 +++++++++++---------- 11 files changed, 65 insertions(+), 54 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 18c33eac..c51073ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ homepage = "https://github.com/posit-dev/air" keywords = ["parser", "formatter"] license = "MIT" repository = "https://github.com/posit-dev/air" +rust-version = "1.83" [profile.release-with-debug] debug = true diff --git a/crates/air/Cargo.toml b/crates/air/Cargo.toml index d3f41f7d..2e7fbf00 100644 --- a/crates/air/Cargo.toml +++ b/crates/air/Cargo.toml @@ -9,6 +9,7 @@ homepage.workspace = true keywords.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [dependencies] air_r_formatter = { workspace = true } diff --git a/crates/air_formatter_test/Cargo.toml b/crates/air_formatter_test/Cargo.toml index a2ca1468..4e20a544 100644 --- a/crates/air_formatter_test/Cargo.toml +++ b/crates/air_formatter_test/Cargo.toml @@ -1,15 +1,16 @@ [package] -authors.workspace = true -categories.workspace = true -description = "Air's formatter test shared infrastructure" -edition.workspace = true -homepage.workspace = true -keywords.workspace = true -license.workspace = true -name = "air_formatter_test" -publish = false -repository.workspace = true -version = "0.0.0" +authors.workspace = true +categories.workspace = true +description = "Air's formatter test shared infrastructure" +edition.workspace = true +homepage.workspace = true +keywords.workspace = true +license.workspace = true +name = "air_formatter_test" +publish = false +repository.workspace = true +rust-version.workspace = true +version = "0.0.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/crates/air_r_factory/Cargo.toml b/crates/air_r_factory/Cargo.toml index 8f6abb0d..0977d9c1 100644 --- a/crates/air_r_factory/Cargo.toml +++ b/crates/air_r_factory/Cargo.toml @@ -9,6 +9,7 @@ homepage.workspace = true keywords.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [dependencies] air_r_syntax = { workspace = true } diff --git a/crates/air_r_formatter/Cargo.toml b/crates/air_r_formatter/Cargo.toml index 32d2fef8..2b09fce6 100644 --- a/crates/air_r_formatter/Cargo.toml +++ b/crates/air_r_formatter/Cargo.toml @@ -10,6 +10,7 @@ license.workspace = true name = "air_r_formatter" publish = false repository.workspace = true +rust-version.workspace = true version = "0.0.0" [dependencies] diff --git a/crates/air_r_parser/Cargo.toml b/crates/air_r_parser/Cargo.toml index 4b50bdf4..9d138fe2 100644 --- a/crates/air_r_parser/Cargo.toml +++ b/crates/air_r_parser/Cargo.toml @@ -1,15 +1,16 @@ [package] -authors.workspace = true -categories.workspace = true -description = "Air R parser" -edition.workspace = true -homepage.workspace = true -keywords.workspace = true -license.workspace = true -name = "air_r_parser" -publish = false -repository.workspace = true -version = "0.0.0" +authors.workspace = true +categories.workspace = true +description = "Air R parser" +edition.workspace = true +homepage.workspace = true +keywords.workspace = true +license.workspace = true +name = "air_r_parser" +publish = false +repository.workspace = true +rust-version.workspace = true +version = "0.0.0" [dependencies] air_r_factory = { workspace = true } diff --git a/crates/air_r_syntax/Cargo.toml b/crates/air_r_syntax/Cargo.toml index de02766f..305d0f05 100644 --- a/crates/air_r_syntax/Cargo.toml +++ b/crates/air_r_syntax/Cargo.toml @@ -1,15 +1,16 @@ [package] -authors.workspace = true -categories.workspace = true -description = "SyntaxKind and common rowan definitions for air_r_parser" -edition.workspace = true -homepage.workspace = true -keywords.workspace = true -license.workspace = true -name = "air_r_syntax" -publish = false -repository.workspace = true -version = "0.0.0" +authors.workspace = true +categories.workspace = true +description = "SyntaxKind and common rowan definitions for air_r_parser" +edition.workspace = true +homepage.workspace = true +keywords.workspace = true +license.workspace = true +name = "air_r_syntax" +publish = false +repository.workspace = true +rust-version.workspace = true +version = "0.0.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/crates/biome_ungrammar/Cargo.toml b/crates/biome_ungrammar/Cargo.toml index 706daeb0..b752ca54 100644 --- a/crates/biome_ungrammar/Cargo.toml +++ b/crates/biome_ungrammar/Cargo.toml @@ -1,15 +1,16 @@ [package] -authors.workspace = true -categories.workspace = true -description = "A DSL for describing concrete syntax trees" -edition.workspace = true -homepage.workspace = true -keywords.workspace = true -license.workspace = true -name = "biome_ungrammar" -publish = false -repository.workspace = true -version = "0.3.1" +authors.workspace = true +categories.workspace = true +description = "A DSL for describing concrete syntax trees" +edition.workspace = true +homepage.workspace = true +keywords.workspace = true +license.workspace = true +name = "biome_ungrammar" +publish = false +repository.workspace = true +rust-version.workspace = true +version = "0.3.1" [lints] workspace = true diff --git a/crates/lsp/Cargo.toml b/crates/lsp/Cargo.toml index 46b851fc..2dbd2b4f 100644 --- a/crates/lsp/Cargo.toml +++ b/crates/lsp/Cargo.toml @@ -9,6 +9,7 @@ homepage.workspace = true keywords.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [dependencies] air_r_formatter.workspace = true diff --git a/crates/lsp_test/Cargo.toml b/crates/lsp_test/Cargo.toml index 522e6bfe..c76e8be8 100644 --- a/crates/lsp_test/Cargo.toml +++ b/crates/lsp_test/Cargo.toml @@ -9,6 +9,7 @@ homepage.workspace = true keywords.workspace = true license.workspace = true repository.workspace = true +rust-version.workspace = true [dependencies] bytes.workspace = true diff --git a/crates/tests_macros/Cargo.toml b/crates/tests_macros/Cargo.toml index c1fc3b50..0fccccd0 100644 --- a/crates/tests_macros/Cargo.toml +++ b/crates/tests_macros/Cargo.toml @@ -1,14 +1,15 @@ [package] -authors.workspace = true -categories.workspace = true -edition.workspace = true -homepage.workspace = true -keywords.workspace = true -license.workspace = true -name = "tests_macros" -publish = false -repository.workspace = true -version = "0.0.0" +authors.workspace = true +categories.workspace = true +edition.workspace = true +homepage.workspace = true +keywords.workspace = true +license.workspace = true +name = "tests_macros" +publish = false +repository.workspace = true +rust-version.workspace = true +version = "0.0.0" [lib] proc-macro = true From e9b08f14650f8503fa7d77c6959be47677deb3b4 Mon Sep 17 00:00:00 2001 From: Davis Vaughan Date: Thu, 5 Dec 2024 15:38:46 -0500 Subject: [PATCH 3/3] Use gross `#[allow(static_mut_refs)]` to be able to use `AUXILIARY_EVENT_TX` --- crates/lsp/src/main_loop.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/lsp/src/main_loop.rs b/crates/lsp/src/main_loop.rs index 55944189..fc7c43ed 100644 --- a/crates/lsp/src/main_loop.rs +++ b/crates/lsp/src/main_loop.rs @@ -379,6 +379,7 @@ impl AuxiliaryState { // with the auxiliary loop (logging messages or spawning a task) from // free functions. unsafe { + #[allow(static_mut_refs)] if let Some(val) = AUXILIARY_EVENT_TX.get_mut() { // Reset channel if already set. Happens e.g. on reconnection after a refresh. *val = auxiliary_event_tx; @@ -454,7 +455,10 @@ impl AuxiliaryState { fn auxiliary_tx() -> &'static TokioUnboundedSender { // If we get here that means the LSP was initialised at least once. The // channel might be closed if the LSP was dropped, but it should exist. - unsafe { AUXILIARY_EVENT_TX.get().unwrap() } + unsafe { + #[allow(static_mut_refs)] + AUXILIARY_EVENT_TX.get().unwrap() + } } fn send_auxiliary(event: AuxiliaryEvent) {