Merge branch 'main' into copilot-disabled-globs
This commit is contained in:
commit
9d41f83b1b
81 changed files with 1649 additions and 1545 deletions
|
@ -23,7 +23,7 @@ impl super::LspAdapter for CLspAdapter {
|
|||
&self,
|
||||
http: Arc<dyn HttpClient>,
|
||||
) -> Result<Box<dyn 'static + Send + Any>> {
|
||||
let release = latest_github_release("clangd/clangd", http).await?;
|
||||
let release = latest_github_release("clangd/clangd", false, http).await?;
|
||||
let asset_name = format!("clangd-mac-{}.zip", release.name);
|
||||
let asset = release
|
||||
.assets
|
||||
|
|
|
@ -24,7 +24,7 @@ impl LspAdapter for ElixirLspAdapter {
|
|||
&self,
|
||||
http: Arc<dyn HttpClient>,
|
||||
) -> Result<Box<dyn 'static + Send + Any>> {
|
||||
let release = latest_github_release("elixir-lsp/elixir-ls", http).await?;
|
||||
let release = latest_github_release("elixir-lsp/elixir-ls", false, http).await?;
|
||||
let asset_name = "elixir-ls.zip";
|
||||
let asset = release
|
||||
.assets
|
||||
|
|
|
@ -33,7 +33,7 @@ impl super::LspAdapter for GoLspAdapter {
|
|||
&self,
|
||||
http: Arc<dyn HttpClient>,
|
||||
) -> Result<Box<dyn 'static + Send + Any>> {
|
||||
let release = latest_github_release("golang/tools", http).await?;
|
||||
let release = latest_github_release("golang/tools", false, http).await?;
|
||||
let version: Option<String> = release.name.strip_prefix("gopls/v").map(str::to_string);
|
||||
if version.is_none() {
|
||||
log::warn!(
|
||||
|
|
|
@ -57,8 +57,8 @@ impl LspAdapter for HtmlLspAdapter {
|
|||
if fs::metadata(&server_path).await.is_err() {
|
||||
self.node
|
||||
.npm_install_packages(
|
||||
[("vscode-langservers-extracted", version.as_str())],
|
||||
&container_dir,
|
||||
[("vscode-langservers-extracted", version.as_str())],
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
|
|
@ -76,8 +76,8 @@ impl LspAdapter for JsonLspAdapter {
|
|||
if fs::metadata(&server_path).await.is_err() {
|
||||
self.node
|
||||
.npm_install_packages(
|
||||
[("vscode-json-languageserver", version.as_str())],
|
||||
&container_dir,
|
||||
[("vscode-json-languageserver", version.as_str())],
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ impl super::LspAdapter for LuaLspAdapter {
|
|||
&self,
|
||||
http: Arc<dyn HttpClient>,
|
||||
) -> Result<Box<dyn 'static + Send + Any>> {
|
||||
let release = latest_github_release("LuaLS/lua-language-server", http).await?;
|
||||
let release = latest_github_release("LuaLS/lua-language-server", false, http).await?;
|
||||
let version = release.name.clone();
|
||||
let platform = match consts::ARCH {
|
||||
"x86_64" => "x64",
|
||||
|
|
|
@ -53,7 +53,7 @@ impl LspAdapter for PythonLspAdapter {
|
|||
|
||||
if fs::metadata(&server_path).await.is_err() {
|
||||
self.node
|
||||
.npm_install_packages([("pyright", version.as_str())], &container_dir)
|
||||
.npm_install_packages(&container_dir, [("pyright", version.as_str())])
|
||||
.await?;
|
||||
}
|
||||
|
||||
|
|
|
@ -24,18 +24,17 @@ impl LspAdapter for RustLspAdapter {
|
|||
&self,
|
||||
http: Arc<dyn HttpClient>,
|
||||
) -> Result<Box<dyn 'static + Send + Any>> {
|
||||
let release = latest_github_release("rust-analyzer/rust-analyzer", http).await?;
|
||||
let release = latest_github_release("rust-analyzer/rust-analyzer", false, http).await?;
|
||||
let asset_name = format!("rust-analyzer-{}-apple-darwin.gz", consts::ARCH);
|
||||
let asset = release
|
||||
.assets
|
||||
.iter()
|
||||
.find(|asset| asset.name == asset_name)
|
||||
.ok_or_else(|| anyhow!("no asset found matching {:?}", asset_name))?;
|
||||
let version = GitHubLspBinaryVersion {
|
||||
Ok(Box::new(GitHubLspBinaryVersion {
|
||||
name: release.name,
|
||||
url: asset.browser_download_url.clone(),
|
||||
};
|
||||
Ok(Box::new(version) as Box<_>)
|
||||
}))
|
||||
}
|
||||
|
||||
async fn fetch_server_binary(
|
||||
|
@ -77,6 +76,7 @@ impl LspAdapter for RustLspAdapter {
|
|||
while let Some(entry) = entries.next().await {
|
||||
last = Some(entry?.path());
|
||||
}
|
||||
|
||||
anyhow::Ok(LanguageServerBinary {
|
||||
path: last.ok_or_else(|| anyhow!("no cached binary"))?,
|
||||
arguments: Default::default(),
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
use anyhow::{anyhow, Result};
|
||||
use async_compression::futures::bufread::GzipDecoder;
|
||||
use async_tar::Archive;
|
||||
use async_trait::async_trait;
|
||||
use futures::{future::BoxFuture, FutureExt};
|
||||
use gpui::AppContext;
|
||||
|
@ -6,7 +8,7 @@ use language::{LanguageServerBinary, LanguageServerName, LspAdapter};
|
|||
use lsp::CodeActionKind;
|
||||
use node_runtime::NodeRuntime;
|
||||
use serde_json::{json, Value};
|
||||
use smol::fs;
|
||||
use smol::{fs, io::BufReader, stream::StreamExt};
|
||||
use std::{
|
||||
any::Any,
|
||||
ffi::OsString,
|
||||
|
@ -14,8 +16,8 @@ use std::{
|
|||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
use util::http::HttpClient;
|
||||
use util::ResultExt;
|
||||
use util::{fs::remove_matching, github::latest_github_release, http::HttpClient};
|
||||
use util::{github::GitHubLspBinaryVersion, ResultExt};
|
||||
|
||||
fn typescript_server_binary_arguments(server_path: &Path) -> Vec<OsString> {
|
||||
vec![
|
||||
|
@ -69,24 +71,24 @@ impl LspAdapter for TypeScriptLspAdapter {
|
|||
|
||||
async fn fetch_server_binary(
|
||||
&self,
|
||||
versions: Box<dyn 'static + Send + Any>,
|
||||
version: Box<dyn 'static + Send + Any>,
|
||||
_: Arc<dyn HttpClient>,
|
||||
container_dir: PathBuf,
|
||||
) -> Result<LanguageServerBinary> {
|
||||
let versions = versions.downcast::<TypeScriptVersions>().unwrap();
|
||||
let version = version.downcast::<TypeScriptVersions>().unwrap();
|
||||
let server_path = container_dir.join(Self::NEW_SERVER_PATH);
|
||||
|
||||
if fs::metadata(&server_path).await.is_err() {
|
||||
self.node
|
||||
.npm_install_packages(
|
||||
&container_dir,
|
||||
[
|
||||
("typescript", versions.typescript_version.as_str()),
|
||||
("typescript", version.typescript_version.as_str()),
|
||||
(
|
||||
"typescript-language-server",
|
||||
versions.server_version.as_str(),
|
||||
version.server_version.as_str(),
|
||||
),
|
||||
],
|
||||
&container_dir,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
@ -172,8 +174,7 @@ pub struct EsLintLspAdapter {
|
|||
}
|
||||
|
||||
impl EsLintLspAdapter {
|
||||
const SERVER_PATH: &'static str =
|
||||
"node_modules/vscode-langservers-extracted/lib/eslint-language-server/eslintServer.js";
|
||||
const SERVER_PATH: &'static str = "vscode-eslint/server/out/eslintServer.js";
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn new(node: Arc<NodeRuntime>) -> Self {
|
||||
|
@ -187,35 +188,10 @@ impl LspAdapter for EsLintLspAdapter {
|
|||
Some(
|
||||
future::ready(json!({
|
||||
"": {
|
||||
"validate": "on",
|
||||
"packageManager": "npm",
|
||||
"useESLintClass": false,
|
||||
"experimental": {
|
||||
"useFlatConfig": false
|
||||
},
|
||||
"codeActionOnSave": {
|
||||
"mode": "all"
|
||||
},
|
||||
"format": false,
|
||||
"quiet": false,
|
||||
"onIgnoredFiles": "off",
|
||||
"options": {},
|
||||
"rulesCustomizations": [],
|
||||
"run": "onType",
|
||||
"problems": {
|
||||
"shortenToSingleLine": false
|
||||
},
|
||||
"nodePath": null,
|
||||
"codeAction": {
|
||||
"disableRuleComment": {
|
||||
"enable": true,
|
||||
"location": "separateLine",
|
||||
"commentStyle": "line"
|
||||
},
|
||||
"showDocumentation": {
|
||||
"enable": true
|
||||
}
|
||||
}
|
||||
"validate": "on",
|
||||
"rulesCustomizations": [],
|
||||
"run": "onType",
|
||||
"nodePath": null,
|
||||
}
|
||||
}))
|
||||
.boxed(),
|
||||
|
@ -228,30 +204,50 @@ impl LspAdapter for EsLintLspAdapter {
|
|||
|
||||
async fn fetch_latest_server_version(
|
||||
&self,
|
||||
_: Arc<dyn HttpClient>,
|
||||
http: Arc<dyn HttpClient>,
|
||||
) -> Result<Box<dyn 'static + Send + Any>> {
|
||||
Ok(Box::new(
|
||||
self.node
|
||||
.npm_package_latest_version("vscode-langservers-extracted")
|
||||
.await?,
|
||||
))
|
||||
// At the time of writing the latest vscode-eslint release was released in 2020 and requires
|
||||
// special custom LSP protocol extensions be handled to fully initalize. Download the latest
|
||||
// prerelease instead to sidestep this issue
|
||||
let release = latest_github_release("microsoft/vscode-eslint", true, http).await?;
|
||||
Ok(Box::new(GitHubLspBinaryVersion {
|
||||
name: release.name,
|
||||
url: release.tarball_url,
|
||||
}))
|
||||
}
|
||||
|
||||
async fn fetch_server_binary(
|
||||
&self,
|
||||
versions: Box<dyn 'static + Send + Any>,
|
||||
_: Arc<dyn HttpClient>,
|
||||
version: Box<dyn 'static + Send + Any>,
|
||||
http: Arc<dyn HttpClient>,
|
||||
container_dir: PathBuf,
|
||||
) -> Result<LanguageServerBinary> {
|
||||
let version = versions.downcast::<String>().unwrap();
|
||||
let server_path = container_dir.join(Self::SERVER_PATH);
|
||||
let version = version.downcast::<GitHubLspBinaryVersion>().unwrap();
|
||||
let destination_path = container_dir.join(format!("vscode-eslint-{}", version.name));
|
||||
let server_path = destination_path.join(Self::SERVER_PATH);
|
||||
|
||||
if fs::metadata(&server_path).await.is_err() {
|
||||
remove_matching(&container_dir, |entry| entry != destination_path).await;
|
||||
|
||||
let mut response = http
|
||||
.get(&version.url, Default::default(), true)
|
||||
.await
|
||||
.map_err(|err| anyhow!("error downloading release: {}", err))?;
|
||||
let decompressed_bytes = GzipDecoder::new(BufReader::new(response.body_mut()));
|
||||
let archive = Archive::new(decompressed_bytes);
|
||||
archive.unpack(&destination_path).await?;
|
||||
|
||||
let mut dir = fs::read_dir(&destination_path).await?;
|
||||
let first = dir.next().await.ok_or(anyhow!("missing first file"))??;
|
||||
let repo_root = destination_path.join("vscode-eslint");
|
||||
fs::rename(first.path(), &repo_root).await?;
|
||||
|
||||
self.node
|
||||
.npm_install_packages(
|
||||
[("vscode-langservers-extracted", version.as_str())],
|
||||
&container_dir,
|
||||
)
|
||||
.run_npm_subcommand(&repo_root, "install", &[])
|
||||
.await?;
|
||||
|
||||
self.node
|
||||
.run_npm_subcommand(&repo_root, "run-script", &["compile"])
|
||||
.await?;
|
||||
}
|
||||
|
||||
|
@ -263,18 +259,17 @@ impl LspAdapter for EsLintLspAdapter {
|
|||
|
||||
async fn cached_server_binary(&self, container_dir: PathBuf) -> Option<LanguageServerBinary> {
|
||||
(|| async move {
|
||||
let server_path = container_dir.join(Self::SERVER_PATH);
|
||||
if server_path.exists() {
|
||||
Ok(LanguageServerBinary {
|
||||
path: self.node.binary_path().await?,
|
||||
arguments: eslint_server_binary_arguments(&server_path),
|
||||
})
|
||||
} else {
|
||||
Err(anyhow!(
|
||||
"missing executable in directory {:?}",
|
||||
container_dir
|
||||
))
|
||||
// This is unfortunate but we don't know what the version is to build a path directly
|
||||
let mut dir = fs::read_dir(&container_dir).await?;
|
||||
let first = dir.next().await.ok_or(anyhow!("missing first file"))??;
|
||||
if !first.file_type().await?.is_dir() {
|
||||
return Err(anyhow!("First entry is not a directory"));
|
||||
}
|
||||
|
||||
Ok(LanguageServerBinary {
|
||||
path: first.path().join(Self::SERVER_PATH),
|
||||
arguments: Default::default(),
|
||||
})
|
||||
})()
|
||||
.await
|
||||
.log_err()
|
||||
|
|
|
@ -61,7 +61,7 @@ impl LspAdapter for YamlLspAdapter {
|
|||
|
||||
if fs::metadata(&server_path).await.is_err() {
|
||||
self.node
|
||||
.npm_install_packages([("yaml-language-server", version.as_str())], &container_dir)
|
||||
.npm_install_packages(&container_dir, [("yaml-language-server", version.as_str())])
|
||||
.await?;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ use cli::{
|
|||
};
|
||||
use client::{self, UserStore, ZED_APP_VERSION, ZED_SECRET_CLIENT_TOKEN};
|
||||
use db::kvp::KEY_VALUE_STORE;
|
||||
use editor::Editor;
|
||||
use futures::{
|
||||
channel::{mpsc, oneshot},
|
||||
FutureExt, SinkExt, StreamExt,
|
||||
|
@ -29,8 +30,16 @@ use settings::{
|
|||
use simplelog::ConfigBuilder;
|
||||
use smol::process::Command;
|
||||
use std::{
|
||||
env, ffi::OsStr, fs::OpenOptions, io::Write as _, os::unix::prelude::OsStrExt, panic,
|
||||
path::PathBuf, sync::Arc, thread, time::Duration,
|
||||
env,
|
||||
ffi::OsStr,
|
||||
fs::OpenOptions,
|
||||
io::Write as _,
|
||||
os::unix::prelude::OsStrExt,
|
||||
panic,
|
||||
path::PathBuf,
|
||||
sync::{Arc, Weak},
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
use terminal_view::{get_working_directory, TerminalView};
|
||||
use util::http::{self, HttpClient};
|
||||
|
@ -43,8 +52,8 @@ use staff_mode::StaffMode;
|
|||
use theme::ThemeRegistry;
|
||||
use util::{channel::RELEASE_CHANNEL, paths, ResultExt, TryFutureExt};
|
||||
use workspace::{
|
||||
self, dock::FocusDock, item::ItemHandle, notifications::NotifyResultExt, AppState, NewFile,
|
||||
OpenSettings, Workspace,
|
||||
dock::FocusDock, item::ItemHandle, notifications::NotifyResultExt, AppState, OpenSettings,
|
||||
Workspace,
|
||||
};
|
||||
use zed::{self, build_window_options, initialize_workspace, languages, menus};
|
||||
|
||||
|
@ -104,7 +113,16 @@ fn main() {
|
|||
.log_err();
|
||||
}
|
||||
})
|
||||
.on_reopen(move |cx| cx.dispatch_global_action(NewFile));
|
||||
.on_reopen(move |cx| {
|
||||
if cx.has_global::<Weak<AppState>>() {
|
||||
if let Some(app_state) = cx.global::<Weak<AppState>>().upgrade() {
|
||||
workspace::open_new(&app_state, cx, |workspace, cx| {
|
||||
Editor::new_file(workspace, &Default::default(), cx)
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
app.run(move |cx| {
|
||||
cx.set_global(*RELEASE_CHANNEL);
|
||||
|
@ -172,8 +190,8 @@ fn main() {
|
|||
})
|
||||
.detach();
|
||||
|
||||
client.start_telemetry();
|
||||
client.report_event(
|
||||
client.telemetry().start();
|
||||
client.telemetry().report_mixpanel_event(
|
||||
"start app",
|
||||
Default::default(),
|
||||
cx.global::<Settings>().telemetry(),
|
||||
|
@ -190,17 +208,18 @@ fn main() {
|
|||
dock_default_item_factory,
|
||||
background_actions,
|
||||
});
|
||||
cx.set_global(Arc::downgrade(&app_state));
|
||||
auto_update::init(http, client::ZED_SERVER_URL.clone(), cx);
|
||||
|
||||
workspace::init(app_state.clone(), cx);
|
||||
recent_projects::init(cx, Arc::downgrade(&app_state));
|
||||
recent_projects::init(cx);
|
||||
|
||||
journal::init(app_state.clone(), cx);
|
||||
language_selector::init(app_state.clone(), cx);
|
||||
theme_selector::init(app_state.clone(), cx);
|
||||
language_selector::init(cx);
|
||||
theme_selector::init(cx);
|
||||
zed::init(&app_state, cx);
|
||||
collab_ui::init(&app_state, cx);
|
||||
feedback::init(app_state.clone(), cx);
|
||||
feedback::init(cx);
|
||||
welcome::init(cx);
|
||||
|
||||
cx.set_menus(menus::menus());
|
||||
|
@ -274,7 +293,10 @@ async fn restore_or_create_workspace(app_state: &Arc<AppState>, mut cx: AsyncApp
|
|||
cx.update(|cx| show_welcome_experience(app_state, cx));
|
||||
} else {
|
||||
cx.update(|cx| {
|
||||
cx.dispatch_global_action(NewFile);
|
||||
workspace::open_new(app_state, cx, |workspace, cx| {
|
||||
Editor::new_file(workspace, &Default::default(), cx)
|
||||
})
|
||||
.detach();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ use collections::VecDeque;
|
|||
pub use editor;
|
||||
use editor::{Editor, MultiBuffer};
|
||||
|
||||
use anyhow::anyhow;
|
||||
use feedback::{
|
||||
feedback_info_text::FeedbackInfoText, submit_feedback_button::SubmitFeedbackButton,
|
||||
};
|
||||
|
@ -20,7 +21,7 @@ use gpui::{
|
|||
geometry::vector::vec2f,
|
||||
impl_actions,
|
||||
platform::{Platform, PromptLevel, TitlebarOptions, WindowBounds, WindowKind, WindowOptions},
|
||||
ViewContext,
|
||||
AppContext, ViewContext,
|
||||
};
|
||||
pub use lsp;
|
||||
pub use project;
|
||||
|
@ -34,7 +35,10 @@ use terminal_view::terminal_button::TerminalButton;
|
|||
use util::{channel::ReleaseChannel, paths, ResultExt};
|
||||
use uuid::Uuid;
|
||||
pub use workspace;
|
||||
use workspace::{create_and_open_local_file, sidebar::SidebarSide, AppState, Restart, Workspace};
|
||||
use workspace::{
|
||||
create_and_open_local_file, open_new, sidebar::SidebarSide, AppState, NewFile, NewWindow,
|
||||
Workspace,
|
||||
};
|
||||
|
||||
#[derive(Deserialize, Clone, PartialEq)]
|
||||
pub struct OpenBrowser {
|
||||
|
@ -111,7 +115,6 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::AppContext) {
|
|||
},
|
||||
);
|
||||
cx.add_global_action(quit);
|
||||
cx.add_global_action(restart);
|
||||
cx.add_global_action(move |action: &OpenBrowser, cx| cx.platform().open_url(&action.url));
|
||||
cx.add_global_action(move |_: &IncreaseBufferFontSize, cx| {
|
||||
cx.update_global::<Settings, _, _>(|settings, cx| {
|
||||
|
@ -146,72 +149,71 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::AppContext) {
|
|||
})
|
||||
.detach_and_log_err(cx);
|
||||
});
|
||||
cx.add_action({
|
||||
let app_state = app_state.clone();
|
||||
cx.add_action(
|
||||
move |workspace: &mut Workspace, _: &OpenLog, cx: &mut ViewContext<Workspace>| {
|
||||
open_log_file(workspace, app_state.clone(), cx);
|
||||
}
|
||||
});
|
||||
cx.add_action({
|
||||
let app_state = app_state.clone();
|
||||
move |_: &mut Workspace, _: &OpenLicenses, cx: &mut ViewContext<Workspace>| {
|
||||
open_log_file(workspace, cx);
|
||||
},
|
||||
);
|
||||
cx.add_action(
|
||||
move |workspace: &mut Workspace, _: &OpenLicenses, cx: &mut ViewContext<Workspace>| {
|
||||
open_bundled_file(
|
||||
app_state.clone(),
|
||||
workspace,
|
||||
"licenses.md",
|
||||
"Open Source License Attribution",
|
||||
"Markdown",
|
||||
cx,
|
||||
);
|
||||
}
|
||||
});
|
||||
cx.add_action({
|
||||
let app_state = app_state.clone();
|
||||
},
|
||||
);
|
||||
cx.add_action(
|
||||
move |workspace: &mut Workspace, _: &OpenTelemetryLog, cx: &mut ViewContext<Workspace>| {
|
||||
open_telemetry_log_file(workspace, app_state.clone(), cx);
|
||||
}
|
||||
});
|
||||
cx.add_action({
|
||||
let app_state = app_state.clone();
|
||||
open_telemetry_log_file(workspace, cx);
|
||||
},
|
||||
);
|
||||
cx.add_action(
|
||||
move |_: &mut Workspace, _: &OpenKeymap, cx: &mut ViewContext<Workspace>| {
|
||||
create_and_open_local_file(&paths::KEYMAP, app_state.clone(), cx, Default::default)
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
});
|
||||
cx.add_action({
|
||||
let app_state = app_state.clone();
|
||||
move |_: &mut Workspace, _: &OpenDefaultKeymap, cx: &mut ViewContext<Workspace>| {
|
||||
create_and_open_local_file(&paths::KEYMAP, cx, Default::default).detach_and_log_err(cx);
|
||||
},
|
||||
);
|
||||
cx.add_action(
|
||||
move |workspace: &mut Workspace, _: &OpenDefaultKeymap, cx: &mut ViewContext<Workspace>| {
|
||||
open_bundled_file(
|
||||
app_state.clone(),
|
||||
workspace,
|
||||
"keymaps/default.json",
|
||||
"Default Key Bindings",
|
||||
"JSON",
|
||||
cx,
|
||||
);
|
||||
}
|
||||
});
|
||||
cx.add_action({
|
||||
let app_state = app_state.clone();
|
||||
move |_: &mut Workspace, _: &OpenDefaultSettings, cx: &mut ViewContext<Workspace>| {
|
||||
},
|
||||
);
|
||||
cx.add_action(
|
||||
move |workspace: &mut Workspace,
|
||||
_: &OpenDefaultSettings,
|
||||
cx: &mut ViewContext<Workspace>| {
|
||||
open_bundled_file(
|
||||
app_state.clone(),
|
||||
workspace,
|
||||
DEFAULT_SETTINGS_ASSET_PATH,
|
||||
"Default Settings",
|
||||
"JSON",
|
||||
cx,
|
||||
);
|
||||
}
|
||||
});
|
||||
},
|
||||
);
|
||||
cx.add_action({
|
||||
let app_state = app_state.clone();
|
||||
move |_: &mut Workspace, _: &DebugElements, cx: &mut ViewContext<Workspace>| {
|
||||
let app_state = app_state.clone();
|
||||
move |workspace: &mut Workspace, _: &DebugElements, cx: &mut ViewContext<Workspace>| {
|
||||
let app_state = workspace.app_state().clone();
|
||||
let markdown = app_state.languages.language_for_name("JSON");
|
||||
let content = to_string_pretty(&cx.debug_elements()).unwrap();
|
||||
let window_id = cx.window_id();
|
||||
cx.spawn(|workspace, mut cx| async move {
|
||||
let markdown = markdown.await.log_err();
|
||||
let content = to_string_pretty(
|
||||
&cx.debug_elements(window_id)
|
||||
.ok_or_else(|| anyhow!("could not debug elements for {window_id}"))?,
|
||||
)
|
||||
.unwrap();
|
||||
workspace
|
||||
.update(&mut cx, |workspace, cx| {
|
||||
workspace.with_local_workspace(&app_state, cx, move |workspace, cx| {
|
||||
workspace.with_local_workspace(cx, move |workspace, cx| {
|
||||
let project = workspace.project().clone();
|
||||
|
||||
let buffer = project
|
||||
|
@ -243,6 +245,28 @@ pub fn init(app_state: &Arc<AppState>, cx: &mut gpui::AppContext) {
|
|||
workspace.toggle_sidebar_item_focus(SidebarSide::Left, 0, cx);
|
||||
},
|
||||
);
|
||||
cx.add_global_action({
|
||||
let app_state = Arc::downgrade(&app_state);
|
||||
move |_: &NewWindow, cx: &mut AppContext| {
|
||||
if let Some(app_state) = app_state.upgrade() {
|
||||
open_new(&app_state, cx, |workspace, cx| {
|
||||
Editor::new_file(workspace, &Default::default(), cx)
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
}
|
||||
});
|
||||
cx.add_global_action({
|
||||
let app_state = Arc::downgrade(&app_state);
|
||||
move |_: &NewFile, cx: &mut AppContext| {
|
||||
if let Some(app_state) = app_state.upgrade() {
|
||||
open_new(&app_state, cx, |workspace, cx| {
|
||||
Editor::new_file(workspace, &Default::default(), cx)
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
}
|
||||
});
|
||||
activity_indicator::init(cx);
|
||||
lsp_log::init(cx);
|
||||
call::init(app_state.client.clone(), app_state.user_store.clone(), cx);
|
||||
|
@ -260,7 +284,7 @@ pub fn initialize_workspace(
|
|||
if let workspace::Event::PaneAdded(pane) = event {
|
||||
pane.update(cx, |pane, cx| {
|
||||
pane.toolbar().update(cx, |toolbar, cx| {
|
||||
let breadcrumbs = cx.add_view(|_| Breadcrumbs::new());
|
||||
let breadcrumbs = cx.add_view(|_| Breadcrumbs::new(workspace));
|
||||
toolbar.add_item(breadcrumbs, cx);
|
||||
let buffer_search_bar = cx.add_view(BufferSearchBar::new);
|
||||
toolbar.add_item(buffer_search_bar, cx);
|
||||
|
@ -284,12 +308,11 @@ pub fn initialize_workspace(
|
|||
cx.emit(workspace::Event::PaneAdded(workspace.active_pane().clone()));
|
||||
cx.emit(workspace::Event::PaneAdded(workspace.dock_pane().clone()));
|
||||
|
||||
let collab_titlebar_item = cx.add_view(|cx| {
|
||||
CollabTitlebarItem::new(&workspace_handle, app_state.user_store.clone(), cx)
|
||||
});
|
||||
let collab_titlebar_item =
|
||||
cx.add_view(|cx| CollabTitlebarItem::new(workspace, &workspace_handle, cx));
|
||||
workspace.set_titlebar_item(collab_titlebar_item.into_any(), cx);
|
||||
|
||||
let project_panel = ProjectPanel::new(workspace.project().clone(), cx);
|
||||
let project_panel = ProjectPanel::new(workspace, cx);
|
||||
workspace.left_sidebar().update(cx, |sidebar, cx| {
|
||||
sidebar.add_item(
|
||||
"icons/folder_tree_16.svg",
|
||||
|
@ -300,14 +323,15 @@ pub fn initialize_workspace(
|
|||
});
|
||||
|
||||
let toggle_terminal = cx.add_view(|cx| TerminalButton::new(workspace_handle.clone(), cx));
|
||||
let copilot = cx.add_view(|cx| copilot_button::CopilotButton::new(app_state.clone(), cx));
|
||||
let copilot = cx.add_view(|cx| copilot_button::CopilotButton::new(cx));
|
||||
let diagnostic_summary =
|
||||
cx.add_view(|cx| diagnostics::items::DiagnosticIndicator::new(workspace.project(), cx));
|
||||
cx.add_view(|cx| diagnostics::items::DiagnosticIndicator::new(workspace, cx));
|
||||
let activity_indicator =
|
||||
activity_indicator::ActivityIndicator::new(workspace, app_state.languages.clone(), cx);
|
||||
let active_buffer_language = cx.add_view(|_| language_selector::ActiveBufferLanguage::new());
|
||||
let active_buffer_language =
|
||||
cx.add_view(|_| language_selector::ActiveBufferLanguage::new(workspace));
|
||||
let feedback_button =
|
||||
cx.add_view(|_| feedback::deploy_feedback_button::DeployFeedbackButton::new());
|
||||
cx.add_view(|_| feedback::deploy_feedback_button::DeployFeedbackButton::new(workspace));
|
||||
let cursor_position = cx.add_view(|_| editor::items::CursorPosition::new());
|
||||
workspace.status_bar().update(cx, |status_bar, cx| {
|
||||
status_bar.add_left_item(diagnostic_summary, cx);
|
||||
|
@ -354,77 +378,26 @@ pub fn build_window_options(
|
|||
}
|
||||
}
|
||||
|
||||
fn restart(_: &Restart, cx: &mut gpui::AppContext) {
|
||||
let mut workspaces = cx
|
||||
.window_ids()
|
||||
.filter_map(|window_id| {
|
||||
Some(
|
||||
cx.root_view(window_id)?
|
||||
.clone()
|
||||
.downcast::<Workspace>()?
|
||||
.downgrade(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// If multiple windows have unsaved changes, and need a save prompt,
|
||||
// prompt in the active window before switching to a different window.
|
||||
workspaces.sort_by_key(|workspace| !cx.window_is_active(workspace.window_id()));
|
||||
|
||||
let should_confirm = cx.global::<Settings>().confirm_quit;
|
||||
cx.spawn(|mut cx| async move {
|
||||
if let (true, Some(workspace)) = (should_confirm, workspaces.first()) {
|
||||
let answer = cx.prompt(
|
||||
workspace.window_id(),
|
||||
PromptLevel::Info,
|
||||
"Are you sure you want to restart?",
|
||||
&["Restart", "Cancel"],
|
||||
);
|
||||
|
||||
if let Some(mut answer) = answer {
|
||||
let answer = answer.next().await;
|
||||
if answer != Some(0) {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If the user cancels any save prompt, then keep the app open.
|
||||
for workspace in workspaces {
|
||||
if !workspace
|
||||
.update(&mut cx, |workspace, cx| {
|
||||
workspace.prepare_to_close(true, cx)
|
||||
})?
|
||||
.await?
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
cx.platform().restart();
|
||||
anyhow::Ok(())
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
|
||||
fn quit(_: &Quit, cx: &mut gpui::AppContext) {
|
||||
let mut workspaces = cx
|
||||
.window_ids()
|
||||
.filter_map(|window_id| {
|
||||
Some(
|
||||
cx.root_view(window_id)?
|
||||
.clone()
|
||||
.downcast::<Workspace>()?
|
||||
.downgrade(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// If multiple windows have unsaved changes, and need a save prompt,
|
||||
// prompt in the active window before switching to a different window.
|
||||
workspaces.sort_by_key(|workspace| !cx.window_is_active(workspace.window_id()));
|
||||
|
||||
let should_confirm = cx.global::<Settings>().confirm_quit;
|
||||
cx.spawn(|mut cx| async move {
|
||||
let mut workspaces = cx
|
||||
.window_ids()
|
||||
.into_iter()
|
||||
.filter_map(|window_id| {
|
||||
Some(
|
||||
cx.root_view(window_id)?
|
||||
.clone()
|
||||
.downcast::<Workspace>()?
|
||||
.downgrade(),
|
||||
)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// If multiple windows have unsaved changes, and need a save prompt,
|
||||
// prompt in the active window before switching to a different window.
|
||||
workspaces.sort_by_key(|workspace| !cx.window_is_active(workspace.window_id()));
|
||||
|
||||
if let (true, Some(workspace)) = (should_confirm, workspaces.first()) {
|
||||
let answer = cx.prompt(
|
||||
workspace.window_id(),
|
||||
|
@ -464,20 +437,15 @@ fn about(_: &mut Workspace, _: &About, cx: &mut gpui::ViewContext<Workspace>) {
|
|||
cx.prompt(PromptLevel::Info, &format!("{app_name} {version}"), &["OK"]);
|
||||
}
|
||||
|
||||
fn open_log_file(
|
||||
workspace: &mut Workspace,
|
||||
app_state: Arc<AppState>,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) {
|
||||
fn open_log_file(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
||||
const MAX_LINES: usize = 1000;
|
||||
|
||||
workspace
|
||||
.with_local_workspace(&app_state.clone(), cx, move |_, cx| {
|
||||
.with_local_workspace(cx, move |workspace, cx| {
|
||||
let fs = workspace.app_state().fs.clone();
|
||||
cx.spawn(|workspace, mut cx| async move {
|
||||
let (old_log, new_log) = futures::join!(
|
||||
app_state.fs.load(&paths::OLD_LOG),
|
||||
app_state.fs.load(&paths::LOG)
|
||||
);
|
||||
let (old_log, new_log) =
|
||||
futures::join!(fs.load(&paths::OLD_LOG), fs.load(&paths::LOG));
|
||||
|
||||
let mut lines = VecDeque::with_capacity(MAX_LINES);
|
||||
for line in old_log
|
||||
|
@ -522,15 +490,12 @@ fn open_log_file(
|
|||
.detach();
|
||||
}
|
||||
|
||||
fn open_telemetry_log_file(
|
||||
workspace: &mut Workspace,
|
||||
app_state: Arc<AppState>,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) {
|
||||
workspace.with_local_workspace(&app_state.clone(), cx, move |_, cx| {
|
||||
fn open_telemetry_log_file(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
||||
workspace.with_local_workspace(cx, move |workspace, cx| {
|
||||
let app_state = workspace.app_state().clone();
|
||||
cx.spawn(|workspace, mut cx| async move {
|
||||
async fn fetch_log_string(app_state: &Arc<AppState>) -> Option<String> {
|
||||
let path = app_state.client.telemetry_log_file_path()?;
|
||||
let path = app_state.client.telemetry().log_file_path()?;
|
||||
app_state.fs.load(&path).await.log_err()
|
||||
}
|
||||
|
||||
|
@ -583,18 +548,18 @@ fn open_telemetry_log_file(
|
|||
}
|
||||
|
||||
fn open_bundled_file(
|
||||
app_state: Arc<AppState>,
|
||||
workspace: &mut Workspace,
|
||||
asset_path: &'static str,
|
||||
title: &'static str,
|
||||
language: &'static str,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) {
|
||||
let language = app_state.languages.language_for_name(language);
|
||||
let language = workspace.app_state().languages.language_for_name(language);
|
||||
cx.spawn(|workspace, mut cx| async move {
|
||||
let language = language.await.log_err();
|
||||
workspace
|
||||
.update(&mut cx, |workspace, cx| {
|
||||
workspace.with_local_workspace(&app_state, cx, |workspace, cx| {
|
||||
workspace.with_local_workspace(cx, |workspace, cx| {
|
||||
let project = workspace.project();
|
||||
let buffer = project.update(cx, |project, cx| {
|
||||
let text = Assets::get(asset_path)
|
||||
|
@ -825,8 +790,12 @@ mod tests {
|
|||
#[gpui::test]
|
||||
async fn test_new_empty_workspace(cx: &mut TestAppContext) {
|
||||
let app_state = init(cx);
|
||||
cx.update(|cx| open_new(&app_state, cx, |_, cx| cx.dispatch_action(NewFile)))
|
||||
.await;
|
||||
cx.update(|cx| {
|
||||
open_new(&app_state, cx, |workspace, cx| {
|
||||
Editor::new_file(workspace, &Default::default(), cx)
|
||||
})
|
||||
})
|
||||
.await;
|
||||
|
||||
let window_id = *cx.window_ids().first().unwrap();
|
||||
let workspace = cx
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue