Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gutter character configuration. #5371

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ layout = ["diff", "diagnostics", "line-numbers", "spacer"]

#### `[editor.gutters.line-numbers]` Section

Options for the line number gutter
Options for the line number gutter.

| Key | Description | Default |
| --- | --- | --- |
Expand All @@ -297,13 +297,36 @@ Example:
min-width = 1
```

#### `[editor.gutters.diagnotics]` Section
#### `[editor.gutters.diagnostics]` Section

Currently unused
Options for the diagnostics gutter.

| Key | Description | Default |
| --- | --- | --- |
| `characters` | Characters to be used in the gutter column | `"●"` |

#### `[editor.gutters.breakpoints]` Section

Options for the breakpoints gutter.

| Key | Description | Default |
| --- | --- | --- |
| `characters.verified` | Characters to be used in the gutter column for verified breakpoints | `"▲"` |
| `characters.other` | Characters to be used in the gutter column for other breakpoints | `"⊚"` |

Alternatively, you can use the `[editor.gutters.breakpoints.characters]` section
and use the `verified` and `other` keys.

#### `[editor.gutters.diff]` Section

Currently unused
| Key | Description | Default |
| --- | --- | --- |
| `characters.add` | Characters to be used in the gutter column for code additions | `"▍"` |
| `characters.remove` | Characters to be used in the gutter column for code deletions | `"▔"` |
| `characters.change` | Characters to be used in the gutter column for code changes | `"▍"` |

Alternatively, you can use the `[editor.gutters.diff.characters]` section
and use the `add`, `remove` and `change` keys.

#### `[editor.gutters.spacer]` Section

Expand Down
69 changes: 69 additions & 0 deletions helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ pub struct GutterConfig {
pub layout: Vec<GutterType>,
/// Options specific to the "line-numbers" gutter
pub line_numbers: GutterLineNumbersConfig,
/// Options specific to the "diagnostics" gutter.
pub diagnostics: DiagnosticsGutterConfig,
/// Options specific to the “breakpoints” gutter.
pub breakpoints: BreakpointsGutterConfig,
/// Options specific to the “diff” gutter.
pub diff: DiffGutterConfig,
}

impl Default for GutterConfig {
Expand All @@ -91,6 +97,9 @@ impl Default for GutterConfig {
GutterType::Diff,
],
line_numbers: GutterLineNumbersConfig::default(),
diagnostics: DiagnosticsGutterConfig::default(),
breakpoints: BreakpointsGutterConfig::default(),
diff: DiffGutterConfig::default(),
}
}
}
Expand Down Expand Up @@ -569,6 +578,66 @@ impl std::str::FromStr for GutterType {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct DiagnosticsGutterConfig {
pub characters: String,
}

impl Default for DiagnosticsGutterConfig {
fn default() -> Self {
Self {
characters: "●".to_owned(),
}
}
}

#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct BreakpointsGutterConfig {
pub characters: BreakpointsGutterCharacters,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct BreakpointsGutterCharacters {
pub verified: String,
pub other: String,
}

impl Default for BreakpointsGutterCharacters {
fn default() -> Self {
Self {
verified: "▲".to_owned(),
other: "⊚".to_owned(),
}
}
}

#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct DiffGutterConfig {
pub characters: DiffGutterCharacters,
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct DiffGutterCharacters {
pub add: String,
pub remove: String,
pub change: String,
}

impl Default for DiffGutterCharacters {
fn default() -> Self {
Self {
add: "▍".to_owned(),
remove: "▔".to_owned(),
change: "▍".to_owned(),
}
}
}

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(default)]
pub struct WhitespaceConfig {
Expand Down
23 changes: 16 additions & 7 deletions helix-view/src/gutter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl GutterType {
}

pub fn diagnostic<'doc>(
_editor: &'doc Editor,
editor: &'doc Editor,
doc: &'doc Document,
_view: &View,
theme: &Theme,
Expand All @@ -73,7 +73,8 @@ pub fn diagnostic<'doc>(
// This unwrap is safe because the iterator cannot be empty as it contains at least the item found by the binary search.
let diagnostic = diagnostics_on_line.max_by_key(|d| d.severity).unwrap();

write!(out, "●").unwrap();
out.write_str(&editor.config().gutters.diagnostics.characters)
.unwrap();
return Some(match diagnostic.severity {
Some(Severity::Error) => error,
Some(Severity::Warning) | None => warning,
Expand All @@ -86,7 +87,7 @@ pub fn diagnostic<'doc>(
}

pub fn diff<'doc>(
_editor: &'doc Editor,
editor: &'doc Editor,
doc: &'doc Document,
_view: &View,
theme: &Theme,
Expand Down Expand Up @@ -116,12 +117,13 @@ pub fn diff<'doc>(
return None;
}

let chars = &editor.config().gutters.diff.characters;
let (icon, style) = if hunk.is_pure_insertion() {
("▍", added)
(&chars.add, added)
} else if hunk.is_pure_removal() {
("▔", deleted)
(&chars.remove, deleted)
} else {
("▍", modified)
(&chars.change, modified)
};

write!(out, "{}", icon).unwrap();
Expand Down Expand Up @@ -268,7 +270,12 @@ pub fn breakpoints<'doc>(
}
};

let sym = if breakpoint.verified { "▲" } else { "⊚" };
let chars = &editor.config().gutters.breakpoints.characters;
let sym = if breakpoint.verified {
&chars.verified
} else {
&chars.other
};
write!(out, "{}", sym).unwrap();
Some(style)
})
Expand Down Expand Up @@ -333,6 +340,7 @@ mod tests {
let gutters = GutterConfig {
layout: vec![GutterType::Diagnostics, GutterType::LineNumbers],
line_numbers: GutterLineNumbersConfig { min_width: 10 },
..GutterConfig::default()
};

let mut view = View::new(DocumentId::default(), gutters);
Expand All @@ -351,6 +359,7 @@ mod tests {
let gutters = GutterConfig {
layout: vec![GutterType::Diagnostics, GutterType::LineNumbers],
line_numbers: GutterLineNumbersConfig { min_width: 1 },
..GutterConfig::default()
};

let mut view = View::new(DocumentId::default(), gutters);
Expand Down
2 changes: 2 additions & 0 deletions helix-view/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ mod tests {
GutterConfig {
layout: vec![GutterType::Diagnostics],
line_numbers: GutterLineNumbersConfig::default(),
..GutterConfig::default()
},
);
view.area = Rect::new(40, 40, 40, 40);
Expand All @@ -507,6 +508,7 @@ mod tests {
GutterConfig {
layout: vec![],
line_numbers: GutterLineNumbersConfig::default(),
..GutterConfig::default()
},
);
view.area = Rect::new(40, 40, 40, 40);
Expand Down