First fixes
This commit is contained in:
parent
64925231b0
commit
676a07270e
2 changed files with 51 additions and 76 deletions
|
@ -2,24 +2,19 @@ use collections::{HashMap, VecDeque};
|
||||||
use editor::{Editor, MoveToEnd};
|
use editor::{Editor, MoveToEnd};
|
||||||
use futures::{channel::mpsc, StreamExt};
|
use futures::{channel::mpsc, StreamExt};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions,
|
actions, AnchorCorner, AnyElement, AppContext, Context, CursorStyle, Element, Empty, Entity,
|
||||||
elements::{
|
Model, ModelContext, MouseButton, Overlay, OverlayFitMode, Subscription, View, ViewContext,
|
||||||
AnchorCorner, ChildView, Empty, Flex, Label, MouseEventHandler, Overlay, OverlayFitMode,
|
VisualContext, WeakModel,
|
||||||
ParentElement, Stack,
|
|
||||||
},
|
|
||||||
platform::{CursorStyle, MouseButton},
|
|
||||||
AnyElement, AppContext, Element, Entity, Model, ModelContext, Subscription, View, View,
|
|
||||||
ViewContext, WeakModel,
|
|
||||||
};
|
};
|
||||||
use language::{LanguageServerId, LanguageServerName};
|
use language::{LanguageServerId, LanguageServerName};
|
||||||
use lsp::IoKind;
|
use lsp::IoKind;
|
||||||
use project::{search::SearchQuery, Project};
|
use project::{search::SearchQuery, Project};
|
||||||
use std::{borrow::Cow, sync::Arc};
|
use std::{borrow::Cow, sync::Arc};
|
||||||
use theme::{ui, Theme};
|
use theme::Theme;
|
||||||
use workspace::{
|
use workspace::{
|
||||||
item::{Item, ItemHandle},
|
item::{Item, ItemHandle},
|
||||||
searchable::{SearchableItem, SearchableItemHandle},
|
searchable::{SearchableItem, SearchableItemHandle},
|
||||||
ToolbarItemLocation, ToolbarItemView, Workspace, WorkspaceCreated,
|
ToolbarItemLocation, ToolbarItemView, Workspace,
|
||||||
};
|
};
|
||||||
|
|
||||||
const SEND_LINE: &str = "// Send:";
|
const SEND_LINE: &str = "// Send:";
|
||||||
|
@ -83,37 +78,29 @@ pub(crate) struct LogMenuItem {
|
||||||
actions!(debug, [OpenLanguageServerLogs]);
|
actions!(debug, [OpenLanguageServerLogs]);
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
pub fn init(cx: &mut AppContext) {
|
||||||
let log_store = cx.add_model(|cx| LogStore::new(cx));
|
let log_store = cx.build_model(|cx| LogStore::new(cx));
|
||||||
|
|
||||||
cx.subscribe_global::<WorkspaceCreated, _>({
|
cx.observe_new_views(|workspace: &mut Workspace, cx| {
|
||||||
let log_store = log_store.clone();
|
let project = workspace.project();
|
||||||
move |event, cx| {
|
if project.read(cx).is_local() {
|
||||||
let workspace = &event.0;
|
log_store.update(cx, |store, cx| {
|
||||||
if let Some(workspace) = workspace.upgrade(cx) {
|
store.add_project(&project, cx);
|
||||||
let project = workspace.read(cx).project().clone();
|
});
|
||||||
if project.read(cx).is_local() {
|
|
||||||
log_store.update(cx, |store, cx| {
|
|
||||||
store.add_project(&project, cx);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
.detach();
|
|
||||||
|
|
||||||
cx.add_action(
|
workspace.register_action(|workspace, _: &OpenLanguageServerLogs, cx| {
|
||||||
move |workspace: &mut Workspace, _: &OpenLanguageServerLogs, cx: _| {
|
|
||||||
let project = workspace.project().read(cx);
|
let project = workspace.project().read(cx);
|
||||||
if project.is_local() {
|
if project.is_local() {
|
||||||
workspace.add_item(
|
workspace.add_item(
|
||||||
Box::new(cx.add_view(|cx| {
|
Box::new(cx.build_view(|cx| {
|
||||||
LspLogView::new(workspace.project().clone(), log_store.clone(), cx)
|
LspLogView::new(workspace.project().clone(), log_store.clone(), cx)
|
||||||
})),
|
})),
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
},
|
});
|
||||||
);
|
})
|
||||||
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LogStore {
|
impl LogStore {
|
||||||
|
@ -204,8 +191,7 @@ impl LogStore {
|
||||||
let server_id = server.server_id();
|
let server_id = server.server_id();
|
||||||
server.on_notification::<lsp::notification::LogMessage, _>({
|
server.on_notification::<lsp::notification::LogMessage, _>({
|
||||||
move |params, mut cx| {
|
move |params, mut cx| {
|
||||||
if let Some((project, this)) =
|
if let Some((project, this)) = weak_project.upgrade().zip(this.upgrade(&mut cx))
|
||||||
weak_project.upgrade(&mut cx).zip(this.upgrade(&mut cx))
|
|
||||||
{
|
{
|
||||||
this.update(&mut cx, |this, cx| {
|
this.update(&mut cx, |this, cx| {
|
||||||
this.add_language_server_log(&project, server_id, ¶ms.message, cx);
|
this.add_language_server_log(&project, server_id, ¶ms.message, cx);
|
||||||
|
@ -314,7 +300,7 @@ impl LogStore {
|
||||||
IoKind::StdOut => true,
|
IoKind::StdOut => true,
|
||||||
IoKind::StdIn => false,
|
IoKind::StdIn => false,
|
||||||
IoKind::StdErr => {
|
IoKind::StdErr => {
|
||||||
let project = project.upgrade(cx)?;
|
let project = project.upgrade()?;
|
||||||
let message = format!("stderr: {}", message.trim());
|
let message = format!("stderr: {}", message.trim());
|
||||||
self.add_language_server_log(&project, language_server_id, &message, cx);
|
self.add_language_server_log(&project, language_server_id, &message, cx);
|
||||||
return Some(());
|
return Some(());
|
||||||
|
@ -446,7 +432,7 @@ impl LspLogView {
|
||||||
log_contents: String,
|
log_contents: String,
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) -> (View<Editor>, Subscription) {
|
) -> (View<Editor>, Subscription) {
|
||||||
let editor = cx.add_view(|cx| {
|
let editor = cx.build_view(|cx| {
|
||||||
let mut editor = Editor::multi_line(None, cx);
|
let mut editor = Editor::multi_line(None, cx);
|
||||||
editor.set_text(log_contents, cx);
|
editor.set_text(log_contents, cx);
|
||||||
editor.move_to_end(&MoveToEnd, cx);
|
editor.move_to_end(&MoveToEnd, cx);
|
||||||
|
|
|
@ -1,35 +1,32 @@
|
||||||
use editor::{scroll::autoscroll::Autoscroll, Anchor, Editor, ExcerptId};
|
use editor::{scroll::autoscroll::Autoscroll, Anchor, Editor, ExcerptId};
|
||||||
use gpui::{
|
use gpui::{
|
||||||
actions,
|
actions, AnchorCorner, AppContext, CursorStyle, Div, Element, Empty, Entity, Focusable, Model,
|
||||||
elements::{
|
MouseButton, Overlay, OverlayFitMode, ParentElement, Render, TextStyle, UniformList,
|
||||||
AnchorCorner, Empty, Flex, Label, MouseEventHandler, Overlay, OverlayFitMode,
|
UniformListState, View, ViewContext, VisualContext, WeakView,
|
||||||
ParentElement, ScrollTarget, Stack, UniformList, UniformListState,
|
|
||||||
},
|
|
||||||
fonts::TextStyle,
|
|
||||||
AppContext, CursorStyle, Element, Entity, Model, MouseButton, View, View, ViewContext,
|
|
||||||
WeakView,
|
|
||||||
};
|
};
|
||||||
use language::{Buffer, OwnedSyntaxLayerInfo, SyntaxLayerInfo};
|
use language::{Buffer, OwnedSyntaxLayerInfo, SyntaxLayerInfo};
|
||||||
use std::{mem, ops::Range, sync::Arc};
|
use std::{mem, ops::Range, sync::Arc};
|
||||||
use theme::{Theme, ThemeSettings};
|
use theme::{ActiveTheme, Theme, ThemeSettings};
|
||||||
use tree_sitter::{Node, TreeCursor};
|
use tree_sitter::{Node, TreeCursor};
|
||||||
use workspace::{
|
use workspace::{
|
||||||
item::{Item, ItemHandle},
|
item::{Item, ItemHandle},
|
||||||
|
ui::v_stack,
|
||||||
ToolbarItemLocation, ToolbarItemView, Workspace,
|
ToolbarItemLocation, ToolbarItemView, Workspace,
|
||||||
};
|
};
|
||||||
|
|
||||||
actions!(debug, [OpenSyntaxTreeView]);
|
actions!(debug, [OpenSyntaxTreeView]);
|
||||||
|
|
||||||
pub fn init(cx: &mut AppContext) {
|
pub fn init(cx: &mut AppContext) {
|
||||||
cx.add_action(
|
cx.observe_new_views(|workspace: &mut Workspace, _| {
|
||||||
move |workspace: &mut Workspace, _: &OpenSyntaxTreeView, cx: _| {
|
workspace.register_action(|workspace, _: &OpenSyntaxTreeView, cx| {
|
||||||
let active_item = workspace.active_item(cx);
|
let active_item = workspace.active_item(cx);
|
||||||
let workspace_handle = workspace.weak_handle();
|
let workspace_handle = workspace.weak_handle();
|
||||||
let syntax_tree_view =
|
let syntax_tree_view =
|
||||||
cx.build_view(|cx| SyntaxTreeView::new(workspace_handle, active_item, cx));
|
cx.build_view(|cx| SyntaxTreeView::new(workspace_handle, active_item, cx));
|
||||||
workspace.add_item(Box::new(syntax_tree_view), cx);
|
workspace.add_item(Box::new(syntax_tree_view), cx);
|
||||||
},
|
});
|
||||||
);
|
})
|
||||||
|
.detach();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct SyntaxTreeView {
|
pub struct SyntaxTreeView {
|
||||||
|
@ -49,7 +46,7 @@ pub struct SyntaxTreeToolbarItemView {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct EditorState {
|
struct EditorState {
|
||||||
editor: ViewHandle<Editor>,
|
editor: View<Editor>,
|
||||||
active_buffer: Option<BufferState>,
|
active_buffer: Option<BufferState>,
|
||||||
_subscription: gpui::Subscription,
|
_subscription: gpui::Subscription,
|
||||||
}
|
}
|
||||||
|
@ -79,7 +76,7 @@ impl SyntaxTreeView {
|
||||||
|
|
||||||
this.workspace_updated(active_item, cx);
|
this.workspace_updated(active_item, cx);
|
||||||
cx.observe(
|
cx.observe(
|
||||||
&workspace_handle.upgrade(cx).unwrap(),
|
&workspace_handle.upgrade().unwrap(),
|
||||||
|this, workspace, cx| {
|
|this, workspace, cx| {
|
||||||
this.workspace_updated(workspace.read(cx).active_item(cx), cx);
|
this.workspace_updated(workspace.read(cx).active_item(cx), cx);
|
||||||
},
|
},
|
||||||
|
@ -95,7 +92,7 @@ impl SyntaxTreeView {
|
||||||
cx: &mut ViewContext<Self>,
|
cx: &mut ViewContext<Self>,
|
||||||
) {
|
) {
|
||||||
if let Some(item) = active_item {
|
if let Some(item) = active_item {
|
||||||
if item.id() != cx.view_id() {
|
if item.item_id() != cx.entity_id() {
|
||||||
if let Some(editor) = item.act_as::<Editor>(cx) {
|
if let Some(editor) = item.act_as::<Editor>(cx) {
|
||||||
self.set_editor(editor, cx);
|
self.set_editor(editor, cx);
|
||||||
}
|
}
|
||||||
|
@ -103,7 +100,7 @@ impl SyntaxTreeView {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_editor(&mut self, editor: ViewHandle<Editor>, cx: &mut ViewContext<Self>) {
|
fn set_editor(&mut self, editor: View<Editor>, cx: &mut ViewContext<Self>) {
|
||||||
if let Some(state) = &self.editor {
|
if let Some(state) = &self.editor {
|
||||||
if state.editor == editor {
|
if state.editor == editor {
|
||||||
return;
|
return;
|
||||||
|
@ -115,8 +112,8 @@ impl SyntaxTreeView {
|
||||||
|
|
||||||
let subscription = cx.subscribe(&editor, |this, _, event, cx| {
|
let subscription = cx.subscribe(&editor, |this, _, event, cx| {
|
||||||
let did_reparse = match event {
|
let did_reparse = match event {
|
||||||
editor::Event::Reparsed => true,
|
editor::EditorEvent::Reparsed => true,
|
||||||
editor::Event::SelectionsChanged { .. } => false,
|
editor::EditorEvent::SelectionsChanged { .. } => false,
|
||||||
_ => return,
|
_ => return,
|
||||||
};
|
};
|
||||||
this.editor_updated(did_reparse, cx);
|
this.editor_updated(did_reparse, cx);
|
||||||
|
@ -490,7 +487,7 @@ impl SyntaxTreeToolbarItemView {
|
||||||
&mut self,
|
&mut self,
|
||||||
cx: &mut ViewContext<'_, '_, Self>,
|
cx: &mut ViewContext<'_, '_, Self>,
|
||||||
) -> Option<gpui::AnyElement<Self>> {
|
) -> Option<gpui::AnyElement<Self>> {
|
||||||
let theme = theme::current(cx).clone();
|
let theme = cx.theme().clone();
|
||||||
let tree_view = self.tree_view.as_ref()?;
|
let tree_view = self.tree_view.as_ref()?;
|
||||||
let tree_view = tree_view.read(cx);
|
let tree_view = tree_view.read(cx);
|
||||||
|
|
||||||
|
@ -502,12 +499,12 @@ impl SyntaxTreeToolbarItemView {
|
||||||
enum Menu {}
|
enum Menu {}
|
||||||
|
|
||||||
Some(
|
Some(
|
||||||
Stack::new()
|
v_stack()
|
||||||
.with_child(Self::render_header(&theme, &active_layer, cx))
|
.child(Self::render_header(&theme, &active_layer, cx))
|
||||||
.with_children(self.menu_open.then(|| {
|
.children(self.menu_open.then(|| {
|
||||||
Overlay::new(
|
overlay(
|
||||||
MouseEventHandler::new::<Menu, _>(0, cx, move |_, cx| {
|
mouse_event_handler::<Menu, _>(0, cx, move |_, cx| {
|
||||||
Flex::column()
|
v_stack()
|
||||||
.with_children(active_buffer.syntax_layers().enumerate().map(
|
.with_children(active_buffer.syntax_layers().enumerate().map(
|
||||||
|(ix, layer)| {
|
|(ix, layer)| {
|
||||||
Self::render_menu_item(&theme, &active_layer, layer, ix, cx)
|
Self::render_menu_item(&theme, &active_layer, layer, ix, cx)
|
||||||
|
@ -525,16 +522,9 @@ impl SyntaxTreeToolbarItemView {
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.with_hoverable(true)
|
.with_hoverable(true)
|
||||||
.with_fit_mode(OverlayFitMode::SwitchAnchor)
|
.with_fit_content()
|
||||||
.with_anchor_corner(AnchorCorner::TopLeft)
|
.into_any()
|
||||||
.with_z_index(999)
|
|
||||||
.aligned()
|
|
||||||
.bottom()
|
|
||||||
.left()
|
|
||||||
}))
|
}))
|
||||||
.aligned()
|
|
||||||
.left()
|
|
||||||
.clipped()
|
|
||||||
.into_any(),
|
.into_any(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -639,14 +629,13 @@ fn format_node_range(node: Node) -> String {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Entity for SyntaxTreeToolbarItemView {
|
impl Render for SyntaxTreeToolbarItemView {
|
||||||
type Event = ();
|
type Element = Focusable<Div>;
|
||||||
}
|
|
||||||
|
|
||||||
impl View for SyntaxTreeToolbarItemView {
|
// todo!()
|
||||||
fn ui_name() -> &'static str {
|
// fn ui_name() -> &'static str {
|
||||||
"SyntaxTreeToolbarItemView"
|
// "SyntaxTreeToolbarItemView"
|
||||||
}
|
// }
|
||||||
|
|
||||||
fn render(&mut self, cx: &mut ViewContext<'_, '_, Self>) -> gpui::AnyElement<Self> {
|
fn render(&mut self, cx: &mut ViewContext<'_, '_, Self>) -> gpui::AnyElement<Self> {
|
||||||
self.render_menu(cx)
|
self.render_menu(cx)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue