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

vim: Add vif/vaf (for Rust) #19967

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion assets/keymaps/vim.json
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@
"shift-b": "vim::CurlyBrackets",
"<": "vim::AngleBrackets",
">": "vim::AngleBrackets",
"a": "vim::Argument"
"a": "vim::Argument",
"f": "vim::OutlineObject"
}
},
{
Expand Down
3 changes: 2 additions & 1 deletion crates/languages/src/rust/outline.scm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
(visibility_modifier)? @context
(function_modifiers)? @context
"fn" @context
name: (_) @name) @item
name: (_) @name
body: (_ "{" @open (_)* "}" @close)) @item

(function_signature_item
(visibility_modifier)? @context
Expand Down
45 changes: 40 additions & 5 deletions crates/vim/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::{motion::right, state::Mode, Vim};
use editor::{
display_map::{DisplaySnapshot, ToDisplayPoint},
movement::{self, FindRange},
Bias, DisplayPoint, Editor,
Bias, DisplayPoint, Editor, ToOffset,
};

use itertools::Itertools;
Expand All @@ -29,6 +29,7 @@ pub enum Object {
AngleBrackets,
Argument,
Tag,
OutlineObject,
}

#[derive(Clone, Deserialize, PartialEq)]
Expand All @@ -54,7 +55,8 @@ actions!(
CurlyBrackets,
AngleBrackets,
Argument,
Tag
Tag,
OutlineObject
]
);

Expand Down Expand Up @@ -100,6 +102,9 @@ pub fn register(editor: &mut Editor, cx: &mut ViewContext<Vim>) {
Vim::action(editor, cx, |vim, _: &Argument, cx| {
vim.object(Object::Argument, cx)
});
Vim::action(editor, cx, |vim, _: &OutlineObject, cx| {
vim.object(Object::OutlineObject, cx)
});
}

impl Vim {
Expand Down Expand Up @@ -129,7 +134,8 @@ impl Object {
| Object::AngleBrackets
| Object::CurlyBrackets
| Object::SquareBrackets
| Object::Argument => true,
| Object::Argument
| Object::OutlineObject => true,
}
}

Expand All @@ -144,7 +150,8 @@ impl Object {
| Object::SquareBrackets
| Object::Tag
| Object::CurlyBrackets
| Object::AngleBrackets => true,
| Object::AngleBrackets
| Object::OutlineObject => true,
}
}

Expand All @@ -167,7 +174,8 @@ impl Object {
| Object::AngleBrackets
| Object::VerticalBars
| Object::Tag
| Object::Argument => Mode::Visual,
| Object::Argument
| Object::OutlineObject => Mode::Visual,
Object::Paragraph => Mode::VisualLine,
}
}
Expand Down Expand Up @@ -215,6 +223,7 @@ impl Object {
surrounding_markers(map, relative_to, around, self.is_multiline(), '<', '>')
}
Object::Argument => argument(map, relative_to, around),
Object::OutlineObject => outline_object(map, selection.start, selection.end, around),
}
}

Expand Down Expand Up @@ -564,6 +573,32 @@ fn argument(
}
}

fn outline_object(
map: &DisplaySnapshot,
start: DisplayPoint,
end: DisplayPoint,
around: bool,
) -> Option<Range<DisplayPoint>> {
println!("outline object!!!!");
let start_offset = start.to_offset(&map, Bias::Left);
let end_offset = end.to_offset(&map, Bias::Left);
let (_buffer_id, symbols) = map.buffer_snapshot.symbols_containing(start_offset, None)?;
for symbol in symbols.iter().rev() {
let range = if around {
&symbol.range
} else {
dbg!(symbol.body_range.as_ref()).unwrap_or(&symbol.range)
};
let start = range.start.to_offset(&map.buffer_snapshot);
let end = range.end.to_offset(&map.buffer_snapshot);
if start < start_offset && end > end_offset {
return Some(start.to_display_point(&map)..end.to_display_point(&map));
}
}
dbg!("none");
return None;
}

fn sentence(
map: &DisplaySnapshot,
relative_to: DisplayPoint,
Expand Down
Loading