};
pub fn extend_selection(root: SyntaxNodeRef, range: TextRange) -> Option<TextRange> {
+ let string_kinds = [COMMENT, STRING, RAW_STRING, BYTE_STRING, RAW_BYTE_STRING];
if range.is_empty() {
let offset = range.start();
let mut leaves = find_leaf_at_offset(root, offset);
let leaf_range = match leaves {
LeafAtOffset::None => return None,
LeafAtOffset::Single(l) => {
- if l.kind() == COMMENT {
- extend_single_word_in_comment(l, offset).unwrap_or_else(|| l.range())
+ if string_kinds.contains(&l.kind()) {
+ extend_single_word_in_comment_or_string(l, offset).unwrap_or_else(|| l.range())
} else {
l.range()
}
return Some(leaf_range);
};
let node = find_covering_node(root, range);
- if node.kind() == COMMENT && range == node.range() {
+ if string_kinds.contains(&node.kind()) && range == node.range() {
if let Some(range) = extend_comments(node) {
return Some(range);
}
}
}
-fn extend_single_word_in_comment(leaf: SyntaxNodeRef, offset: TextUnit) -> Option<TextRange> {
+fn extend_single_word_in_comment_or_string(
+ leaf: SyntaxNodeRef,
+ offset: TextUnit,
+) -> Option<TextRange> {
let text: &str = leaf.leaf_text()?;
let cursor_position: u32 = (offset - leaf.range().start()).into();
&["hello", "// hello world"],
);
}
+
+ #[test]
+ fn test_extend_selection_string() {
+ do_check(
+ r#"
+fn bar(){}
+
+" fn f<|>oo() {"
+ "#,
+ &["foo", "\" fn foo() {\""],
+ );
+ }
}
//! to support custom watcher events (related to https://github.com/rust-analyzer/rust-analyzer/issues/131)
//!
//! VFS is based on a concept of roots: a set of directories on the file system
-//! whihc are watched for changes. Typically, there will be a root for each
+//! which are watched for changes. Typically, there will be a root for each
//! Cargo package.
mod arena;
mod io;