From b9b6ca6d04929ed4b3969901054bf7e01f4ba8d7 Mon Sep 17 00:00:00 2001 From: JoshuaBatty Date: Fri, 5 Jan 2024 10:49:35 +1100 Subject: [PATCH] clippy and rebase --- sway-core/src/lib.rs | 10 ++-------- sway-lsp/benches/lsp_benchmarks/compile.rs | 10 ++++------ sway-lsp/benches/lsp_benchmarks/mod.rs | 2 +- sway-lsp/src/capabilities/semantic_tokens.rs | 2 +- sway-lsp/src/core/session.rs | 6 ++---- sway-lsp/src/handlers/notification.rs | 4 ++-- sway-lsp/src/server_state.rs | 5 ++--- 7 files changed, 14 insertions(+), 25 deletions(-) diff --git a/sway-core/src/lib.rs b/sway-core/src/lib.rs index 9b6c0a88942..469da991469 100644 --- a/sway-core/src/lib.rs +++ b/sway-core/src/lib.rs @@ -619,17 +619,12 @@ pub fn compile_to_ast( if is_parse_module_cache_up_to_date(engines, &path, include_tests) { let mut entry = query_engine .get_programs_cache_entry(&path) - .expect(&format!( - "unable to find entry in cache at path {:?}", - &path - )); + .unwrap_or_else(|| panic!("unable to find entry in cache at path {:?}", &path)); entry.programs.metrics.reused_modules += 1; - + let (warnings, errors) = entry.handler_data; let new_handler = Handler::from_parts(warnings, errors); handler.append(new_handler); - - //eprintln!("re-using cached prgram data, returning from compilation"); return Ok(entry.programs); }; } @@ -688,7 +683,6 @@ pub fn compile_to_ast( if let Some(config) = build_config { let path = config.canonical_root_module(); - let cache_entry = ProgramsCacheEntry { path, programs: programs.clone(), diff --git a/sway-lsp/benches/lsp_benchmarks/compile.rs b/sway-lsp/benches/lsp_benchmarks/compile.rs index e868d9d2d85..070a9674834 100644 --- a/sway-lsp/benches/lsp_benchmarks/compile.rs +++ b/sway-lsp/benches/lsp_benchmarks/compile.rs @@ -11,13 +11,13 @@ fn benchmarks(c: &mut Criterion) { c.bench_function("compile", |b| { b.iter(|| { let engines = Engines::default(); - let _ = black_box(session::compile(&uri, None, &engines, None).unwrap()); + let _ = black_box(session::compile(&uri, &engines, None).unwrap()); }) }); c.bench_function("traverse", |b| { let engines = Engines::default(); - let results = black_box(session::compile(&uri, None, &engines, None).unwrap()); + let results = black_box(session::compile(&uri, &engines, None).unwrap()); b.iter(|| { let _ = black_box(session::traverse(results.clone(), &engines).unwrap()); }) @@ -26,10 +26,8 @@ fn benchmarks(c: &mut Criterion) { c.bench_function("did_change_with_caching", |b| { let engines = Engines::default(); b.iter(|| { - for version in 0..NUM_DID_CHANGE_ITERATIONS { - let _ = black_box( - session::compile(&uri, Some(version as i32), &engines, None).unwrap(), - ); + for _ in 0..NUM_DID_CHANGE_ITERATIONS { + let _ = black_box(session::compile(&uri, &engines, None).unwrap()); } }) }); diff --git a/sway-lsp/benches/lsp_benchmarks/mod.rs b/sway-lsp/benches/lsp_benchmarks/mod.rs index df1f9a281a3..cf4bf9827f0 100644 --- a/sway-lsp/benches/lsp_benchmarks/mod.rs +++ b/sway-lsp/benches/lsp_benchmarks/mod.rs @@ -12,7 +12,7 @@ pub async fn compile_test_project() -> (Url, Arc) { let uri = Url::from_file_path(benchmark_dir().join("src/main.sw")).unwrap(); session.handle_open_file(&uri).await; // Compile the project and write the parse result to the session - let parse_result = session::parse_project(&uri, None, &session.engines.read(), None).unwrap(); + let parse_result = session::parse_project(&uri, &session.engines.read(), None).unwrap(); session.write_parse_result(parse_result); (uri, Arc::new(session)) } diff --git a/sway-lsp/src/capabilities/semantic_tokens.rs b/sway-lsp/src/capabilities/semantic_tokens.rs index 2d348294ff5..06c4c513270 100644 --- a/sway-lsp/src/capabilities/semantic_tokens.rs +++ b/sway-lsp/src/capabilities/semantic_tokens.rs @@ -42,7 +42,7 @@ pub fn semantic_tokens_range( /// Sort tokens by their span so each token is sequential. /// /// If this step isn't done, then the bit offsets used for the lsp_types::SemanticToken are incorrect. -fn sort_tokens(tokens: &mut Vec<(TokenIdent, Token)>) { +fn sort_tokens(tokens: &mut [(TokenIdent, Token)]) { tokens.sort_by(|(a_span, _), (b_span, _)| { let a = (a_span.range.start, a_span.range.end); let b = (b_span.range.start, b_span.range.end); diff --git a/sway-lsp/src/core/session.rs b/sway-lsp/src/core/session.rs index 41af7156c16..aa40af40507 100644 --- a/sway-lsp/src/core/session.rs +++ b/sway-lsp/src/core/session.rs @@ -435,7 +435,6 @@ pub(crate) fn build_plan(uri: &Url) -> Result { pub fn compile( uri: &Url, - version: Option, engines: &Engines, retrigger_compilation: Option>, ) -> Result, Handler)>, LanguageServerError> { @@ -538,11 +537,10 @@ pub fn traverse( /// Parses the project and returns true if the compiler diagnostics are new and should be published. pub fn parse_project( uri: &Url, - version: Option, engines: &Engines, retrigger_compilation: Option>, ) -> Result { - let results = compile(uri, version, engines, retrigger_compilation)?; + let results = compile(uri, engines, retrigger_compilation)?; if results.last().is_none() { //eprintln!("compilation failed, returning"); return Err(LanguageServerError::ProgramsIsNone); @@ -632,7 +630,7 @@ mod tests { let uri = get_url(&dir); let engines = Engines::default(); let result = - parse_project(&uri, None, &engines, None).expect_err("expected ManifestFileNotFound"); + parse_project(&uri, &engines, None).expect_err("expected ManifestFileNotFound"); assert!(matches!( result, LanguageServerError::DocumentError( diff --git a/sway-lsp/src/handlers/notification.rs b/sway-lsp/src/handlers/notification.rs index 7de957bb1bb..ccaaca5555c 100644 --- a/sway-lsp/src/handlers/notification.rs +++ b/sway-lsp/src/handlers/notification.rs @@ -91,7 +91,7 @@ pub async fn handle_did_change_text_document( .await?; //eprintln!("changes for version {:?} have been written to disk", params.text_document.version); send_new_compilation_request( - &state, + state, session.clone(), &uri, Some(params.text_document.version), @@ -111,7 +111,7 @@ pub(crate) async fn handle_did_save_text_document( .await?; session.sync.resync()?; //eprintln!("resynced"); - send_new_compilation_request(&state, session.clone(), &uri, None); + send_new_compilation_request(state, session.clone(), &uri, None); state.wait_for_parsing().await; state .publish_diagnostics(uri, params.text_document.uri, session) diff --git a/sway-lsp/src/server_state.rs b/sway-lsp/src/server_state.rs index 3663597f65b..308c28865dc 100644 --- a/sway-lsp/src/server_state.rs +++ b/sway-lsp/src/server_state.rs @@ -158,7 +158,6 @@ impl ServerState { //eprintln!("THREAD | starting parsing project: version: {:?}", version); match session::parse_project( &uri, - version, &engines_clone, Some(retrigger_compilation.clone()), ) { @@ -176,7 +175,7 @@ impl ServerState { ); *last_compilation_state.write() = LastCompilationState::Success; } - Err(err) => { + Err(_err) => { //eprintln!("compilation has returned cancelled {:?}", err); update_compilation_state( is_compiling.clone(), @@ -232,7 +231,7 @@ impl ServerState { tracing::info!("Shutting Down the Sway Language Server"); // Drain pending compilation requests - while let Ok(_) = self.cb_rx.try_recv() { + while self.cb_rx.try_recv().is_ok() { //eprintln!("draining pending compilation requests"); } // set the retrigger_compilation flag to true so that the compilation exit early