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:
Bennet Bo Fenner 2024-06-01 20:33:32 +02:00 committed by GitHub
parent 95e360b170
commit ab8d25e0a2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 113 additions and 101 deletions

View file

@ -3289,12 +3289,17 @@ impl MultiBufferSnapshot {
pub fn indent_guides_in_range(
&self,
range: Range<Anchor>,
ignore_disabled_for_language: bool,
cx: &AppContext,
) -> Vec<MultiBufferIndentGuide> {
// Fast path for singleton buffers, we can skip the conversion between offsets.
if let Some((_, _, snapshot)) = self.as_singleton() {
return snapshot
.indent_guides_in_range(range.start.text_anchor..range.end.text_anchor, cx)
.indent_guides_in_range(
range.start.text_anchor..range.end.text_anchor,
ignore_disabled_for_language,
cx,
)
.into_iter()
.map(|guide| MultiBufferIndentGuide {
multibuffer_row_range: MultiBufferRow(guide.start_row)
@ -3314,7 +3319,11 @@ impl MultiBufferSnapshot {
excerpt
.buffer
.indent_guides_in_range(excerpt.range.context.clone(), cx)
.indent_guides_in_range(
excerpt.range.context.clone(),
ignore_disabled_for_language,
cx,
)
.into_iter()
.map(move |indent_guide| {
let start_row = excerpt_offset_row