Skip to content

Commit 4aac564

Browse files
JSON Schema URIs (zed-industries#38916)
Closes #ISSUE Improves the efficiency of our interactions with the Zed language server. Previously, on startup and after every workspace configuration changed notification, we would send >1MB of JSON Schemas to the JSON LSP. The only reason this had to happen was due to the case where an extension was installed that would result in a change to the JSON schema for settings (i.e. added language, theme, etc). This PR changes the behavior to use the URI LSP extensions of `vscode-json-language-server` in order to send the server URI's that it can then use to fetch the schemas as needed (i.e. the settings schema is only generated and sent when `settings.json` is opened. This brings the JSON we send to on startup and after every workspace configuration changed notification down to a couple of KB. Additionally, using another LSP extension request we can notify the server when a schema has changed using the URI as a key, so we no longer have to send a workspace configuration changed notification, and the schema contents will only be re-requested and regenerated if the schema is in use. Release Notes: - Improved the efficiency of communication with the builtin JSON LSP. JSON Schemas are no longer sent to the JSON language server in their full form. If you wish to view a builtin JSON schema in the language server info tab of the language server logs (`dev: open language server logs`), you must now use the `editor: open url` action with your cursor over the URL that is sent to the server. - Made it so that Zed urls (`zed://...`) are resolved locally when opened within the editor instead of being resolved through the OS. Users who could not previously open `zed://*` URLs in the editor can now do so by pasting the link into a buffer and using the `editor: open url` action (please open an issue if this is the case for you!). --------- Co-authored-by: Michael <[email protected]>
1 parent 30b49cf commit 4aac564

File tree

28 files changed

+738
-484
lines changed

28 files changed

+738
-484
lines changed

Cargo.lock

Lines changed: 27 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ members = [
9191
"crates/inspector_ui",
9292
"crates/install_cli",
9393
"crates/journal",
94+
"crates/json_schema_store",
9495
"crates/keymap_editor",
9596
"crates/language",
9697
"crates/language_extension",
@@ -322,6 +323,7 @@ zeta2_tools = { path = "crates/zeta2_tools" }
322323
inspector_ui = { path = "crates/inspector_ui" }
323324
install_cli = { path = "crates/install_cli" }
324325
journal = { path = "crates/journal" }
326+
json_schema_store = { path = "crates/json_schema_store" }
325327
keymap_editor = { path = "crates/keymap_editor" }
326328
language = { path = "crates/language" }
327329
language_extension = { path = "crates/language_extension" }
@@ -811,6 +813,7 @@ image_viewer = { codegen-units = 1 }
811813
edit_prediction_button = { codegen-units = 1 }
812814
install_cli = { codegen-units = 1 }
813815
journal = { codegen-units = 1 }
816+
json_schema_store = { codegen-units = 1 }
814817
lmstudio = { codegen-units = 1 }
815818
menu = { codegen-units = 1 }
816819
notifications = { codegen-units = 1 }

crates/dap/src/registry.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ impl DapRegistry {
6464
.and_then(|adapter| adapter.adapter_language_name())
6565
}
6666

67-
pub async fn adapters_schema(&self) -> task::AdapterSchemas {
68-
let mut schemas = AdapterSchemas(vec![]);
67+
pub fn adapters_schema(&self) -> task::AdapterSchemas {
68+
let mut schemas = vec![];
6969

70-
let adapters = self.0.read().adapters.clone();
70+
let adapters = &self.0.read().adapters;
7171

7272
for (name, adapter) in adapters.into_iter() {
73-
schemas.0.push(AdapterSchema {
74-
adapter: name.into(),
73+
schemas.push(AdapterSchema {
74+
adapter: name.clone().into(),
7575
schema: adapter.dap_schema(),
7676
});
7777
}
7878

79-
schemas
79+
AdapterSchemas(schemas)
8080
}
8181

8282
pub fn locators(&self) -> FxHashMap<SharedString, Arc<dyn DapLocator>> {

crates/editor/src/editor.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ use aho_corasick::AhoCorasick;
8383
use anyhow::{Context as _, Result, anyhow};
8484
use blink_manager::BlinkManager;
8585
use buffer_diff::DiffHunkStatus;
86-
use client::{Collaborator, ParticipantIndex};
86+
use client::{Collaborator, ParticipantIndex, parse_zed_link};
8787
use clock::{AGENT_REPLICA_ID, ReplicaId};
8888
use code_context_menus::{
8989
AvailableCodeAction, CodeActionContents, CodeActionsItem, CodeActionsMenu, CodeContextMenu,
@@ -16326,20 +16326,24 @@ impl Editor {
1632616326
None
1632716327
};
1632816328

16329-
let url_finder = cx.spawn_in(window, async move |editor, cx| {
16329+
let url_finder = cx.spawn_in(window, async move |_editor, cx| {
1633016330
let url = if let Some(end_pos) = end_position {
1633116331
find_url_from_range(&buffer, start_position..end_pos, cx.clone())
1633216332
} else {
1633316333
find_url(&buffer, start_position, cx.clone()).map(|(_, url)| url)
1633416334
};
1633516335

1633616336
if let Some(url) = url {
16337-
editor.update(cx, |_, cx| {
16338-
cx.open_url(&url);
16339-
})
16340-
} else {
16341-
Ok(())
16337+
cx.update(|window, cx| {
16338+
if parse_zed_link(&url, cx).is_some() {
16339+
window.dispatch_action(Box::new(zed_actions::OpenZedUrl { url }), cx);
16340+
} else {
16341+
cx.open_url(&url);
16342+
}
16343+
})?;
1634216344
}
16345+
16346+
anyhow::Ok(())
1634316347
});
1634416348

1634516349
url_finder.detach();

crates/extension/src/extension_events.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl ExtensionEvents {
3232
}
3333
}
3434

35-
#[derive(Clone)]
35+
#[derive(Clone, Debug)]
3636
pub enum Event {
3737
ExtensionInstalled(Arc<ExtensionManifest>),
3838
ExtensionUninstalled(Arc<ExtensionManifest>),
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
[package]
2+
name = "json_schema_store"
3+
version = "0.1.0"
4+
edition.workspace = true
5+
publish.workspace = true
6+
license = "GPL-3.0-or-later"
7+
8+
[lints]
9+
workspace = true
10+
11+
[lib]
12+
path = "src/json_schema_store.rs"
13+
14+
[features]
15+
default = []
16+
17+
[dependencies]
18+
anyhow.workspace = true
19+
dap.workspace = true
20+
extension.workspace = true
21+
gpui.workspace = true
22+
language.workspace = true
23+
paths.workspace = true
24+
project.workspace = true
25+
schemars.workspace = true
26+
serde_json.workspace = true
27+
serde.workspace = true
28+
settings.workspace = true
29+
snippet_provider.workspace = true
30+
task.workspace = true
31+
theme.workspace = true
32+
util.workspace = true
33+
workspace-hack.workspace = true
34+
35+
36+
37+
# Uncomment other workspace dependencies as needed
38+
# assistant.workspace = true
39+
# client.workspace = true
40+
# project.workspace = true
41+
# settings.workspace = true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../LICENSE-GPL

0 commit comments

Comments
 (0)