indent guides: Respect language specific settings in multibuffers (#12528)
Indent guides can be configured per language, meaning that in a multi buffer we can get excerpts where indent guides should be disabled/enabled/styled differently than other excerpts. Imagine the following scenario, i have indent guides disabled in my settings, but want to enable them for JS and Python. I also want to use a different line width for python files. Something like this is now supported: <img width="445" alt="image" src="https://github.com/zed-industries/zed/assets/53836821/0c91411c-145c-4210-a883-4c469d5cb828"> And the relevant settings for the example above: ```json "indent_guides": { "enabled": false }, "languages": { "JavaScript": { "indent_guides": { "enabled": true } }, "Python": { "indent_guides": { "enabled": true, "line_width": 5 } } } ``` Release Notes: - Respect language specific settings when showing indent guides in a multibuffer - Fixes an issue where indent guide specific settings were not recognized when specified in local settings
This commit is contained in:
parent
95e360b170
commit
ab8d25e0a2
6 changed files with 113 additions and 101 deletions
|
@ -2,7 +2,7 @@ use std::{ops::Range, time::Duration};
|
|||
|
||||
use collections::HashSet;
|
||||
use gpui::{AppContext, Task};
|
||||
use language::BufferRow;
|
||||
use language::{language_settings::language_settings, BufferRow};
|
||||
use multi_buffer::{MultiBufferIndentGuide, MultiBufferRow};
|
||||
use text::{BufferId, LineIndent, Point};
|
||||
use ui::ViewContext;
|
||||
|
@ -37,13 +37,26 @@ impl Editor {
|
|||
snapshot: &DisplaySnapshot,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
) -> Option<Vec<MultiBufferIndentGuide>> {
|
||||
let enabled = self.should_show_indent_guides(cx);
|
||||
let show_indent_guides = self.should_show_indent_guides().unwrap_or_else(|| {
|
||||
if let Some(buffer) = self.buffer().read(cx).as_singleton() {
|
||||
language_settings(buffer.read(cx).language(), buffer.read(cx).file(), cx)
|
||||
.indent_guides
|
||||
.enabled
|
||||
} else {
|
||||
true
|
||||
}
|
||||
});
|
||||
|
||||
if enabled {
|
||||
Some(indent_guides_in_range(visible_buffer_range, snapshot, cx))
|
||||
} else {
|
||||
None
|
||||
if !show_indent_guides {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(indent_guides_in_range(
|
||||
visible_buffer_range,
|
||||
self.should_show_indent_guides() == Some(true),
|
||||
snapshot,
|
||||
cx,
|
||||
))
|
||||
}
|
||||
|
||||
pub fn find_active_indent_guide_indices(
|
||||
|
@ -77,9 +90,14 @@ impl Editor {
|
|||
|
||||
if state.should_refresh() {
|
||||
state.cursor_row = cursor_row;
|
||||
let snapshot = snapshot.clone();
|
||||
state.dirty = false;
|
||||
|
||||
if indent_guides.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let snapshot = snapshot.clone();
|
||||
|
||||
let task = cx
|
||||
.background_executor()
|
||||
.spawn(resolve_indented_range(snapshot, cursor_row));
|
||||
|
@ -131,6 +149,7 @@ impl Editor {
|
|||
|
||||
pub fn indent_guides_in_range(
|
||||
visible_buffer_range: Range<MultiBufferRow>,
|
||||
ignore_disabled_for_language: bool,
|
||||
snapshot: &DisplaySnapshot,
|
||||
cx: &AppContext,
|
||||
) -> Vec<MultiBufferIndentGuide> {
|
||||
|
@ -143,7 +162,7 @@ pub fn indent_guides_in_range(
|
|||
|
||||
snapshot
|
||||
.buffer_snapshot
|
||||
.indent_guides_in_range(start_anchor..end_anchor, cx)
|
||||
.indent_guides_in_range(start_anchor..end_anchor, ignore_disabled_for_language, cx)
|
||||
.into_iter()
|
||||
.filter(|indent_guide| {
|
||||
// Filter out indent guides that are inside a fold
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue