language_tools.rs

 1mod highlights_tree_view;
 2mod key_context_view;
 3pub mod lsp_button;
 4pub mod lsp_log_view;
 5mod syntax_tree_view;
 6
 7#[cfg(test)]
 8mod lsp_log_view_tests;
 9
10use gpui::{App, AppContext, Entity};
11
12pub use highlights_tree_view::{HighlightsTreeToolbarItemView, HighlightsTreeView};
13pub use lsp_log_view::LspLogView;
14pub use syntax_tree_view::{SyntaxTreeToolbarItemView, SyntaxTreeView};
15use ui::{Context, Window};
16use workspace::{Item, ItemHandle, SplitDirection, Workspace};
17
18pub fn init(cx: &mut App) {
19    highlights_tree_view::init(cx);
20    lsp_log_view::init(false, cx);
21    syntax_tree_view::init(cx);
22    key_context_view::init(cx);
23}
24
25fn get_or_create_tool<T>(
26    workspace: &mut Workspace,
27    destination: SplitDirection,
28    window: &mut Window,
29    cx: &mut Context<Workspace>,
30    new_tool: impl FnOnce(&mut Window, &mut Context<T>) -> T,
31) -> Entity<T>
32where
33    T: Item,
34{
35    if let Some(item) = workspace.item_of_type::<T>(cx) {
36        return item;
37    }
38
39    let new_tool = cx.new(|cx| new_tool(window, cx));
40    match workspace.find_pane_in_direction(destination, cx) {
41        Some(right_pane) => {
42            workspace.add_item(
43                right_pane,
44                new_tool.boxed_clone(),
45                None,
46                true,
47                true,
48                window,
49                cx,
50            );
51        }
52        None => {
53            workspace.split_item(destination, new_tool.boxed_clone(), window, cx);
54        }
55    }
56    new_tool
57}