Skip to content

Commit

Permalink
cli: complete: complete revset alias symbols for revisions
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobhellermann committed Feb 1, 2025
1 parent f7429f2 commit cfe5915
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
14 changes: 14 additions & 0 deletions cli/src/complete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use crate::config::default_config_layers;
use crate::config::ConfigArgKind;
use crate::config::ConfigEnv;
use crate::config::CONFIG_SCHEMA;
use crate::revset_util::load_revset_aliases;
use crate::ui::Ui;

const BOOKMARK_HELP_TEMPLATE: &str = r#"template-aliases.'bookmark_help()'='''
Expand Down Expand Up @@ -238,6 +239,7 @@ fn revisions(revisions: Option<&str>) -> Vec<CompletionCandidate> {
const CHANGE_ID: usize = 3;
const REMOTE_BOOKMARK_MINE: usize = 4;
const REMOTE_BOOKMARK: usize = 5;
const REVSET_ALIAS: usize = 6;

let mut candidates = Vec::new();

Expand Down Expand Up @@ -334,6 +336,18 @@ fn revisions(revisions: Option<&str>) -> Vec<CompletionCandidate> {
.display_order(Some(CHANGE_ID))
}));

// revset aliases

let revset_aliases = load_revset_aliases(&Ui::null(), settings.config())?;
let mut symbol_names: Vec<_> = revset_aliases.symbol_names().collect();
symbol_names.sort();
candidates.extend(symbol_names.into_iter().map(|symbol| {
let (_, defn) = revset_aliases.get_symbol(symbol).unwrap();
CompletionCandidate::new(symbol)
.help(Some(defn.into()))
.display_order(Some(REVSET_ALIAS))
}));

Ok(candidates)
})
}
Expand Down
14 changes: 14 additions & 0 deletions cli/tests/test_completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,14 @@ fn test_revisions() {
test_env.jj_cmd_ok(&repo_path, &["b", "c", "immutable_bookmark"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "immutable"]);
test_env.add_config(r#"revset-aliases."immutable_heads()" = "immutable_bookmark""#);
test_env.add_config(r#"revset-aliases."siblings" = "@-+ ~@""#);
test_env.add_config(
r#"revset-aliases."alias_with_newline" = '''
roots(
conflicts()
)
'''"#,
);

test_env.jj_cmd_ok(&repo_path, &["b", "c", "mutable_bookmark"]);
test_env.jj_cmd_ok(&repo_path, &["commit", "-m", "mutable"]);
Expand All @@ -406,6 +414,8 @@ fn test_revisions() {
zq remote_commit
zz (no description set)
remote_bookmark@origin remote_commit
alias_with_newline roots(
siblings @-+ ~@
");

// complete only mutable revisions
Expand All @@ -415,6 +425,8 @@ fn test_revisions() {
k working_copy
y mutable
zq remote_commit
alias_with_newline roots(
siblings @-+ ~@
");

// complete args of the default command
Expand All @@ -429,6 +441,8 @@ fn test_revisions() {
zq remote_commit
zz (no description set)
remote_bookmark@origin remote_commit
alias_with_newline roots(
siblings @-+ ~@
");
}

Expand Down

0 comments on commit cfe5915

Please sign in to comment.