Skip to content

Commit

Permalink
Show error when attach request is selected but not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
RemcoSmitsDev committed Nov 2, 2024
1 parent b04ca64 commit 4b4831b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions crates/dap/src/adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,12 @@ pub trait DebugAdapter: 'static + Send + Sync {
/// Should return base configuration to make the debug adapter work
fn request_args(&self, config: &DebugAdapterConfig) -> Value;

/// Whether the adapter supports `attach` request,
/// if not support and the request is selected we will show an error message
fn supports_attach(&self) -> bool {
false
}

/// Filters out the processes that the adapter can attach to for debugging
fn attach_processes<'a>(
&self,
Expand Down
4 changes: 4 additions & 0 deletions crates/dap_adapters/src/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ impl DebugAdapter for JsDebugAdapter {
})
}

fn supports_attach(&self) -> bool {
true
}

fn attach_processes<'a>(
&self,
processes: &'a HashMap<Pid, Process>,
Expand Down
6 changes: 6 additions & 0 deletions crates/project/src/dap_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@ impl DapStore {
.context("Creating debug adapter")?,
);

if !adapter.supports_attach()
&& matches!(config.request, DebugRequestType::Attach(_))
{
return Err(anyhow!("Debug adapter does not support `attach` request"));
}

let path = cx.update(|cx| {
let name = LanguageServerName::from(adapter.name().as_ref());

Expand Down

0 comments on commit 4b4831b

Please sign in to comment.