Skip to content

Commit 0dbd74b

Browse files
Sync extension debuggers to remote host (cherry-pick #33876) (#33933)
Cherry-picked Sync extension debuggers to remote host (#33876) Closes #33835 Release Notes: - Fixed debugger extensions not working in remote projects. Co-authored-by: Ryan Hawkins <[email protected]>
1 parent 98d2322 commit 0dbd74b

File tree

4 files changed

+77
-11
lines changed

4 files changed

+77
-11
lines changed

crates/extension/src/extension_builder.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::{
2-
ExtensionLibraryKind, ExtensionManifest, GrammarManifestEntry, parse_wasm_extension_version,
2+
ExtensionLibraryKind, ExtensionManifest, GrammarManifestEntry, build_debug_adapter_schema_path,
3+
parse_wasm_extension_version,
34
};
45
use anyhow::{Context as _, Result, bail};
56
use async_compression::futures::bufread::GzipDecoder;
@@ -99,12 +100,8 @@ impl ExtensionBuilder {
99100
}
100101

101102
for (debug_adapter_name, meta) in &mut extension_manifest.debug_adapters {
102-
let debug_adapter_relative_schema_path =
103-
meta.schema_path.clone().unwrap_or_else(|| {
104-
Path::new("debug_adapter_schemas")
105-
.join(Path::new(debug_adapter_name.as_ref()).with_extension("json"))
106-
});
107-
let debug_adapter_schema_path = extension_dir.join(debug_adapter_relative_schema_path);
103+
let debug_adapter_schema_path =
104+
extension_dir.join(build_debug_adapter_schema_path(debug_adapter_name, meta));
108105

109106
let debug_adapter_schema = fs::read_to_string(&debug_adapter_schema_path)
110107
.with_context(|| {

crates/extension/src/extension_manifest.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,16 @@ impl ExtensionManifest {
132132
}
133133
}
134134

135+
pub fn build_debug_adapter_schema_path(
136+
adapter_name: &Arc<str>,
137+
meta: &DebugAdapterManifestEntry,
138+
) -> PathBuf {
139+
meta.schema_path.clone().unwrap_or_else(|| {
140+
Path::new("debug_adapter_schemas")
141+
.join(Path::new(adapter_name.as_ref()).with_extension("json"))
142+
})
143+
}
144+
135145
/// A capability for an extension.
136146
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
137147
#[serde(tag = "kind")]
@@ -320,6 +330,29 @@ mod tests {
320330
}
321331
}
322332

333+
#[test]
334+
fn test_build_adapter_schema_path_with_schema_path() {
335+
let adapter_name = Arc::from("my_adapter");
336+
let entry = DebugAdapterManifestEntry {
337+
schema_path: Some(PathBuf::from("foo/bar")),
338+
};
339+
340+
let path = build_debug_adapter_schema_path(&adapter_name, &entry);
341+
assert_eq!(path, PathBuf::from("foo/bar"));
342+
}
343+
344+
#[test]
345+
fn test_build_adapter_schema_path_without_schema_path() {
346+
let adapter_name = Arc::from("my_adapter");
347+
let entry = DebugAdapterManifestEntry { schema_path: None };
348+
349+
let path = build_debug_adapter_schema_path(&adapter_name, &entry);
350+
assert_eq!(
351+
path,
352+
PathBuf::from("debug_adapter_schemas").join("my_adapter.json")
353+
);
354+
}
355+
323356
#[test]
324357
fn test_allow_exact_match() {
325358
let manifest = ExtensionManifest {

crates/extension_host/src/extension_host.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,6 +1633,23 @@ impl ExtensionStore {
16331633
}
16341634
}
16351635

1636+
for (adapter_name, meta) in loaded_extension.manifest.debug_adapters.iter() {
1637+
let schema_path = &extension::build_debug_adapter_schema_path(adapter_name, meta);
1638+
1639+
if fs.is_file(&src_dir.join(schema_path)).await {
1640+
match schema_path.parent() {
1641+
Some(parent) => fs.create_dir(&tmp_dir.join(parent)).await?,
1642+
None => {}
1643+
}
1644+
fs.copy_file(
1645+
&src_dir.join(schema_path),
1646+
&tmp_dir.join(schema_path),
1647+
fs::CopyOptions::default(),
1648+
)
1649+
.await?
1650+
}
1651+
}
1652+
16361653
Ok(())
16371654
})
16381655
}

crates/extension_host/src/headless_host.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use anyhow::{Context as _, Result};
44
use client::{TypedEnvelope, proto};
55
use collections::{HashMap, HashSet};
66
use extension::{
7-
Extension, ExtensionHostProxy, ExtensionLanguageProxy, ExtensionLanguageServerProxy,
8-
ExtensionManifest,
7+
Extension, ExtensionDebugAdapterProviderProxy, ExtensionHostProxy, ExtensionLanguageProxy,
8+
ExtensionLanguageServerProxy, ExtensionManifest,
99
};
1010
use fs::{Fs, RemoveOptions, RenameOptions};
1111
use gpui::{App, AppContext as _, AsyncApp, Context, Entity, Task, WeakEntity};
@@ -169,8 +169,9 @@ impl HeadlessExtensionStore {
169169
return Ok(());
170170
}
171171

172-
let wasm_extension: Arc<dyn Extension> =
173-
Arc::new(WasmExtension::load(extension_dir, &manifest, wasm_host.clone(), &cx).await?);
172+
let wasm_extension: Arc<dyn Extension> = Arc::new(
173+
WasmExtension::load(extension_dir.clone(), &manifest, wasm_host.clone(), &cx).await?,
174+
);
174175

175176
for (language_server_id, language_server_config) in &manifest.language_servers {
176177
for language in language_server_config.languages() {
@@ -186,6 +187,24 @@ impl HeadlessExtensionStore {
186187
);
187188
})?;
188189
}
190+
for (debug_adapter, meta) in &manifest.debug_adapters {
191+
let schema_path = extension::build_debug_adapter_schema_path(debug_adapter, meta);
192+
193+
this.update(cx, |this, _cx| {
194+
this.proxy.register_debug_adapter(
195+
wasm_extension.clone(),
196+
debug_adapter.clone(),
197+
&extension_dir.join(schema_path),
198+
);
199+
})?;
200+
}
201+
202+
for debug_adapter in manifest.debug_locators.keys() {
203+
this.update(cx, |this, _cx| {
204+
this.proxy
205+
.register_debug_locator(wasm_extension.clone(), debug_adapter.clone());
206+
})?;
207+
}
189208
}
190209

191210
Ok(())

0 commit comments

Comments
 (0)