Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Merge branch 'main' into window_context_2

Antonio Scandurrac76b9794e4df
diff --cc crates/copilot/src/sign_in.rs
index e67f1b3e431,3b949217bc7..c57a476f36a
--- a/crates/copilot/src/sign_in.rs
+++ b/crates/copilot/src/sign_in.rs
@@@ -24,55 -23,51 +24,57 @@@ struct OpenGithub
const COPILOT_SIGN_UP_URL: &'static str = "https://github.com/features/copilot";
pub fn init(cx: &mut AppContext) {
- let copilot = Copilot::global(cx).unwrap();
+ if let Some(copilot) = Copilot::global(cx) {
+ let mut code_verification: Option<ViewHandle<CopilotCodeVerification>> = None;
+ cx.observe(&copilot, move |copilot, cx| {
+ let status = copilot.read(cx).status();
- let mut code_verification: Option<ViewHandle<CopilotCodeVerification>> = None;
- cx.observe(&copilot, move |copilot, cx| {
- let status = copilot.read(cx).status();
-
- match &status {
- crate::Status::SigningIn { prompt } => {
- if let Some(code_verification) = code_verification.as_mut() {
- if cx.has_window(code_verification.window_id()) {
- cx.update_window(code_verification.window_id(), |cx| {
- code_verification.update(cx, |code_verification_view, cx| {
- code_verification_view.set_status(status, cx);
+ match &status {
+ crate::Status::SigningIn { prompt } => {
+ if let Some(code_verification_handle) = code_verification.as_mut() {
- if cx.has_window(code_verification_handle.window_id()) {
- code_verification_handle.update(cx, |code_verification_view, cx| {
- code_verification_view.set_status(status, cx)
++ let window_id = code_verification_handle.window_id();
++ if cx.has_window(window_id) {
++ cx.update_window(window_id, |cx| {
++ code_verification_handle.update(cx, |code_verification, cx| {
++ code_verification.set_status(status, cx)
++ });
+ cx.activate_window();
});
- });
- } else {
- *code_verification = create_copilot_auth_window(cx, &status);
- cx.activate_window(code_verification_handle.window_id());
+ } else {
- create_copilot_auth_window(cx, &status, &mut code_verification);
++ code_verification = Some(create_copilot_auth_window(cx, &status));
+ }
+ } else if let Some(_prompt) = prompt {
- create_copilot_auth_window(cx, &status, &mut code_verification);
++ code_verification = Some(create_copilot_auth_window(cx, &status));
}
- } else if let Some(_prompt) = prompt {
- code_verification = Some(create_copilot_auth_window(cx, &status));
}
- }
- Status::Authorized | Status::Unauthorized => {
- if let Some(code_verification) = code_verification.as_ref() {
- cx.update_window(code_verification.window_id(), |cx| {
- code_verification.update(cx, |code_verification, cx| {
- code_verification.set_status(status, cx);
+ Status::Authorized | Status::Unauthorized => {
+ if let Some(code_verification) = code_verification.as_ref() {
- code_verification.update(cx, |code_verification, cx| {
- code_verification.set_status(status, cx)
- });
++ let window_id = code_verification.window_id();
++ cx.update_window(window_id, |cx| {
++ code_verification.update(cx, |code_verification, cx| {
++ code_verification.set_status(status, cx)
++ });
+
- cx.platform().activate(true);
- cx.activate_window(code_verification.window_id());
++ cx.platform().activate(true);
+ cx.activate_window();
+ });
-
- cx.platform().activate(true);
- });
+ }
}
- }
- _ => {
- if let Some(code_verification) = code_verification.take() {
- cx.remove_window(code_verification.window_id());
+ _ => {
+ if let Some(code_verification) = code_verification.take() {
+ cx.remove_window(code_verification.window_id());
+ }
}
}
- }
- })
- .detach();
+ })
+ .detach();
- cx.add_action(
- |code_verification: &mut CopilotCodeVerification, _: &ClickedConnect, _| {
- code_verification.connect_clicked = true;
- },
- );
+ cx.add_action(
+ |code_verification: &mut CopilotCodeVerification, _: &ClickedConnect, _| {
+ code_verification.connect_clicked = true;
+ },
+ );
+ }
}
fn create_copilot_auth_window(
diff --cc crates/diagnostics/src/diagnostics.rs
index 42f97ae3485,a2793b1fff5..99d2984f8e1
--- a/crates/diagnostics/src/diagnostics.rs
+++ b/crates/diagnostics/src/diagnostics.rs
@@@ -214,7 -221,9 +220,9 @@@ impl ProjectDiagnosticsEditor
let buffer = project
.update(&mut cx, |project, cx| project.open_buffer(path.clone(), cx))
.await?;
- this.update(&mut cx, |this, cx| this.populate_excerpts(path, buffer, cx))?;
+ this.update(&mut cx, |this, cx| {
+ this.populate_excerpts(path, language_server_id, buffer, cx)
- })
++ })?;
}
Result::<_, anyhow::Error>::Ok(())
}
@@@ -770,11 -796,11 +795,11 @@@ mod tests
display_map::{BlockContext, TransformBlock},
DisplayPoint,
};
- use gpui::TestAppContext;
+ use gpui::{TestAppContext, WindowContext};
use language::{Diagnostic, DiagnosticEntry, DiagnosticSeverity, PointUtf16, Unclipped};
+ use project::FakeFs;
use serde_json::json;
use unindent::Unindent as _;
- use workspace::AppState;
#[gpui::test]
async fn test_diagnostics(cx: &mut TestAppContext) {
@@@ -1180,8 -1205,276 +1204,274 @@@
});
}
+ #[gpui::test]
+ async fn test_diagnostics_multiple_servers(cx: &mut TestAppContext) {
+ Settings::test_async(cx);
+ let fs = FakeFs::new(cx.background());
+ fs.insert_tree(
+ "/test",
+ json!({
+ "main.js": "
+ a();
+ b();
+ c();
+ d();
+ e();
+ ".unindent()
+ }),
+ )
+ .await;
+
+ let server_id_1 = LanguageServerId(100);
+ let server_id_2 = LanguageServerId(101);
+ let project = Project::test(fs.clone(), ["/test".as_ref()], cx).await;
+ let (_, workspace) = cx.add_window(|cx| Workspace::test_new(project.clone(), cx));
+
+ let view = cx.add_view(&workspace, |cx| {
+ ProjectDiagnosticsEditor::new(project.clone(), workspace.downgrade(), cx)
+ });
+
+ // Two language servers start updating diagnostics
+ project.update(cx, |project, cx| {
+ project.disk_based_diagnostics_started(server_id_1, cx);
+ project.disk_based_diagnostics_started(server_id_2, cx);
+ project
+ .update_diagnostic_entries(
+ server_id_1,
+ PathBuf::from("/test/main.js"),
+ None,
+ vec![DiagnosticEntry {
+ range: Unclipped(PointUtf16::new(0, 0))..Unclipped(PointUtf16::new(0, 1)),
+ diagnostic: Diagnostic {
+ message: "error 1".to_string(),
+ severity: DiagnosticSeverity::WARNING,
+ is_primary: true,
+ is_disk_based: true,
+ group_id: 1,
+ ..Default::default()
+ },
+ }],
+ cx,
+ )
+ .unwrap();
+ project
+ .update_diagnostic_entries(
+ server_id_2,
+ PathBuf::from("/test/main.js"),
+ None,
+ vec![DiagnosticEntry {
+ range: Unclipped(PointUtf16::new(1, 0))..Unclipped(PointUtf16::new(1, 1)),
+ diagnostic: Diagnostic {
+ message: "warning 1".to_string(),
+ severity: DiagnosticSeverity::ERROR,
+ is_primary: true,
+ is_disk_based: true,
+ group_id: 2,
+ ..Default::default()
+ },
+ }],
+ cx,
+ )
+ .unwrap();
+ });
+
+ // The first language server finishes
+ project.update(cx, |project, cx| {
+ project.disk_based_diagnostics_finished(server_id_1, cx);
+ });
+
+ // Only the first language server's diagnostics are shown.
+ cx.foreground().run_until_parked();
+ view.update(cx, |view, cx| {
+ assert_eq!(
+ editor_blocks(&view.editor, cx),
+ [
+ (0, "path header block".into()),
+ (2, "diagnostic header".into()),
+ ]
+ );
+ assert_eq!(
+ view.editor.update(cx, |editor, cx| editor.display_text(cx)),
+ concat!(
+ "\n", // filename
+ "\n", // padding
+ // diagnostic group 1
+ "\n", // primary message
+ "\n", // padding
+ "a();\n", //
+ "b();",
+ )
+ );
+ });
+
+ // The second language server finishes
+ project.update(cx, |project, cx| {
+ project.disk_based_diagnostics_finished(server_id_2, cx);
+ });
+
+ // Both language server's diagnostics are shown.
+ cx.foreground().run_until_parked();
+ view.update(cx, |view, cx| {
+ assert_eq!(
+ editor_blocks(&view.editor, cx),
+ [
+ (0, "path header block".into()),
+ (2, "diagnostic header".into()),
+ (6, "collapsed context".into()),
+ (7, "diagnostic header".into()),
+ ]
+ );
+ assert_eq!(
+ view.editor.update(cx, |editor, cx| editor.display_text(cx)),
+ concat!(
+ "\n", // filename
+ "\n", // padding
+ // diagnostic group 1
+ "\n", // primary message
+ "\n", // padding
+ "a();\n", // location
+ "b();\n", //
+ "\n", // collapsed context
+ // diagnostic group 2
+ "\n", // primary message
+ "\n", // padding
+ "a();\n", // context
+ "b();\n", //
+ "c();", // context
+ )
+ );
+ });
+
+ // Both language servers start updating diagnostics, and the first server finishes.
+ project.update(cx, |project, cx| {
+ project.disk_based_diagnostics_started(server_id_1, cx);
+ project.disk_based_diagnostics_started(server_id_2, cx);
+ project
+ .update_diagnostic_entries(
+ server_id_1,
+ PathBuf::from("/test/main.js"),
+ None,
+ vec![DiagnosticEntry {
+ range: Unclipped(PointUtf16::new(2, 0))..Unclipped(PointUtf16::new(2, 1)),
+ diagnostic: Diagnostic {
+ message: "warning 2".to_string(),
+ severity: DiagnosticSeverity::WARNING,
+ is_primary: true,
+ is_disk_based: true,
+ group_id: 1,
+ ..Default::default()
+ },
+ }],
+ cx,
+ )
+ .unwrap();
+ project
+ .update_diagnostic_entries(
+ server_id_2,
+ PathBuf::from("/test/main.rs"),
+ None,
+ vec![],
+ cx,
+ )
+ .unwrap();
+ project.disk_based_diagnostics_finished(server_id_1, cx);
+ });
+
+ // Only the first language server's diagnostics are updated.
+ cx.foreground().run_until_parked();
+ view.update(cx, |view, cx| {
+ assert_eq!(
+ editor_blocks(&view.editor, cx),
+ [
+ (0, "path header block".into()),
+ (2, "diagnostic header".into()),
+ (7, "collapsed context".into()),
+ (8, "diagnostic header".into()),
+ ]
+ );
+ assert_eq!(
+ view.editor.update(cx, |editor, cx| editor.display_text(cx)),
+ concat!(
+ "\n", // filename
+ "\n", // padding
+ // diagnostic group 1
+ "\n", // primary message
+ "\n", // padding
+ "a();\n", // location
+ "b();\n", //
+ "c();\n", // context
+ "\n", // collapsed context
+ // diagnostic group 2
+ "\n", // primary message
+ "\n", // padding
+ "b();\n", // context
+ "c();\n", //
+ "d();", // context
+ )
+ );
+ });
+
+ // The second language server finishes.
+ project.update(cx, |project, cx| {
+ project
+ .update_diagnostic_entries(
+ server_id_2,
+ PathBuf::from("/test/main.js"),
+ None,
+ vec![DiagnosticEntry {
+ range: Unclipped(PointUtf16::new(3, 0))..Unclipped(PointUtf16::new(3, 1)),
+ diagnostic: Diagnostic {
+ message: "warning 2".to_string(),
+ severity: DiagnosticSeverity::WARNING,
+ is_primary: true,
+ is_disk_based: true,
+ group_id: 1,
+ ..Default::default()
+ },
+ }],
+ cx,
+ )
+ .unwrap();
+ project.disk_based_diagnostics_finished(server_id_2, cx);
+ });
+
+ // Both language servers' diagnostics are updated.
+ cx.foreground().run_until_parked();
+ view.update(cx, |view, cx| {
+ assert_eq!(
+ editor_blocks(&view.editor, cx),
+ [
+ (0, "path header block".into()),
+ (2, "diagnostic header".into()),
+ (7, "collapsed context".into()),
+ (8, "diagnostic header".into()),
+ ]
+ );
+ assert_eq!(
+ view.editor.update(cx, |editor, cx| editor.display_text(cx)),
+ concat!(
+ "\n", // filename
+ "\n", // padding
+ // diagnostic group 1
+ "\n", // primary message
+ "\n", // padding
+ "b();\n", // location
+ "c();\n", //
+ "d();\n", // context
+ "\n", // collapsed context
+ // diagnostic group 2
+ "\n", // primary message
+ "\n", // padding
+ "c();\n", // context
+ "d();\n", //
+ "e();", // context
+ )
+ );
+ });
+ }
+
- fn editor_blocks(editor: &ViewHandle<Editor>, cx: &mut AppContext) -> Vec<(u32, String)> {
- let mut presenter = cx.build_presenter(editor.id(), 0., Default::default());
- let mut cx = presenter.build_layout_context(Default::default(), false, cx);
- cx.render(editor, |editor, cx| {
+ fn editor_blocks(editor: &ViewHandle<Editor>, cx: &mut WindowContext) -> Vec<(u32, String)> {
+ editor.update(cx, |editor, cx| {
let snapshot = editor.snapshot(cx);
snapshot
.blocks_in_range(0..snapshot.max_point().row())
diff --cc crates/diagnostics/src/items.rs
index 7e7cdf43dd7,65b42ab3d43..333f5c843e2
--- a/crates/diagnostics/src/items.rs
+++ b/crates/diagnostics/src/items.rs
@@@ -3,10 -3,11 +3,11 @@@ use editor::{Editor, GoToDiagnostic}
use gpui::{
elements::*,
platform::{CursorStyle, MouseButton},
- serde_json, AppContext, Entity, ModelHandle, RenderContext, Subscription, View, ViewContext,
- ViewHandle, WeakViewHandle,
+ serde_json, AppContext, Entity, ModelHandle, Subscription, View, ViewContext, ViewHandle,
+ WeakViewHandle,
};
use language::Diagnostic;
+ use lsp::LanguageServerId;
use project::Project;
use settings::Settings;
use workspace::{item::ItemHandle, StatusItemView};