mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 08:54:04 +00:00
WIP
Co-Authored-By: Mikayla Maki <mikayla.c.maki@gmail.com>
This commit is contained in:
parent
c1934d6232
commit
083986dfae
3 changed files with 90 additions and 34 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2037,6 +2037,7 @@ dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"postage",
|
"postage",
|
||||||
"project",
|
"project",
|
||||||
|
"search",
|
||||||
"serde",
|
"serde",
|
||||||
"settings",
|
"settings",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
|
|
|
@ -21,6 +21,7 @@ isahc = "1.7"
|
||||||
lazy_static = "1.4.0"
|
lazy_static = "1.4.0"
|
||||||
postage = { version = "0.4", features = ["futures-traits"] }
|
postage = { version = "0.4", features = ["futures-traits"] }
|
||||||
project = { path = "../project" }
|
project = { path = "../project" }
|
||||||
|
search = { path = "../search" }
|
||||||
serde = { version = "1.0", features = ["derive", "rc"] }
|
serde = { version = "1.0", features = ["derive", "rc"] }
|
||||||
settings = { path = "../settings" }
|
settings = { path = "../settings" }
|
||||||
smallvec = { version = "1.6", features = ["union"] }
|
smallvec = { version = "1.6", features = ["union"] }
|
||||||
|
|
|
@ -9,10 +9,9 @@ use gpui::{
|
||||||
elements::{ChildView, Flex, Label, MouseEventHandler, ParentElement, Stack, Text},
|
elements::{ChildView, Flex, Label, MouseEventHandler, ParentElement, Stack, Text},
|
||||||
serde_json, AnyViewHandle, CursorStyle, Element, ElementBox, Entity, ModelHandle, MouseButton,
|
serde_json, AnyViewHandle, CursorStyle, Element, ElementBox, Entity, ModelHandle, MouseButton,
|
||||||
MutableAppContext, PromptLevel, RenderContext, Task, View, ViewContext, ViewHandle,
|
MutableAppContext, PromptLevel, RenderContext, Task, View, ViewContext, ViewHandle,
|
||||||
WeakViewHandle,
|
|
||||||
};
|
};
|
||||||
use isahc::Request;
|
use isahc::Request;
|
||||||
use language::{Language, LanguageConfig};
|
use language::Buffer;
|
||||||
use postage::prelude::Stream;
|
use postage::prelude::Stream;
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
@ -162,43 +161,44 @@ struct FeedbackRequestBody<'a> {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct FeedbackEditor {
|
struct FeedbackEditor {
|
||||||
editor: ViewHandle<Editor>,
|
editor: ViewHandle<Editor>,
|
||||||
|
project: ModelHandle<Project>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FeedbackEditor {
|
impl FeedbackEditor {
|
||||||
fn new(
|
fn new_with_buffer(
|
||||||
project_handle: ModelHandle<Project>,
|
project: ModelHandle<Project>,
|
||||||
_: WeakViewHandle<Workspace>,
|
buffer: ModelHandle<Buffer>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
|
const FEDBACK_PLACEHOLDER_TEXT: &str = "Thanks for spending time with Zed. Enter your feedback here in the form of Markdown. Save the tab to submit your feedback.";
|
||||||
|
|
||||||
|
let editor = cx.add_view(|cx| {
|
||||||
|
let mut editor = Editor::for_buffer(buffer, Some(project.clone()), cx);
|
||||||
|
editor.set_vertical_scroll_margin(5, cx);
|
||||||
|
editor.set_placeholder_text(FEDBACK_PLACEHOLDER_TEXT, cx);
|
||||||
|
editor
|
||||||
|
});
|
||||||
|
|
||||||
|
let this = Self { editor, project };
|
||||||
|
this
|
||||||
|
}
|
||||||
|
|
||||||
|
fn new(project: ModelHandle<Project>, cx: &mut ViewContext<Self>) -> Self {
|
||||||
// TODO FEEDBACK: This doesn't work like I expected it would
|
// TODO FEEDBACK: This doesn't work like I expected it would
|
||||||
// let markdown_language = Arc::new(Language::new(
|
// let markdown_language = Arc::new(Language::new(
|
||||||
// LanguageConfig::default(),
|
// LanguageConfig::default(),
|
||||||
// Some(tree_sitter_markdown::language()),
|
// Some(tree_sitter_markdown::language()),
|
||||||
// ));
|
// ));
|
||||||
|
|
||||||
let markdown_language = project_handle
|
let markdown_language = project.read(cx).languages().get_language("Markdown");
|
||||||
.read(cx)
|
|
||||||
.languages()
|
|
||||||
.get_language("Markdown")
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let buffer = project_handle
|
let buffer = project
|
||||||
.update(cx, |project, cx| {
|
.update(cx, |project, cx| {
|
||||||
project.create_buffer("", Some(markdown_language), cx)
|
project.create_buffer("", markdown_language, cx)
|
||||||
})
|
})
|
||||||
.expect("creating buffers on a local workspace always succeeds");
|
.expect("creating buffers on a local workspace always succeeds");
|
||||||
|
|
||||||
const FEDBACK_PLACEHOLDER_TEXT: &str = "Thanks for spending time with Zed. Enter your feedback here in the form of Markdown. Save the tab to submit your feedback.";
|
Self::new_with_buffer(project, buffer, cx)
|
||||||
|
|
||||||
let editor = cx.add_view(|cx| {
|
|
||||||
let mut editor = Editor::for_buffer(buffer, Some(project_handle.clone()), cx);
|
|
||||||
editor.set_vertical_scroll_margin(5, cx);
|
|
||||||
editor.set_placeholder_text(FEDBACK_PLACEHOLDER_TEXT, cx);
|
|
||||||
editor
|
|
||||||
});
|
|
||||||
|
|
||||||
let this = Self { editor };
|
|
||||||
this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_save(
|
fn handle_save(
|
||||||
|
@ -297,7 +297,7 @@ impl FeedbackEditor {
|
||||||
bail!("Feedback API failed with: {}", response_status)
|
bail!("Feedback API failed with: {}", response_status)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.read_with(&async_cx, |this, cx| -> anyhow::Result<()> {
|
this.read_with(&async_cx, |_this, _cx| -> anyhow::Result<()> {
|
||||||
bail!("Error")
|
bail!("Error")
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
|
@ -326,9 +326,8 @@ impl FeedbackEditor {
|
||||||
// if let Some(existing) = workspace.item_of_type::<FeedbackEditor>(cx) {
|
// if let Some(existing) = workspace.item_of_type::<FeedbackEditor>(cx) {
|
||||||
// workspace.activate_item(&existing, cx);
|
// workspace.activate_item(&existing, cx);
|
||||||
// } else {
|
// } else {
|
||||||
let workspace_handle = cx.weak_handle();
|
let feedback_editor =
|
||||||
let feedback_editor = cx
|
cx.add_view(|cx| FeedbackEditor::new(workspace.project().clone(), cx));
|
||||||
.add_view(|cx| FeedbackEditor::new(workspace.project().clone(), workspace_handle, cx));
|
|
||||||
workspace.add_item(Box::new(feedback_editor), cx);
|
workspace.add_item(Box::new(feedback_editor), cx);
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
@ -395,19 +394,19 @@ impl Item for FeedbackEditor {
|
||||||
|
|
||||||
fn save(
|
fn save(
|
||||||
&mut self,
|
&mut self,
|
||||||
project_handle: gpui::ModelHandle<Project>,
|
project: gpui::ModelHandle<Project>,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Task<anyhow::Result<()>> {
|
) -> Task<anyhow::Result<()>> {
|
||||||
self.handle_save(project_handle, cx)
|
self.handle_save(project, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_as(
|
fn save_as(
|
||||||
&mut self,
|
&mut self,
|
||||||
project_handle: gpui::ModelHandle<Project>,
|
project: gpui::ModelHandle<Project>,
|
||||||
_: std::path::PathBuf,
|
_: std::path::PathBuf,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> Task<anyhow::Result<()>> {
|
) -> Task<anyhow::Result<()>> {
|
||||||
self.handle_save(project_handle, cx)
|
self.handle_save(project, cx)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reload(
|
fn reload(
|
||||||
|
@ -426,9 +425,19 @@ impl Item for FeedbackEditor {
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
{
|
{
|
||||||
// TODO FEEDBACK: split is busted
|
let buffer = self
|
||||||
// Some(self.clone())
|
.editor
|
||||||
None
|
.read(cx)
|
||||||
|
.buffer()
|
||||||
|
.read(cx)
|
||||||
|
.as_singleton()
|
||||||
|
.expect("Feedback buffer is only ever singleton");
|
||||||
|
|
||||||
|
Some(Self::new_with_buffer(
|
||||||
|
self.project.clone(),
|
||||||
|
buffer.clone(),
|
||||||
|
cx,
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialized_item_kind() -> Option<&'static str> {
|
fn serialized_item_kind() -> Option<&'static str> {
|
||||||
|
@ -446,5 +455,50 @@ impl Item for FeedbackEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// impl SearchableItem for FeedbackEditor {
|
||||||
|
// type Match = <Editor as SearchableItem>::Match;
|
||||||
|
|
||||||
|
// fn to_search_event(event: &Self::Event) -> Option<workspace::searchable::SearchEvent> {
|
||||||
|
// Editor::to_search_event(event)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fn clear_matches(&mut self, cx: &mut ViewContext<Self>) {
|
||||||
|
// self.
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fn update_matches(&mut self, matches: Vec<Self::Match>, cx: &mut ViewContext<Self>) {
|
||||||
|
// todo!()
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fn query_suggestion(&mut self, cx: &mut ViewContext<Self>) -> String {
|
||||||
|
// todo!()
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fn activate_match(
|
||||||
|
// &mut self,
|
||||||
|
// index: usize,
|
||||||
|
// matches: Vec<Self::Match>,
|
||||||
|
// cx: &mut ViewContext<Self>,
|
||||||
|
// ) {
|
||||||
|
// todo!()
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fn find_matches(
|
||||||
|
// &mut self,
|
||||||
|
// query: project::search::SearchQuery,
|
||||||
|
// cx: &mut ViewContext<Self>,
|
||||||
|
// ) -> Task<Vec<Self::Match>> {
|
||||||
|
// todo!()
|
||||||
|
// }
|
||||||
|
|
||||||
|
// fn active_match_index(
|
||||||
|
// &mut self,
|
||||||
|
// matches: Vec<Self::Match>,
|
||||||
|
// cx: &mut ViewContext<Self>,
|
||||||
|
// ) -> Option<usize> {
|
||||||
|
// todo!()
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// TODO FEEDBACK: search buffer?
|
// TODO FEEDBACK: search buffer?
|
||||||
// TODO FEEDBACK: warnings
|
// TODO FEEDBACK: warnings
|
||||||
|
|
Loading…
Reference in a new issue