Merge branch 'main' into copilot-disabled-globs
This commit is contained in:
commit
9d41f83b1b
81 changed files with 1649 additions and 1545 deletions
|
@ -11,25 +11,27 @@ path = "src/feedback.rs"
|
|||
test-support = []
|
||||
|
||||
[dependencies]
|
||||
anyhow.workspace = true
|
||||
client = { path = "../client" }
|
||||
editor = { path = "../editor" }
|
||||
language = { path = "../language" }
|
||||
gpui = { path = "../gpui" }
|
||||
project = { path = "../project" }
|
||||
search = { path = "../search" }
|
||||
settings = { path = "../settings" }
|
||||
theme = { path = "../theme" }
|
||||
util = { path = "../util" }
|
||||
workspace = { path = "../workspace" }
|
||||
|
||||
log.workspace = true
|
||||
futures.workspace = true
|
||||
gpui = { path = "../gpui" }
|
||||
anyhow.workspace = true
|
||||
smallvec.workspace = true
|
||||
human_bytes = "0.4.1"
|
||||
isahc = "1.7"
|
||||
lazy_static.workspace = true
|
||||
postage.workspace = true
|
||||
project = { path = "../project" }
|
||||
search = { path = "../search" }
|
||||
serde.workspace = true
|
||||
serde_derive.workspace = true
|
||||
settings = { path = "../settings" }
|
||||
sysinfo = "0.27.1"
|
||||
theme = { path = "../theme" }
|
||||
tree-sitter-markdown = { git = "https://github.com/MDeiml/tree-sitter-markdown", rev = "330ecab87a3e3a7211ac69bbadc19eabecdb1cca" }
|
||||
urlencoding = "2.1.2"
|
||||
util = { path = "../util" }
|
||||
workspace = { path = "../workspace" }
|
||||
|
|
|
@ -1,15 +1,16 @@
|
|||
use gpui::{
|
||||
elements::*,
|
||||
platform::{CursorStyle, MouseButton},
|
||||
Entity, View, ViewContext,
|
||||
Entity, View, ViewContext, WeakViewHandle,
|
||||
};
|
||||
use settings::Settings;
|
||||
use workspace::{item::ItemHandle, StatusItemView};
|
||||
use workspace::{item::ItemHandle, StatusItemView, Workspace};
|
||||
|
||||
use crate::feedback_editor::{FeedbackEditor, GiveFeedback};
|
||||
|
||||
pub struct DeployFeedbackButton {
|
||||
active: bool,
|
||||
workspace: WeakViewHandle<Workspace>,
|
||||
}
|
||||
|
||||
impl Entity for DeployFeedbackButton {
|
||||
|
@ -17,8 +18,11 @@ impl Entity for DeployFeedbackButton {
|
|||
}
|
||||
|
||||
impl DeployFeedbackButton {
|
||||
pub fn new() -> Self {
|
||||
DeployFeedbackButton { active: false }
|
||||
pub fn new(workspace: &Workspace) -> Self {
|
||||
DeployFeedbackButton {
|
||||
active: false,
|
||||
workspace: workspace.weak_handle(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -52,9 +56,12 @@ impl View for DeployFeedbackButton {
|
|||
.with_style(style.container)
|
||||
})
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(MouseButton::Left, move |_, _, cx| {
|
||||
.on_click(MouseButton::Left, move |_, this, cx| {
|
||||
if !active {
|
||||
cx.dispatch_action(GiveFeedback)
|
||||
if let Some(workspace) = this.workspace.upgrade(cx) {
|
||||
workspace
|
||||
.update(cx, |workspace, cx| FeedbackEditor::deploy(workspace, cx))
|
||||
}
|
||||
}
|
||||
})
|
||||
.with_tooltip::<Self>(
|
||||
|
|
|
@ -3,20 +3,10 @@ pub mod feedback_editor;
|
|||
pub mod feedback_info_text;
|
||||
pub mod submit_feedback_button;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
mod system_specs;
|
||||
use gpui::{actions, impl_actions, platform::PromptLevel, AppContext, ClipboardItem, ViewContext};
|
||||
use serde::Deserialize;
|
||||
use gpui::{actions, platform::PromptLevel, AppContext, ClipboardItem, ViewContext};
|
||||
use system_specs::SystemSpecs;
|
||||
use workspace::{AppState, Workspace};
|
||||
|
||||
#[derive(Deserialize, Clone, PartialEq)]
|
||||
pub struct OpenBrowser {
|
||||
pub url: Arc<str>,
|
||||
}
|
||||
|
||||
impl_actions!(zed, [OpenBrowser]);
|
||||
use workspace::Workspace;
|
||||
|
||||
actions!(
|
||||
zed,
|
||||
|
@ -28,29 +18,20 @@ actions!(
|
|||
]
|
||||
);
|
||||
|
||||
pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
|
||||
let system_specs = SystemSpecs::new(&cx);
|
||||
let system_specs_text = system_specs.to_string();
|
||||
|
||||
feedback_editor::init(system_specs, app_state, cx);
|
||||
|
||||
cx.add_global_action(move |action: &OpenBrowser, cx| cx.platform().open_url(&action.url));
|
||||
|
||||
let url = format!(
|
||||
"https://github.com/zed-industries/community/issues/new?assignees=&labels=defect%2Ctriage&template=2_bug_report.yml&environment={}",
|
||||
urlencoding::encode(&system_specs_text)
|
||||
);
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
feedback_editor::init(cx);
|
||||
|
||||
cx.add_action(
|
||||
move |_: &mut Workspace,
|
||||
_: &CopySystemSpecsIntoClipboard,
|
||||
cx: &mut ViewContext<Workspace>| {
|
||||
let specs = SystemSpecs::new(&cx).to_string();
|
||||
cx.prompt(
|
||||
PromptLevel::Info,
|
||||
&format!("Copied into clipboard:\n\n{system_specs_text}"),
|
||||
&format!("Copied into clipboard:\n\n{specs}"),
|
||||
&["OK"],
|
||||
);
|
||||
let item = ClipboardItem::new(system_specs_text.clone());
|
||||
let item = ClipboardItem::new(specs.clone());
|
||||
cx.write_to_clipboard(item);
|
||||
},
|
||||
);
|
||||
|
@ -58,24 +39,24 @@ pub fn init(app_state: Arc<AppState>, cx: &mut AppContext) {
|
|||
cx.add_action(
|
||||
|_: &mut Workspace, _: &RequestFeature, cx: &mut ViewContext<Workspace>| {
|
||||
let url = "https://github.com/zed-industries/community/issues/new?assignees=&labels=enhancement%2Ctriage&template=0_feature_request.yml";
|
||||
cx.dispatch_action(OpenBrowser {
|
||||
url: url.into(),
|
||||
});
|
||||
cx.platform().open_url(url);
|
||||
},
|
||||
);
|
||||
|
||||
cx.add_action(
|
||||
move |_: &mut Workspace, _: &FileBugReport, cx: &mut ViewContext<Workspace>| {
|
||||
cx.dispatch_action(OpenBrowser {
|
||||
url: url.clone().into(),
|
||||
});
|
||||
let url = format!(
|
||||
"https://github.com/zed-industries/community/issues/new?assignees=&labels=defect%2Ctriage&template=2_bug_report.yml&environment={}",
|
||||
urlencoding::encode(&SystemSpecs::new(&cx).to_string())
|
||||
);
|
||||
cx.platform().open_url(&url);
|
||||
},
|
||||
);
|
||||
|
||||
cx.add_action(
|
||||
|_: &mut Workspace, _: &OpenZedCommunityRepo, cx: &mut ViewContext<Workspace>| {
|
||||
let url = "https://github.com/zed-industries/community";
|
||||
cx.dispatch_action(OpenBrowser { url: url.into() });
|
||||
},
|
||||
);
|
||||
cx.add_global_action(open_zed_community_repo);
|
||||
}
|
||||
|
||||
pub fn open_zed_community_repo(_: &OpenZedCommunityRepo, cx: &mut AppContext) {
|
||||
let url = "https://github.com/zed-industries/community";
|
||||
cx.platform().open_url(&url);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,4 @@
|
|||
use std::{
|
||||
any::TypeId,
|
||||
borrow::Cow,
|
||||
ops::{Range, RangeInclusive},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
use crate::system_specs::SystemSpecs;
|
||||
use anyhow::bail;
|
||||
use client::{Client, ZED_SECRET_CLIENT_TOKEN, ZED_SERVER_URL};
|
||||
use editor::{Anchor, Editor};
|
||||
|
@ -19,46 +13,41 @@ use gpui::{
|
|||
use isahc::Request;
|
||||
use language::Buffer;
|
||||
use postage::prelude::Stream;
|
||||
|
||||
use project::Project;
|
||||
use serde::Serialize;
|
||||
use smallvec::SmallVec;
|
||||
use std::{
|
||||
any::TypeId,
|
||||
borrow::Cow,
|
||||
ops::{Range, RangeInclusive},
|
||||
sync::Arc,
|
||||
};
|
||||
use util::ResultExt;
|
||||
use workspace::{
|
||||
item::{Item, ItemHandle},
|
||||
item::{Item, ItemEvent, ItemHandle},
|
||||
searchable::{SearchableItem, SearchableItemHandle},
|
||||
AppState, Workspace,
|
||||
Workspace,
|
||||
};
|
||||
|
||||
use crate::{submit_feedback_button::SubmitFeedbackButton, system_specs::SystemSpecs};
|
||||
|
||||
const FEEDBACK_CHAR_LIMIT: RangeInclusive<usize> = 10..=5000;
|
||||
const FEEDBACK_SUBMISSION_ERROR_TEXT: &str =
|
||||
"Feedback failed to submit, see error log for details.";
|
||||
|
||||
actions!(feedback, [GiveFeedback, SubmitFeedback]);
|
||||
|
||||
pub fn init(system_specs: SystemSpecs, app_state: Arc<AppState>, cx: &mut AppContext) {
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
cx.add_action({
|
||||
move |workspace: &mut Workspace, _: &GiveFeedback, cx: &mut ViewContext<Workspace>| {
|
||||
FeedbackEditor::deploy(system_specs.clone(), workspace, app_state.clone(), cx);
|
||||
FeedbackEditor::deploy(workspace, cx);
|
||||
}
|
||||
});
|
||||
|
||||
cx.add_async_action(
|
||||
|submit_feedback_button: &mut SubmitFeedbackButton, _: &SubmitFeedback, cx| {
|
||||
if let Some(active_item) = submit_feedback_button.active_item.as_ref() {
|
||||
Some(active_item.update(cx, |feedback_editor, cx| feedback_editor.handle_save(cx)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct FeedbackRequestBody<'a> {
|
||||
feedback_text: &'a str,
|
||||
metrics_id: Option<Arc<str>>,
|
||||
installation_id: Option<Arc<str>>,
|
||||
system_specs: SystemSpecs,
|
||||
is_staff: bool,
|
||||
token: &'a str,
|
||||
|
@ -94,7 +83,7 @@ impl FeedbackEditor {
|
|||
}
|
||||
}
|
||||
|
||||
fn handle_save(&mut self, cx: &mut ViewContext<Self>) -> Task<anyhow::Result<()>> {
|
||||
pub fn submit(&mut self, cx: &mut ViewContext<Self>) -> Task<anyhow::Result<()>> {
|
||||
let feedback_text = self.editor.read(cx).text(cx);
|
||||
let feedback_char_count = feedback_text.chars().count();
|
||||
let feedback_text = feedback_text.trim().to_string();
|
||||
|
@ -133,10 +122,8 @@ impl FeedbackEditor {
|
|||
if answer == Some(0) {
|
||||
match FeedbackEditor::submit_feedback(&feedback_text, client, specs).await {
|
||||
Ok(_) => {
|
||||
this.update(&mut cx, |_, cx| {
|
||||
cx.dispatch_action(workspace::CloseActiveItem);
|
||||
})
|
||||
.log_err();
|
||||
this.update(&mut cx, |_, cx| cx.emit(editor::Event::Closed))
|
||||
.log_err();
|
||||
}
|
||||
Err(error) => {
|
||||
log::error!("{}", error);
|
||||
|
@ -164,13 +151,16 @@ impl FeedbackEditor {
|
|||
) -> anyhow::Result<()> {
|
||||
let feedback_endpoint = format!("{}/api/feedback", *ZED_SERVER_URL);
|
||||
|
||||
let metrics_id = zed_client.metrics_id();
|
||||
let is_staff = zed_client.is_staff();
|
||||
let telemetry = zed_client.telemetry();
|
||||
let metrics_id = telemetry.metrics_id();
|
||||
let installation_id = telemetry.installation_id();
|
||||
let is_staff = telemetry.is_staff();
|
||||
let http_client = zed_client.http_client();
|
||||
|
||||
let request = FeedbackRequestBody {
|
||||
feedback_text: &feedback_text,
|
||||
metrics_id,
|
||||
installation_id,
|
||||
system_specs,
|
||||
is_staff: is_staff.unwrap_or(false),
|
||||
token: ZED_SECRET_CLIENT_TOKEN,
|
||||
|
@ -197,22 +187,21 @@ impl FeedbackEditor {
|
|||
}
|
||||
|
||||
impl FeedbackEditor {
|
||||
pub fn deploy(
|
||||
system_specs: SystemSpecs,
|
||||
_: &mut Workspace,
|
||||
app_state: Arc<AppState>,
|
||||
cx: &mut ViewContext<Workspace>,
|
||||
) {
|
||||
let markdown = app_state.languages.language_for_name("Markdown");
|
||||
pub fn deploy(workspace: &mut Workspace, cx: &mut ViewContext<Workspace>) {
|
||||
let markdown = workspace
|
||||
.app_state()
|
||||
.languages
|
||||
.language_for_name("Markdown");
|
||||
cx.spawn(|workspace, mut cx| async move {
|
||||
let markdown = markdown.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().clone();
|
||||
let buffer = project
|
||||
.update(cx, |project, cx| project.create_buffer("", markdown, cx))
|
||||
.expect("creating buffers on a local workspace always succeeds");
|
||||
let system_specs = SystemSpecs::new(cx);
|
||||
let feedback_editor = cx
|
||||
.add_view(|cx| FeedbackEditor::new(system_specs, project, buffer, cx));
|
||||
workspace.add_item(Box::new(feedback_editor), cx);
|
||||
|
@ -290,7 +279,7 @@ impl Item for FeedbackEditor {
|
|||
_: ModelHandle<Project>,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Task<anyhow::Result<()>> {
|
||||
self.handle_save(cx)
|
||||
self.submit(cx)
|
||||
}
|
||||
|
||||
fn save_as(
|
||||
|
@ -299,7 +288,7 @@ impl Item for FeedbackEditor {
|
|||
_: std::path::PathBuf,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Task<anyhow::Result<()>> {
|
||||
self.handle_save(cx)
|
||||
self.submit(cx)
|
||||
}
|
||||
|
||||
fn reload(
|
||||
|
@ -352,6 +341,10 @@ impl Item for FeedbackEditor {
|
|||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn to_item_events(event: &Self::Event) -> SmallVec<[ItemEvent; 2]> {
|
||||
Editor::to_item_events(event)
|
||||
}
|
||||
}
|
||||
|
||||
impl SearchableItem for FeedbackEditor {
|
||||
|
|
|
@ -6,7 +6,7 @@ use gpui::{
|
|||
use settings::Settings;
|
||||
use workspace::{item::ItemHandle, ToolbarItemLocation, ToolbarItemView};
|
||||
|
||||
use crate::{feedback_editor::FeedbackEditor, OpenZedCommunityRepo};
|
||||
use crate::{feedback_editor::FeedbackEditor, open_zed_community_repo, OpenZedCommunityRepo};
|
||||
|
||||
pub struct FeedbackInfoText {
|
||||
active_item: Option<ViewHandle<FeedbackEditor>>,
|
||||
|
@ -57,7 +57,7 @@ impl View for FeedbackInfoText {
|
|||
})
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(MouseButton::Left, |_, _, cx| {
|
||||
cx.dispatch_action(OpenZedCommunityRepo)
|
||||
open_zed_community_repo(&Default::default(), cx)
|
||||
}),
|
||||
)
|
||||
.with_child(
|
||||
|
|
|
@ -1,12 +1,16 @@
|
|||
use crate::feedback_editor::{FeedbackEditor, SubmitFeedback};
|
||||
use anyhow::Result;
|
||||
use gpui::{
|
||||
elements::{Label, MouseEventHandler},
|
||||
platform::{CursorStyle, MouseButton},
|
||||
AnyElement, Element, Entity, View, ViewContext, ViewHandle,
|
||||
AnyElement, AppContext, Element, Entity, Task, View, ViewContext, ViewHandle,
|
||||
};
|
||||
use settings::Settings;
|
||||
use workspace::{item::ItemHandle, ToolbarItemLocation, ToolbarItemView};
|
||||
|
||||
use crate::feedback_editor::{FeedbackEditor, SubmitFeedback};
|
||||
pub fn init(cx: &mut AppContext) {
|
||||
cx.add_async_action(SubmitFeedbackButton::submit);
|
||||
}
|
||||
|
||||
pub struct SubmitFeedbackButton {
|
||||
pub(crate) active_item: Option<ViewHandle<FeedbackEditor>>,
|
||||
|
@ -18,6 +22,18 @@ impl SubmitFeedbackButton {
|
|||
active_item: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn submit(
|
||||
&mut self,
|
||||
_: &SubmitFeedback,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Option<Task<Result<()>>> {
|
||||
if let Some(active_item) = self.active_item.as_ref() {
|
||||
Some(active_item.update(cx, |feedback_editor, cx| feedback_editor.submit(cx)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Entity for SubmitFeedbackButton {
|
||||
|
@ -39,8 +55,8 @@ impl View for SubmitFeedbackButton {
|
|||
.with_style(style.container)
|
||||
})
|
||||
.with_cursor_style(CursorStyle::PointingHand)
|
||||
.on_click(MouseButton::Left, |_, _, cx| {
|
||||
cx.dispatch_action(SubmitFeedback)
|
||||
.on_click(MouseButton::Left, |_, this, cx| {
|
||||
this.submit(&Default::default(), cx);
|
||||
})
|
||||
.aligned()
|
||||
.contained()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue