From fbe92d4228ba71101da3045eab6d1d22e709685f Mon Sep 17 00:00:00 2001 From: JoshuaBatty Date: Sat, 21 Sep 2024 13:39:42 +1000 Subject: [PATCH 1/3] fix oob concurrent slab panic when creating runnables on a did save event --- sway-lsp/src/core/session.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/sway-lsp/src/core/session.rs b/sway-lsp/src/core/session.rs index 7f4ed2a9153..34bc75bbccc 100644 --- a/sway-lsp/src/core/session.rs +++ b/sway-lsp/src/core/session.rs @@ -465,6 +465,7 @@ pub fn parse_project( } let diagnostics = traverse(results, engines, session.clone(), lsp_mode.as_ref())?; + eprintln!("diagnostics: {:?}", diagnostics); if let Some(config) = &lsp_mode { // Only write the diagnostics results on didSave or didOpen. if !config.optimized_build { @@ -477,7 +478,18 @@ pub fn parse_project( if let Some(typed) = &session.compiled_program.read().typed { session.runnables.clear(); - create_runnables(&session.runnables, typed, engines.de(), engines.se()); + let path = uri.to_file_path().unwrap(); + let program_id = program_id_from_path(&path, engines)?; + if let Some(metrics) = session.metrics.get(&program_id) { + // Check if the cached AST was returned by the compiler for the users workspace. + // If it was, then we need to use the original engines. + let engines = if metrics.reused_programs > 0 { + &*session.engines.read() + } else { + engines + }; + create_runnables(&session.runnables, typed, engines.de(), engines.se()); + } } Ok(()) } From 39f8063ce2542d310fe839d8ea833092b9e61fdb Mon Sep 17 00:00:00 2001 From: JoshuaBatty Date: Sat, 21 Sep 2024 14:32:46 +1000 Subject: [PATCH 2/3] remove print --- sway-lsp/src/core/session.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/sway-lsp/src/core/session.rs b/sway-lsp/src/core/session.rs index 34bc75bbccc..c55869d5f66 100644 --- a/sway-lsp/src/core/session.rs +++ b/sway-lsp/src/core/session.rs @@ -465,7 +465,6 @@ pub fn parse_project( } let diagnostics = traverse(results, engines, session.clone(), lsp_mode.as_ref())?; - eprintln!("diagnostics: {:?}", diagnostics); if let Some(config) = &lsp_mode { // Only write the diagnostics results on didSave or didOpen. if !config.optimized_build { From 8cc50625da39660160b321d7de5a4d76a71c9933 Mon Sep 17 00:00:00 2001 From: JoshuaBatty Date: Sat, 21 Sep 2024 14:43:47 +1000 Subject: [PATCH 3/3] temp disable optimised builds from did_change events --- sway-lsp/src/handlers/notification.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sway-lsp/src/handlers/notification.rs b/sway-lsp/src/handlers/notification.rs index 928262efb51..7c7dfddf7cc 100644 --- a/sway-lsp/src/handlers/notification.rs +++ b/sway-lsp/src/handlers/notification.rs @@ -111,7 +111,8 @@ pub async fn handle_did_change_text_document( session.clone(), &uri, Some(params.text_document.version), - true, + // TODO: Set this back to true once https://github.com/FuelLabs/sway/issues/6576 is fixed. + false, file_versions, ); Ok(())