Skip to content

Commit

Permalink
on stable, this action only exists as string.
Browse files Browse the repository at this point in the history
  • Loading branch information
smitbarmase committed Mar 4, 2025
1 parent 64b2ddc commit efe4418
Showing 1 changed file with 1 addition and 79 deletions.
80 changes: 1 addition & 79 deletions crates/migrator/src/migrator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ const KEYMAP_MIGRATION_TRANSFORMATION_PATTERNS: MigrationPatterns = &[
),
(ACTION_STRING_PATTERN, rename_string_action),
(CONTEXT_PREDICATE_PATTERN, rename_context_key),
(
ACTION_STRING_OF_ARRAY_PATTERN,
replace_first_string_of_array,
),
];

static KEYMAP_MIGRATION_TRANSFORMATION_QUERY: LazyLock<Query> = LazyLock::new(|| {
Expand Down Expand Up @@ -269,51 +265,6 @@ static TRANSFORM_ARRAY: LazyLock<HashMap<(&str, &str), &str>> = LazyLock::new(||
])
});

const ACTION_STRING_OF_ARRAY_PATTERN: &str = r#"(document
(array
(object
(pair
key: (string (string_content) @name)
value: (
(object
(pair
key: (string)
value: ((array
. (string (string_content) @action_name)
)
)
)
)
)
)
)
)
(#eq? @name "bindings")
)"#;

// ["editor::GoToPrevHunk", { "center_cursor": true }] -> ["editor::GoToPreviousHunk", { "center_cursor": true }]
fn replace_first_string_of_array(
contents: &str,
mat: &QueryMatch,
query: &Query,
) -> Option<(Range<usize>, String)> {
let action_name_ix = query.capture_index_for_name("action_name")?;
let action_name = contents.get(
mat.nodes_for_capture_index(action_name_ix)
.next()?
.byte_range(),
)?;
let replacement = STRING_OF_ARRAY_REPLACE.get(action_name)?;
let range_to_replace = mat
.nodes_for_capture_index(action_name_ix)
.next()?
.byte_range();
Some((range_to_replace, replacement.to_string()))
}

static STRING_OF_ARRAY_REPLACE: LazyLock<HashMap<&str, &str>> =
LazyLock::new(|| HashMap::from_iter([("editor::GoToPrevHunk", "editor::GoToPreviousHunk")]));

const ACTION_ARGUMENT_OBJECT_PATTERN: &str = r#"(document
(array
(object
Expand Down Expand Up @@ -485,6 +436,7 @@ static STRING_REPLACE: LazyLock<HashMap<&str, &str>> = LazyLock::new(|| {
("pane::ActivatePrevItem", "pane::ActivatePreviousItem"),
("vim::MoveToPrev", "vim::MoveToPrevious"),
("vim::MoveToPrevMatch", "vim::MoveToPreviousMatch"),
("editor::GoToPrevHunk", "editor::GoToPreviousHunk"),
])
});

Expand Down Expand Up @@ -926,36 +878,6 @@ mod tests {
)
}

#[test]
fn test_string_of_array_replace() {
assert_migrate_keymap(
r#"
[
{
"bindings": {
"ctrl-p": ["editor::GoToPrevHunk", { "center_cursor": true }],
"ctrl-q": ["editor::GoToPrevHunk"],
"ctrl-q": "editor::GoToPrevHunk", // should remain same
}
}
]
"#,
Some(
r#"
[
{
"bindings": {
"ctrl-p": ["editor::GoToPreviousHunk", { "center_cursor": true }],
"ctrl-q": ["editor::GoToPreviousHunk"],
"ctrl-q": "editor::GoToPrevHunk", // should remain same
}
}
]
"#,
),
)
}

#[test]
fn test_action_argument_snake_case() {
// First performs transformations, then replacements
Expand Down

0 comments on commit efe4418

Please sign in to comment.