Skip to content

Commit

Permalink
Merge branch 'zed-industries:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
diocletiann authored Mar 4, 2024
2 parents 2b21c58 + 20acc12 commit 6047708
Show file tree
Hide file tree
Showing 33 changed files with 2,393 additions and 212 deletions.
664 changes: 515 additions & 149 deletions Cargo.lock

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,17 @@ wasmtime-wasi = "18.0"
which = "6.0.0"
sys-locale = "0.3.1"

[workspace.dependencies.windows]
version = "0.53.0"
features = [
"Win32_Graphics_Gdi",
"Win32_UI_WindowsAndMessaging",
"Win32_Security",
"Win32_System_Threading",
]



[patch.crates-io]
tree-sitter = { git = "https://github.com/tree-sitter/tree-sitter", rev = "e4a23971ec3071a09c1e84816954c98f96e98e52" }
# Workaround for a broken nightly build of gpui: See #7644 and revisit once 0.5.3 is released.
Expand Down
1 change: 1 addition & 0 deletions assets/keymaps/default-linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,7 @@
"ctrl-alt-b": "branches::OpenRecent",
"ctrl-~": "workspace::NewTerminal",
"ctrl-s": "workspace::Save",
"ctrl-k s": "workspace::SaveWithoutFormat",
"ctrl-shift-s": "workspace::SaveAs",
"ctrl-n": "workspace::NewFile",
"ctrl-shift-n": "workspace::NewWindow",
Expand Down
3 changes: 2 additions & 1 deletion assets/keymaps/default-macos.json
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@
"alt-cmd-b": "branches::OpenRecent",
"ctrl-~": "workspace::NewTerminal",
"cmd-s": "workspace::Save",
"cmd-k s": "workspace::SaveWithoutFormat",
"cmd-shift-s": "workspace::SaveAs",
"cmd-n": "workspace::NewFile",
"cmd-shift-n": "workspace::NewWindow",
Expand All @@ -426,8 +427,8 @@
"cmd-j": "workspace::ToggleBottomDock",
"alt-cmd-y": "workspace::CloseAllDocks",
"cmd-shift-f": "pane::DeploySearch",
"cmd-k cmd-t": "theme_selector::Toggle",
"cmd-k cmd-s": "zed::OpenKeymap",
"cmd-k cmd-t": "theme_selector::Toggle",
"cmd-t": "project_symbols::Toggle",
"cmd-p": "file_finder::Toggle",
"cmd-shift-p": "command_palette::Toggle",
Expand Down
9 changes: 7 additions & 2 deletions crates/diagnostics/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,8 +735,13 @@ impl Item for ProjectDiagnosticsEditor {
true
}

fn save(&mut self, project: Model<Project>, cx: &mut ViewContext<Self>) -> Task<Result<()>> {
self.editor.save(project, cx)
fn save(
&mut self,
format: bool,
project: Model<Project>,
cx: &mut ViewContext<Self>,
) -> Task<Result<()>> {
self.editor.save(format, project, cx)
}

fn save_as(
Expand Down
12 changes: 6 additions & 6 deletions crates/editor/src/editor_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5265,7 +5265,7 @@ async fn test_document_format_during_save(cx: &mut gpui::TestAppContext) {
assert!(cx.read(|cx| editor.is_dirty(cx)));

let save = editor
.update(cx, |editor, cx| editor.save(project.clone(), cx))
.update(cx, |editor, cx| editor.save(true, project.clone(), cx))
.unwrap();
fake_server
.handle_request::<lsp::request::Formatting, _, _>(move |params, _| async move {
Expand Down Expand Up @@ -5303,7 +5303,7 @@ async fn test_document_format_during_save(cx: &mut gpui::TestAppContext) {
unreachable!()
});
let save = editor
.update(cx, |editor, cx| editor.save(project.clone(), cx))
.update(cx, |editor, cx| editor.save(true, project.clone(), cx))
.unwrap();
cx.executor().advance_clock(super::FORMAT_TIMEOUT);
cx.executor().start_waiting();
Expand All @@ -5326,7 +5326,7 @@ async fn test_document_format_during_save(cx: &mut gpui::TestAppContext) {
});

let save = editor
.update(cx, |editor, cx| editor.save(project.clone(), cx))
.update(cx, |editor, cx| editor.save(true, project.clone(), cx))
.unwrap();
fake_server
.handle_request::<lsp::request::Formatting, _, _>(move |params, _| async move {
Expand Down Expand Up @@ -5379,7 +5379,7 @@ async fn test_range_format_during_save(cx: &mut gpui::TestAppContext) {
assert!(cx.read(|cx| editor.is_dirty(cx)));

let save = editor
.update(cx, |editor, cx| editor.save(project.clone(), cx))
.update(cx, |editor, cx| editor.save(true, project.clone(), cx))
.unwrap();
fake_server
.handle_request::<lsp::request::RangeFormatting, _, _>(move |params, _| async move {
Expand Down Expand Up @@ -5418,7 +5418,7 @@ async fn test_range_format_during_save(cx: &mut gpui::TestAppContext) {
},
);
let save = editor
.update(cx, |editor, cx| editor.save(project.clone(), cx))
.update(cx, |editor, cx| editor.save(true, project.clone(), cx))
.unwrap();
cx.executor().advance_clock(super::FORMAT_TIMEOUT);
cx.executor().start_waiting();
Expand All @@ -5441,7 +5441,7 @@ async fn test_range_format_during_save(cx: &mut gpui::TestAppContext) {
});

let save = editor
.update(cx, |editor, cx| editor.save(project.clone(), cx))
.update(cx, |editor, cx| editor.save(true, project.clone(), cx))
.unwrap();
fake_server
.handle_request::<lsp::request::RangeFormatting, _, _>(move |params, _| async move {
Expand Down
17 changes: 12 additions & 5 deletions crates/editor/src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,14 +702,21 @@ impl Item for Editor {
}
}

fn save(&mut self, project: Model<Project>, cx: &mut ViewContext<Self>) -> Task<Result<()>> {
fn save(
&mut self,
format: bool,
project: Model<Project>,
cx: &mut ViewContext<Self>,
) -> Task<Result<()>> {
self.report_editor_event("save", None, cx);
let buffers = self.buffer().clone().read(cx).all_buffers();
cx.spawn(|this, mut cx| async move {
this.update(&mut cx, |this, cx| {
this.perform_format(project.clone(), FormatTrigger::Save, cx)
})?
.await?;
if format {
this.update(&mut cx, |this, cx| {
this.perform_format(project.clone(), FormatTrigger::Save, cx)
})?
.await?;
}

if buffers.len() == 1 {
project
Expand Down
21 changes: 14 additions & 7 deletions crates/gpui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,31 @@ media.workspace = true
metal = "0.25"
objc = "0.2"

[target.'cfg(target_os = "linux")'.dependencies]
[target.'cfg(any(target_os = "linux", target_os = "windows"))'.dependencies]
flume = "0.11"
#TODO: use these on all platforms
blade-graphics.workspace = true
blade-macros.workspace = true
blade-rwh.workspace = true
bytemuck = "1"
cosmic-text = "0.10.0"

[target.'cfg(target_os = "linux")'.dependencies]
open = "5.0.1"
ashpd = "0.7.0"
xcb = { version = "1.3", features = ["as-raw-xcb-connection", "randr", "xkb"] }
wayland-client= { version = "0.31.2" }
wayland-cursor = "0.31.1"
wayland-protocols = { version = "0.31.2", features = ["client", "staging", "unstable"] }
wayland-backend = { version = "0.3.3", features = ["client_system"] }
xkbcommon = { version = "0.7", features = ["wayland", "x11"] }
as-raw-xcb-connection = "1"
calloop = "0.12.4"
calloop-wayland-source = "0.2.0"
#TODO: use these on all platforms
blade-graphics.workspace = true
blade-macros.workspace = true
blade-rwh.workspace = true
bytemuck = "1"
cosmic-text = "0.10.0"
oo7 = "0.3.0"

[target.'cfg(windows)'.dependencies]
windows.workspace = true

[[example]]
name = "hello_world"
Expand Down
9 changes: 7 additions & 2 deletions crates/gpui/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ mod linux;
#[cfg(target_os = "macos")]
mod mac;

#[cfg(any(target_os = "linux", feature = "macos-blade"))]
#[cfg(any(target_os = "linux", target_os = "windows", feature = "macos-blade"))]
mod blade;

#[cfg(any(test, feature = "test-support"))]
mod test;

#[cfg(target_os = "windows")]
mod windows;

use crate::{
Action, AnyWindowHandle, AsyncWindowContext, BackgroundExecutor, Bounds, DevicePixels, Font,
FontId, FontMetrics, FontRun, ForegroundExecutor, GlobalPixels, GlyphId, Keymap, LineLayout,
Expand Down Expand Up @@ -54,6 +57,8 @@ pub(crate) use mac::*;
pub(crate) use test::*;
use time::UtcOffset;
pub use util::SemanticVersion;
#[cfg(target_os = "windows")]
pub(crate) use windows::*;

#[cfg(target_os = "macos")]
pub(crate) fn current_platform() -> Rc<dyn Platform> {
Expand All @@ -66,7 +71,7 @@ pub(crate) fn current_platform() -> Rc<dyn Platform> {
// todo("windows")
#[cfg(target_os = "windows")]
pub(crate) fn current_platform() -> Rc<dyn Platform> {
unimplemented!()
Rc::new(WindowsPlatform::new())
}

pub(crate) trait Platform: 'static {
Expand Down
3 changes: 2 additions & 1 deletion crates/gpui/src/platform/linux/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::rc::Rc;

use crate::platform::PlatformWindow;
use crate::{AnyWindowHandle, DisplayId, PlatformDisplay, WindowOptions};
use crate::{AnyWindowHandle, CursorStyle, DisplayId, PlatformDisplay, WindowOptions};

pub trait Client {
fn displays(&self) -> Vec<Rc<dyn PlatformDisplay>>;
Expand All @@ -11,4 +11,5 @@ pub trait Client {
handle: AnyWindowHandle,
options: WindowOptions,
) -> Box<dyn PlatformWindow>;
fn set_cursor_style(&self, style: CursorStyle);
}
80 changes: 73 additions & 7 deletions crates/gpui/src/platform/linux/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
time::Duration,
};

use anyhow::anyhow;
use ashpd::desktop::file_chooser::{OpenFileRequest, SaveFileRequest};
use async_task::Runnable;
use calloop::{EventLoop, LoopHandle, LoopSignal};
Expand Down Expand Up @@ -107,6 +108,8 @@ impl LinuxPlatform {
}
}

const KEYRING_LABEL: &str = "zed-github-account";

impl Platform for LinuxPlatform {
fn background_executor(&self) -> BackgroundExecutor {
self.inner.background_executor.clone()
Expand Down Expand Up @@ -321,8 +324,11 @@ impl Platform for LinuxPlatform {
})
}

//todo!(linux)
fn app_path(&self) -> Result<PathBuf> {
unimplemented!()
Err(anyhow::Error::msg(
"Platform<LinuxPlatform>::app_path is not implemented yet",
))
}

// todo(linux)
Expand All @@ -332,12 +338,16 @@ impl Platform for LinuxPlatform {
UtcOffset::UTC
}

//todo!(linux)
fn path_for_auxiliary_executable(&self, name: &str) -> Result<PathBuf> {
unimplemented!()
Err(anyhow::Error::msg(
"Platform<LinuxPlatform>::path_for_auxiliary_executable is not implemented yet",
))
}

// todo(linux)
fn set_cursor_style(&self, style: CursorStyle) {}
fn set_cursor_style(&self, style: CursorStyle) {
self.client.set_cursor_style(style)
}

// todo(linux)
fn should_auto_hide_scrollbars(&self) -> bool {
Expand All @@ -352,16 +362,72 @@ impl Platform for LinuxPlatform {
None
}

//todo!(linux)
fn write_credentials(&self, url: &str, username: &str, password: &[u8]) -> Task<Result<()>> {
unimplemented!()
let url = url.to_string();
let username = username.to_string();
let password = password.to_vec();
self.background_executor().spawn(async move {
let keyring = oo7::Keyring::new().await?;
keyring.unlock().await?;
keyring
.create_item(
KEYRING_LABEL,
&vec![("url", &url), ("username", &username)],
password,
true,
)
.await?;
Ok(())
})
}

//todo!(linux)
fn read_credentials(&self, url: &str) -> Task<Result<Option<(String, Vec<u8>)>>> {
unimplemented!()
let url = url.to_string();
self.background_executor().spawn(async move {
let keyring = oo7::Keyring::new().await?;
keyring.unlock().await?;

let items = keyring.search_items(&vec![("url", &url)]).await?;

for item in items.into_iter() {
if item.label().await.is_ok_and(|label| label == KEYRING_LABEL) {
let attributes = item.attributes().await?;
let username = attributes
.get("username")
.ok_or_else(|| anyhow!("Cannot find username in stored credentials"))?;
let secret = item.secret().await?;

// we lose the zeroizing capabilities at this boundary,
// a current limitation GPUI's credentials api
return Ok(Some((username.to_string(), secret.to_vec())));
} else {
continue;
}
}
Ok(None)
})
}

//todo!(linux)
fn delete_credentials(&self, url: &str) -> Task<Result<()>> {
unimplemented!()
let url = url.to_string();
self.background_executor().spawn(async move {
let keyring = oo7::Keyring::new().await?;
keyring.unlock().await?;

let items = keyring.search_items(&vec![("url", &url)]).await?;

for item in items.into_iter() {
if item.label().await.is_ok_and(|label| label == KEYRING_LABEL) {
item.delete().await?;
return Ok(());
}
}

Ok(())
})
}

fn window_appearance(&self) -> crate::WindowAppearance {
Expand Down
11 changes: 9 additions & 2 deletions crates/gpui/src/platform/linux/text_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use cosmic_text::{
fontdb::Query, Attrs, AttrsList, BufferLine, CacheKey, Family, Font as CosmicTextFont,
FontSystem, SwashCache,
};

use itertools::Itertools;
use parking_lot::{RwLock, RwLockUpgradableReadGuard};
use pathfinder_geometry::{
rect::{RectF, RectI},
Expand Down Expand Up @@ -71,9 +73,14 @@ impl PlatformTextSystem for LinuxTextSystem {
.collect()
}

// todo(linux)
fn all_font_families(&self) -> Vec<String> {
Vec::new()
self.0
.read()
.font_system
.db()
.faces()
.filter_map(|face| Some(face.families.get(0)?.0.clone()))
.collect_vec()
}

fn font_id(&self, font: &Font) -> Result<FontId> {
Expand Down
1 change: 1 addition & 0 deletions crates/gpui/src/platform/linux/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
pub(crate) use client::*;

mod client;
mod cursor;
mod display;
mod window;
Loading

0 comments on commit 6047708

Please sign in to comment.