convenience api

This commit is contained in:
Aleksey Kladov 2019-07-19 19:05:34 +03:00
parent a6df224f7d
commit 191a6ba330
8 changed files with 63 additions and 50 deletions

View file

@ -156,7 +156,7 @@ fn extend_list_item(node: &SyntaxNode) -> Option<TextRange> {
SyntaxElement::Token(it) => is_single_line_ws(it),
})
.next()
.and_then(|it| it.as_token().cloned())
.and_then(|it| it.into_token())
.filter(|node| node.kind() == T![,])
}
@ -167,7 +167,7 @@ fn extend_list_item(node: &SyntaxNode) -> Option<TextRange> {
// Include any following whitespace when comma if after list item.
let final_node = comma_node
.next_sibling_or_token()
.and_then(|it| it.as_token().cloned())
.and_then(|it| it.into_token())
.filter(|node| is_single_line_ws(node))
.unwrap_or(comma_node);

View file

@ -27,7 +27,7 @@ pub fn join_lines(file: &SourceFile, range: TextRange) -> TextEdit {
SyntaxElement::Token(token) => token.parent(),
};
let mut edit = TextEditBuilder::default();
for token in node.descendants_with_tokens().filter_map(|it| it.as_token().cloned()) {
for token in node.descendants_with_tokens().filter_map(|it| it.into_token()) {
let range = match range.intersection(&token.range()) {
Some(range) => range,
None => continue,

View file

@ -237,8 +237,7 @@ pub(crate) fn highlight_as_html(db: &RootDatabase, file_id: FileId, rainbow: boo
let mut buf = String::new();
buf.push_str(&STYLE);
buf.push_str("<pre><code>");
let tokens =
parse.tree().syntax().descendants_with_tokens().filter_map(|it| it.as_token().cloned());
let tokens = parse.tree().syntax().descendants_with_tokens().filter_map(|it| it.into_token());
for token in tokens {
could_intersect.retain(|it| token.range().start() <= it.range.end());
while let Some(r) = ranges.get(frontier) {