diff --git a/crates/project/src/debugger/dap_command.rs b/crates/project/src/debugger/dap_command.rs index f6386c46f5..fba9414c56 100644 --- a/crates/project/src/debugger/dap_command.rs +++ b/crates/project/src/debugger/dap_command.rs @@ -17,6 +17,7 @@ use util::ResultExt; pub(crate) trait LocalDapCommand: 'static + Send + Sync + std::fmt::Debug { type Response: 'static + Send + std::fmt::Debug; type DapRequest: 'static + Send + dap::requests::Request; + const CACHEABLE: bool = false; fn is_supported(_capabilities: &Capabilities) -> bool { true @@ -843,6 +844,7 @@ pub struct VariablesCommand { impl LocalDapCommand for VariablesCommand { type Response = Vec; type DapRequest = dap::requests::Variables; + const CACHEABLE: bool = true; fn to_dap(&self) -> ::Arguments { dap::VariablesArguments { @@ -1069,6 +1071,7 @@ pub(crate) struct ModulesCommand; impl LocalDapCommand for ModulesCommand { type Response = Vec; type DapRequest = dap::requests::Modules; + const CACHEABLE: bool = true; fn is_supported(capabilities: &Capabilities) -> bool { capabilities.supports_modules_request.unwrap_or_default() @@ -1142,6 +1145,8 @@ pub(crate) struct LoadedSourcesCommand; impl LocalDapCommand for LoadedSourcesCommand { type Response = Vec; type DapRequest = dap::requests::LoadedSources; + const CACHEABLE: bool = true; + fn is_supported(capabilities: &Capabilities) -> bool { capabilities .supports_loaded_sources_request @@ -1216,6 +1221,7 @@ pub(crate) struct StackTraceCommand { impl LocalDapCommand for StackTraceCommand { type Response = Vec; type DapRequest = dap::requests::StackTrace; + const CACHEABLE: bool = true; fn to_dap(&self) -> ::Arguments { dap::StackTraceArguments { @@ -1289,6 +1295,7 @@ pub(crate) struct ScopesCommand { impl LocalDapCommand for ScopesCommand { type Response = Vec; type DapRequest = dap::requests::Scopes; + const CACHEABLE: bool = true; fn to_dap(&self) -> ::Arguments { dap::ScopesArguments { @@ -1347,6 +1354,7 @@ impl DapCommand for ScopesCommand { impl LocalDapCommand for super::session::CompletionsQuery { type Response = dap::CompletionsResponse; type DapRequest = dap::requests::Completions; + const CACHEABLE: bool = true; fn to_dap(&self) -> ::Arguments { dap::CompletionsArguments { @@ -1512,6 +1520,7 @@ pub(crate) struct ThreadsCommand; impl LocalDapCommand for ThreadsCommand { type Response = Vec; type DapRequest = dap::requests::Threads; + const CACHEABLE: bool = true; fn to_dap(&self) -> ::Arguments { () diff --git a/crates/project/src/debugger/session.rs b/crates/project/src/debugger/session.rs index 0538de36c2..43897dbb6f 100644 --- a/crates/project/src/debugger/session.rs +++ b/crates/project/src/debugger/session.rs @@ -787,6 +787,12 @@ impl Session { process_result: impl FnOnce(&mut Self, &T::Response, &mut Context) + 'static, cx: &mut Context, ) { + const { + assert!( + T::CACHEABLE, + "Only requests marked as cacheable should invoke `fetch`" + ); + } if let Entry::Vacant(vacant) = self.requests.entry(request.into()) { let command = vacant.key().0.clone().as_any_arc().downcast::().unwrap();