Remove the fixme

This commit is contained in:
Kirill Bulatov 2020-11-12 13:52:24 +02:00
parent 3481ea96bd
commit 07e633ef0a

View file

@ -63,47 +63,26 @@ impl ImportScope {
} }
} }
fn insert_pos_after_inner_elements(&self) -> (InsertPosition<SyntaxElement>, AddBlankLine) { fn insert_pos_after_last_inner_element(&self) -> (InsertPosition<SyntaxElement>, AddBlankLine) {
let mut last_inner_element = None; self.as_syntax_node()
.children_with_tokens()
for maybe_inner_element in self.as_syntax_node().children_with_tokens() { .filter(|child| match child {
match maybe_inner_element { NodeOrToken::Node(node) => is_inner_attribute(node.clone()),
NodeOrToken::Node(maybe_inner_node) => { NodeOrToken::Token(token) => is_inner_comment(token.clone()),
if is_inner_node(maybe_inner_node.clone()) { })
last_inner_element = Some(NodeOrToken::Node(maybe_inner_node)) .last()
} else { .map(|last_inner_element| {
// FIXME: https://doc.rust-lang.org/reference/comments.html#doc-comments (InsertPosition::After(last_inner_element.into()), AddBlankLine::BeforeTwice)
// states that inner comments (`//!` and `/*!`) are equal to inner attribute `#![doc="..."]` })
// yet RA treats them differently now: inner attributes never belong to child nodes, .unwrap_or_else(|| self.first_insert_pos())
// but inner comments can, ergo this check.
// We need to align this and treat both cases the same way.
if let Some(maybe_inner_token) = maybe_inner_node.first_token() {
if is_inner_token(maybe_inner_token.clone()) {
last_inner_element = Some(NodeOrToken::Token(maybe_inner_token))
}
}
};
}
NodeOrToken::Token(maybe_inner_token) => {
if is_inner_token(maybe_inner_token.clone()) {
last_inner_element = Some(NodeOrToken::Token(maybe_inner_token))
}
}
}
}
match last_inner_element {
Some(element) => (InsertPosition::After(element.into()), AddBlankLine::BeforeTwice),
None => self.first_insert_pos(),
}
} }
} }
fn is_inner_node(node: SyntaxNode) -> bool { fn is_inner_attribute(node: SyntaxNode) -> bool {
ast::Attr::cast(node).map(|attr| attr.kind()) == Some(ast::AttrKind::Inner) ast::Attr::cast(node).map(|attr| attr.kind()) == Some(ast::AttrKind::Inner)
} }
fn is_inner_token(token: SyntaxToken) -> bool { fn is_inner_comment(token: SyntaxToken) -> bool {
ast::Comment::cast(token).and_then(|comment| comment.kind().doc) ast::Comment::cast(token).and_then(|comment| comment.kind().doc)
== Some(ast::CommentPlacement::Inner) == Some(ast::CommentPlacement::Inner)
} }
@ -582,7 +561,7 @@ fn find_insert_position(
(InsertPosition::After(node.into()), AddBlankLine::BeforeTwice) (InsertPosition::After(node.into()), AddBlankLine::BeforeTwice)
} }
// there are no imports in this file at all // there are no imports in this file at all
None => scope.insert_pos_after_inner_elements(), None => scope.insert_pos_after_last_inner_element(),
}, },
} }
} }