Indent guides (#11503)

Builds on top of existing work from #2249, but here's a showcase:


https://github.com/zed-industries/zed/assets/53836821/4b346965-6654-496c-b379-75425d9b493f

TODO:
- [x] handle line wrapping
- [x] implement handling in multibuffer (crashes currently)
- [x] add configuration option
- [x] new theme properties? What colors to use?
- [x] Possibly support indents with different colors or background
colors
- [x] investigate edge cases (e.g. indent guides and folds continue on
empty lines even if the next indent is different)
- [x] add more tests (also test `find_active_indent_index`)
- [x] docs (will do in a follow up PR)
- [x] benchmark performance impact

Release Notes:

- Added indent guides
([#5373](https://github.com/zed-industries/zed/issues/5373))

---------

Co-authored-by: Nate Butler <1714999+iamnbutler@users.noreply.github.com>
Co-authored-by: Remco <djsmits12@gmail.com>
This commit is contained in:
Bennet Bo Fenner 2024-05-23 15:50:59 +02:00 committed by GitHub
parent 3eb0418bda
commit feea607bac
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 1705 additions and 65 deletions

View file

@ -78,6 +78,8 @@ pub struct LanguageSettings {
pub show_wrap_guides: bool,
/// Character counts at which to show wrap guides in the editor.
pub wrap_guides: Vec<usize>,
/// Indent guide related settings.
pub indent_guides: IndentGuideSettings,
/// Whether or not to perform a buffer format before saving.
pub format_on_save: FormatOnSave,
/// Whether or not to remove any trailing whitespace from lines of a buffer
@ -242,6 +244,9 @@ pub struct LanguageSettingsContent {
/// Default: []
#[serde(default)]
pub wrap_guides: Option<Vec<usize>>,
/// Indent guide related settings.
#[serde(default)]
pub indent_guides: Option<IndentGuideSettings>,
/// Whether or not to perform a buffer format before saving.
///
/// Default: on
@ -411,6 +416,59 @@ pub enum Formatter {
CodeActions(HashMap<String, bool>),
}
/// The settings for indent guides.
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct IndentGuideSettings {
/// Whether to display indent guides in the editor.
///
/// Default: true
#[serde(default = "default_true")]
pub enabled: bool,
/// The width of the indent guides in pixels, between 1 and 10.
///
/// Default: 1
#[serde(default = "line_width")]
pub line_width: u32,
/// Determines how indent guides are colored.
///
/// Default: Fixed
#[serde(default)]
pub coloring: IndentGuideColoring,
/// Determines how indent guide backgrounds are colored.
///
/// Default: Disabled
#[serde(default)]
pub background_coloring: IndentGuideBackgroundColoring,
}
fn line_width() -> u32 {
1
}
/// Determines how indent guides are colored.
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum IndentGuideColoring {
/// Do not render any lines for indent guides.
Disabled,
/// Use the same color for all indentation levels.
#[default]
Fixed,
/// Use a different color for each indentation level.
IndentAware,
}
/// Determines how indent guide backgrounds are colored.
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum IndentGuideBackgroundColoring {
/// Do not render any background for indent guides.
#[default]
Disabled,
/// Use a different color for each indentation level.
IndentAware,
}
/// The settings for inlay hints.
#[derive(Copy, Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
pub struct InlayHintSettings {
@ -715,6 +773,7 @@ fn merge_settings(settings: &mut LanguageSettings, src: &LanguageSettingsContent
);
merge(&mut settings.show_wrap_guides, src.show_wrap_guides);
merge(&mut settings.wrap_guides, src.wrap_guides.clone());
merge(&mut settings.indent_guides, src.indent_guides);
merge(
&mut settings.code_actions_on_format,
src.code_actions_on_format.clone(),