From 2c8049270a120f6f25414f7695d3b336fca3b548 Mon Sep 17 00:00:00 2001 From: Finn Evers Date: Mon, 26 May 2025 23:57:45 +0200 Subject: [PATCH] language_tools: Increase available space for language server logs (#30742) This PR contains some small improvements for the language server log editors. Due to the large gutter as well as the introduction of the minimap, the horizontally available space was rather small. As these editors soft wrap at the editor width, it resulted in the logs becoming vertically larger and somewhat harder to read. The improvement here is to disable all elements in the gutter that will never appear or be used in the logs anyway. Furthermore, I opted to disable the minimap altogether, since from my point of view it did not contain any valuable information about the logs being shown. First image is the current main, second is this branch. I put these below each other so the difference is easier to spot. ![main](https://github.com/user-attachments/assets/b3796e5f-4fe3-48c8-95a4-d3b84c607963) ![PR](https://github.com/user-attachments/assets/bd8a4e6c-dbbb-4a9e-99aa-474fa073196f) Release Notes: - N/A --- crates/editor/src/editor.rs | 56 ++++++++++++++++--- crates/language_tools/src/lsp_log.rs | 80 +++++++++++++++------------- 2 files changed, 94 insertions(+), 42 deletions(-) diff --git a/crates/editor/src/editor.rs b/crates/editor/src/editor.rs index dbee215a117ed24955dd49ac58f4b2faffb11a10..4334e1336e8cd36e264e8fa38b7d6b95d5b5a2fc 100644 --- a/crates/editor/src/editor.rs +++ b/crates/editor/src/editor.rs @@ -716,18 +716,39 @@ impl ScrollbarMarkerState { #[derive(Clone, Copy, PartialEq, Eq)] pub enum MinimapVisibility { Disabled, - Enabled(bool), + Enabled { + /// The configuration currently present in the users settings. + setting_configuration: bool, + /// Whether to override the currently set visibility from the users setting. + toggle_override: bool, + }, } impl MinimapVisibility { fn for_mode(mode: &EditorMode, cx: &App) -> Self { if mode.is_full() { - Self::Enabled(EditorSettings::get_global(cx).minimap.minimap_enabled()) + Self::Enabled { + setting_configuration: EditorSettings::get_global(cx).minimap.minimap_enabled(), + toggle_override: false, + } } else { Self::Disabled } } + fn hidden(&self) -> Self { + match *self { + Self::Enabled { + setting_configuration, + .. + } => Self::Enabled { + setting_configuration, + toggle_override: setting_configuration, + }, + Self::Disabled => Self::Disabled, + } + } + fn disabled(&self) -> bool { match *self { Self::Disabled => true, @@ -735,16 +756,35 @@ impl MinimapVisibility { } } + fn settings_visibility(&self) -> bool { + match *self { + Self::Enabled { + setting_configuration, + .. + } => setting_configuration, + _ => false, + } + } + fn visible(&self) -> bool { match *self { - Self::Enabled(visible) => visible, + Self::Enabled { + setting_configuration, + toggle_override, + } => setting_configuration ^ toggle_override, _ => false, } } fn toggle_visibility(&self) -> Self { match *self { - Self::Enabled(visible) => Self::Enabled(!visible), + Self::Enabled { + toggle_override, + setting_configuration, + } => Self::Enabled { + setting_configuration, + toggle_override: !toggle_override, + }, Self::Disabled => Self::Disabled, } } @@ -16979,6 +17019,10 @@ impl Editor { self.set_minimap_visibility(MinimapVisibility::Disabled, window, cx); } + pub fn hide_minimap_by_default(&mut self, window: &mut Window, cx: &mut Context) { + self.set_minimap_visibility(self.minimap_visibility.hidden(), window, cx); + } + /// Normally the text in full mode and auto height editors is padded on the /// left side by roughly half a character width for improved hit testing. /// @@ -18518,9 +18562,9 @@ impl Editor { } let minimap_settings = EditorSettings::get_global(cx).minimap; - if self.minimap_visibility.visible() != minimap_settings.minimap_enabled() { + if self.minimap_visibility.settings_visibility() != minimap_settings.minimap_enabled() { self.set_minimap_visibility( - self.minimap_visibility.toggle_visibility(), + MinimapVisibility::for_mode(self.mode(), cx), window, cx, ); diff --git a/crates/language_tools/src/lsp_log.rs b/crates/language_tools/src/lsp_log.rs index ef0d5e6d03f07ee7cc2f3dcf24f2ddc2d00b9aca..3acb1cb2b0a866deeee3b260f8a8b5a85b3e90a8 100644 --- a/crates/language_tools/src/lsp_log.rs +++ b/crates/language_tools/src/lsp_log.rs @@ -702,15 +702,7 @@ impl LspLogView { window: &mut Window, cx: &mut Context, ) -> (Entity, Vec) { - let editor = cx.new(|cx| { - let mut editor = Editor::multi_line(window, cx); - editor.set_text(log_contents, window, cx); - editor.move_to_end(&MoveToEnd, window, cx); - editor.set_read_only(true); - editor.set_show_edit_predictions(Some(false), window, cx); - editor.set_soft_wrap_mode(SoftWrap::EditorWidth, cx); - editor - }); + let editor = initialize_new_editor(log_contents, true, window, cx); let editor_subscription = cx.subscribe( &editor, |_, _, event: &EditorEvent, cx: &mut Context| cx.emit(event.clone()), @@ -727,10 +719,8 @@ impl LspLogView { window: &mut Window, cx: &mut Context, ) -> (Entity, Vec) { - let editor = cx.new(|cx| { - let mut editor = Editor::multi_line(window, cx); - let server_info = format!( - "* Server: {NAME} (id {ID}) + let server_info = format!( + "* Server: {NAME} (id {ID}) * Binary: {BINARY:#?} @@ -740,29 +730,24 @@ impl LspLogView { * Capabilities: {CAPABILITIES} * Configuration: {CONFIGURATION}", - NAME = server.name(), - ID = server.server_id(), - BINARY = server.binary(), - WORKSPACE_FOLDERS = server - .workspace_folders() - .iter() - .filter_map(|path| path - .to_file_path() - .ok() - .map(|path| path.to_string_lossy().into_owned())) - .collect::>() - .join(", "), - CAPABILITIES = serde_json::to_string_pretty(&server.capabilities()) - .unwrap_or_else(|e| format!("Failed to serialize capabilities: {e}")), - CONFIGURATION = serde_json::to_string_pretty(server.configuration()) - .unwrap_or_else(|e| format!("Failed to serialize configuration: {e}")), - ); - editor.set_text(server_info, window, cx); - editor.set_read_only(true); - editor.set_show_edit_predictions(Some(false), window, cx); - editor.set_soft_wrap_mode(SoftWrap::EditorWidth, cx); - editor - }); + NAME = server.name(), + ID = server.server_id(), + BINARY = server.binary(), + WORKSPACE_FOLDERS = server + .workspace_folders() + .iter() + .filter_map(|path| path + .to_file_path() + .ok() + .map(|path| path.to_string_lossy().into_owned())) + .collect::>() + .join(", "), + CAPABILITIES = serde_json::to_string_pretty(&server.capabilities()) + .unwrap_or_else(|e| format!("Failed to serialize capabilities: {e}")), + CONFIGURATION = serde_json::to_string_pretty(server.configuration()) + .unwrap_or_else(|e| format!("Failed to serialize configuration: {e}")), + ); + let editor = initialize_new_editor(server_info, false, window, cx); let editor_subscription = cx.subscribe( &editor, |_, _, event: &EditorEvent, cx: &mut Context| cx.emit(event.clone()), @@ -1550,6 +1535,29 @@ impl Render for LspLogToolbarItemView { } } +fn initialize_new_editor( + content: String, + move_to_end: bool, + window: &mut Window, + cx: &mut App, +) -> Entity { + cx.new(|cx| { + let mut editor = Editor::multi_line(window, cx); + editor.hide_minimap_by_default(window, cx); + editor.set_text(content, window, cx); + editor.set_show_git_diff_gutter(false, cx); + editor.set_show_runnables(false, cx); + editor.set_show_breakpoints(false, cx); + editor.set_read_only(true); + editor.set_show_edit_predictions(Some(false), window, cx); + editor.set_soft_wrap_mode(SoftWrap::EditorWidth, cx); + if move_to_end { + editor.move_to_end(&MoveToEnd, window, cx); + } + editor + }) +} + const RPC_MESSAGES: &str = "RPC Messages"; const SERVER_LOGS: &str = "Server Logs"; const SERVER_TRACE: &str = "Server Trace";