Add copilot menu item for enabling paths by glob
This commit is contained in:
parent
c485fc86a2
commit
8eb1312deb
12 changed files with 432 additions and 232 deletions
|
@ -19,6 +19,7 @@ test-support = [
|
|||
]
|
||||
|
||||
[dependencies]
|
||||
assets = { path = "../assets" }
|
||||
db = { path = "../db" }
|
||||
call = { path = "../call" }
|
||||
client = { path = "../client" }
|
||||
|
|
|
@ -14,9 +14,8 @@ pub mod sidebar;
|
|||
mod status_bar;
|
||||
mod toolbar;
|
||||
|
||||
pub use smallvec;
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use assets::Assets;
|
||||
use call::ActiveCall;
|
||||
use client::{
|
||||
proto::{self, PeerId},
|
||||
|
@ -47,13 +46,14 @@ use gpui::{
|
|||
ModelHandle, SizeConstraint, Subscription, Task, View, ViewContext, ViewHandle, WeakViewHandle,
|
||||
};
|
||||
use item::{FollowableItem, FollowableItemHandle, Item, ItemHandle, ProjectItem};
|
||||
use language::LanguageRegistry;
|
||||
use language::{LanguageRegistry, Rope};
|
||||
use std::{
|
||||
any::TypeId,
|
||||
borrow::Cow,
|
||||
cmp, env,
|
||||
future::Future,
|
||||
path::{Path, PathBuf},
|
||||
str,
|
||||
sync::Arc,
|
||||
time::Duration,
|
||||
};
|
||||
|
@ -82,7 +82,7 @@ use status_bar::StatusBar;
|
|||
pub use status_bar::StatusItemView;
|
||||
use theme::{Theme, ThemeRegistry};
|
||||
pub use toolbar::{ToolbarItemLocation, ToolbarItemView};
|
||||
use util::ResultExt;
|
||||
use util::{paths, ResultExt};
|
||||
|
||||
lazy_static! {
|
||||
static ref ZED_WINDOW_SIZE: Option<Vector2F> = env::var("ZED_WINDOW_SIZE")
|
||||
|
@ -126,6 +126,8 @@ actions!(
|
|||
]
|
||||
);
|
||||
|
||||
actions!(zed, [OpenSettings]);
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct OpenPaths {
|
||||
pub paths: Vec<PathBuf>,
|
||||
|
@ -314,6 +316,18 @@ pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
|
|||
.detach();
|
||||
});
|
||||
|
||||
cx.add_action({
|
||||
let app_state = app_state.clone();
|
||||
move |_: &mut Workspace, _: &OpenSettings, cx: &mut ViewContext<Workspace>| {
|
||||
create_and_open_local_file(&paths::SETTINGS, app_state.clone(), cx, || {
|
||||
Settings::initial_user_settings_content(&Assets)
|
||||
.as_ref()
|
||||
.into()
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
});
|
||||
|
||||
let client = &app_state.client;
|
||||
client.add_view_request_handler(Workspace::handle_follow);
|
||||
client.add_view_message_handler(Workspace::handle_unfollow);
|
||||
|
@ -2981,6 +2995,34 @@ pub fn open_new(
|
|||
})
|
||||
}
|
||||
|
||||
pub fn create_and_open_local_file(
|
||||
path: &'static Path,
|
||||
app_state: Arc<AppState>,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
default_content: impl 'static + Send + FnOnce() -> Rope,
|
||||
) -> Task<Result<Box<dyn ItemHandle>>> {
|
||||
cx.spawn(|workspace, mut cx| async move {
|
||||
let fs = &app_state.fs;
|
||||
if !fs.is_file(path).await {
|
||||
fs.create_file(path, Default::default()).await?;
|
||||
fs.save(path, &default_content(), Default::default())
|
||||
.await?;
|
||||
}
|
||||
|
||||
let mut items = workspace
|
||||
.update(&mut cx, |workspace, cx| {
|
||||
workspace.with_local_workspace(&app_state, cx, |workspace, cx| {
|
||||
workspace.open_paths(vec![path.to_path_buf()], false, cx)
|
||||
})
|
||||
})?
|
||||
.await?
|
||||
.await;
|
||||
|
||||
let item = items.pop().flatten();
|
||||
item.ok_or_else(|| anyhow!("path {path:?} is not a file"))?
|
||||
})
|
||||
}
|
||||
|
||||
pub fn join_remote_project(
|
||||
project_id: u64,
|
||||
follow_user_id: u64,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue