Skip to content

Commit a1ac491

Browse files
committed
Add cwd to debug adapter launch
1 parent 7d83bbd commit a1ac491

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/emmylua.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::fs;
2+
use std::str::FromStr;
23
use zed::lsp::CompletionKind;
34
use zed::{CodeLabel, CodeLabelSpan, LanguageServerId};
45
use zed_extension_api::{self as zed, Result, serde_json::Value};
@@ -278,17 +279,23 @@ impl zed::Extension for EmmyLuaExtension {
278279
fn get_dap_binary(
279280
&mut self,
280281
adapter_name: String,
281-
_config: zed::DebugTaskDefinition,
282+
config: zed::DebugTaskDefinition,
282283
user_provided_debug_adapter_path: Option<String>,
283284
worktree: &zed::Worktree,
284285
) -> std::result::Result<zed::DebugAdapterBinary, String> {
285286
if adapter_name != "emmylua_new" {
286287
return Err(format!("Unknown debug adapter: {}", adapter_name));
287288
}
288289

290+
let cwd = Some(worktree.root_path());
291+
289292
let default_request_args = zed::StartDebuggingRequestArguments {
290-
configuration: Default::default(),
291-
request: zed::StartDebuggingRequestArgumentsRequest::Launch,
293+
configuration: config.config.clone(),
294+
request: self.dap_request_kind(
295+
adapter_name,
296+
Value::from_str(config.config.as_str())
297+
.map_err(|e| format!("Invalid JSON configuration: {e}"))?,
298+
)?,
292299
};
293300

294301
// Check if user provided a custom path
@@ -298,7 +305,7 @@ impl zed::Extension for EmmyLuaExtension {
298305
command: Some(path),
299306
arguments: vec![],
300307
envs: vec![],
301-
cwd: None,
308+
cwd,
302309
connection: None,
303310
request_args: default_request_args,
304311
});
@@ -310,7 +317,7 @@ impl zed::Extension for EmmyLuaExtension {
310317
command: Some(path),
311318
arguments: vec![],
312319
envs: vec![],
313-
cwd: None,
320+
cwd,
314321
connection: None,
315322
request_args: default_request_args,
316323
});
@@ -399,17 +406,21 @@ impl zed::Extension for EmmyLuaExtension {
399406
command: Some(binary_path),
400407
arguments: vec![],
401408
envs: vec![],
402-
cwd: None,
409+
cwd,
403410
connection: None,
404411
request_args: default_request_args,
405412
})
406413
}
407414

408415
fn dap_request_kind(
409416
&mut self,
410-
_adapter_name: String,
417+
adapter_name: String,
411418
config: Value,
412419
) -> std::result::Result<zed::StartDebuggingRequestArgumentsRequest, String> {
420+
if adapter_name != "emmylua_new" {
421+
return Err(format!("Unknown debug adapter: {}", adapter_name));
422+
}
423+
413424
let request_type = config
414425
.get("request")
415426
.and_then(|v| v.as_str())

0 commit comments

Comments
 (0)