mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
tweak extend selection
This commit is contained in:
parent
8fc7f438c4
commit
05a9d42f54
3 changed files with 54 additions and 16 deletions
|
@ -61,6 +61,18 @@ impl<'a> SyntaxText<'a> {
|
|||
});
|
||||
SyntaxText { node: self.node, range }
|
||||
}
|
||||
pub fn char_at(&self, offset: TextUnit) -> Option<char> {
|
||||
let mut start: TextUnit = 0.into();
|
||||
for chunk in self.chunks() {
|
||||
let end = start + TextUnit::of_str(chunk);
|
||||
if start <= offset && offset < end {
|
||||
let off: usize = u32::from(offset - start) as usize;
|
||||
return Some(chunk[off..].chars().next().unwrap());
|
||||
}
|
||||
start = end;
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> fmt::Debug for SyntaxText<'a> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue