Skip to content
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions book/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,3 +397,17 @@ S-tab = "move_parent_node_start"
tab = "extend_parent_node_end"
S-tab = "extend_parent_node_start"
```

### `[editor.vcs]` Section

Options for configuring VCSs (version control systems).

| Key | Description | Default |
| `providers` | VCSs to try (in the given order) for diff computations and the `version-control` element in the statusline | See note |

The only valid provider is `git` at the moment (if Helix is compiled with git support)

Note: the default providers change based on how Helix was compiled:

- If the `git` feature was used (the default): `["git"]`
- Else: `[]`
1 change: 1 addition & 0 deletions helix-vcs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ arc-swap = { version = "1.7.0" }
gix = { version = "0.58.0", features = ["attributes"], default-features = false, optional = true }
imara-diff = "0.1.5"
anyhow = "1"
serde = { version = "1.0", features = ["derive"] }

log = "0.4"

Expand Down
37 changes: 37 additions & 0 deletions helix-vcs/src/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//! Configuration for helix's VCS handling, to provide diffs and current VCS state.

use serde::{Deserialize, Serialize};

/// Main configuration struct, to be embedded in the larger editor configuration.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case", default)]
pub struct Vcs {
/// Providers for diff and state.
///
/// The default is either the empty vec or just git (if the relevant feature is active).
#[serde(default = "default_providers")]
pub providers: Vec<Provider>,
}

impl Default for Vcs {
fn default() -> Self {
Self {
providers: default_providers(),
}
}
}

/// Supported providers
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum Provider {
#[cfg(feature = "git")]
Git,
}

fn default_providers() -> Vec<Provider> {
vec![
#[cfg(feature = "git")]
Provider::Git,
]
}
2 changes: 1 addition & 1 deletion helix-vcs/src/git/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{fs::File, io::Write, path::Path, process::Command};

use tempfile::TempDir;

use crate::{DiffProvider, Git};
use crate::{git::Git, DiffProvider};

fn exec_git_cmd(args: &str, git_dir: &Path) {
let res = Command::new("git")
Expand Down
42 changes: 16 additions & 26 deletions helix-vcs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
use anyhow::{bail, Result};
use anyhow::Result;
use arc_swap::ArcSwap;
use std::{path::Path, sync::Arc};

#[cfg(feature = "git")]
pub use git::Git;
#[cfg(not(feature = "git"))]
pub use Dummy as Git;

#[cfg(feature = "git")]
mod git;

mod diff;

pub use diff::{DiffHandle, Hunk};

pub mod config;

pub trait DiffProvider {
/// Returns the data that a diff should be computed against
/// if this provider is used.
Expand All @@ -23,19 +19,8 @@ pub trait DiffProvider {
fn get_current_head_name(&self, file: &Path) -> Result<Arc<ArcSwap<Box<str>>>>;
}

#[doc(hidden)]
pub struct Dummy;
impl DiffProvider for Dummy {
fn get_diff_base(&self, _file: &Path) -> Result<Vec<u8>> {
bail!("helix was compiled without git support")
}

fn get_current_head_name(&self, _file: &Path) -> Result<Arc<ArcSwap<Box<str>>>> {
bail!("helix was compiled without git support")
}
}

pub struct DiffProviderRegistry {
/// Built from the list in the user configuration.
providers: Vec<Box<dyn DiffProvider>>,
}

Expand Down Expand Up @@ -67,12 +52,17 @@ impl DiffProviderRegistry {
}
}

impl Default for DiffProviderRegistry {
fn default() -> Self {
// currently only git is supported
// TODO make this configurable when more providers are added
let git: Box<dyn DiffProvider> = Box::new(Git);
let providers = vec![git];
DiffProviderRegistry { providers }
impl From<&config::Vcs> for DiffProviderRegistry {
fn from(value: &config::Vcs) -> Self {
fn mapper(p: &config::Provider) -> Box<dyn DiffProvider> {
match p {
#[cfg(feature = "git")]
config::Provider::Git => Box::new(git::Git),
}
}

Self {
providers: value.providers.iter().map(mapper).collect(),
}
}
}
6 changes: 5 additions & 1 deletion helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ pub struct Config {
/// Which indent heuristic to use when a new line is inserted
#[serde(default)]
pub indent_heuristic: IndentationHeuristic,
/// VCS configuration (notably which to activate, in which order)
#[serde(default)]
pub vcs: helix_vcs::config::Vcs,
}

#[derive(Debug, Clone, PartialEq, Deserialize, Serialize, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -867,6 +870,7 @@ impl Default for Config {
smart_tab: Some(SmartTabConfig::default()),
popup_border: PopupBorderConfig::None,
indent_heuristic: IndentationHeuristic::default(),
vcs: Default::default(),
}
}
}
Expand Down Expand Up @@ -1060,7 +1064,7 @@ impl Editor {
theme: theme_loader.default(),
language_servers,
diagnostics: BTreeMap::new(),
diff_providers: DiffProviderRegistry::default(),
diff_providers: DiffProviderRegistry::from(&conf.vcs),
debugger: None,
debugger_events: SelectAll::new(),
breakpoints: HashMap::new(),
Expand Down