mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 21:35:20 +00:00
Add completions for patterns
This commit is contained in:
parent
f3125555a8
commit
b184bfad7a
6 changed files with 315 additions and 26 deletions
|
@ -51,7 +51,7 @@ pub(crate) struct CompletionContext<'a> {
|
|||
/// If a name-binding or reference to a const in a pattern.
|
||||
/// Irrefutable patterns (like let) are excluded.
|
||||
pub(super) is_pat_binding_or_const: bool,
|
||||
pub(super) is_irrefutable_let_pat_binding: bool,
|
||||
pub(super) is_irrefutable_pat_binding: bool,
|
||||
/// A single-indent path, like `foo`. `::foo` should not be considered a trivial path.
|
||||
pub(super) is_trivial_path: bool,
|
||||
/// If not a trivial path, the prefix (qualifier).
|
||||
|
@ -147,7 +147,7 @@ impl<'a> CompletionContext<'a> {
|
|||
active_parameter: ActiveParameter::at(db, position),
|
||||
is_param: false,
|
||||
is_pat_binding_or_const: false,
|
||||
is_irrefutable_let_pat_binding: false,
|
||||
is_irrefutable_pat_binding: false,
|
||||
is_trivial_path: false,
|
||||
path_qual: None,
|
||||
after_if: false,
|
||||
|
@ -327,14 +327,19 @@ impl<'a> CompletionContext<'a> {
|
|||
if bind_pat.syntax().parent().and_then(ast::RecordPatFieldList::cast).is_some() {
|
||||
self.is_pat_binding_or_const = false;
|
||||
}
|
||||
if let Some(let_stmt) = bind_pat.syntax().ancestors().find_map(ast::LetStmt::cast) {
|
||||
if let Some(pat) = let_stmt.pat() {
|
||||
if pat.syntax().text_range().contains_range(bind_pat.syntax().text_range())
|
||||
{
|
||||
self.is_pat_binding_or_const = false;
|
||||
self.is_irrefutable_let_pat_binding = true;
|
||||
if let Some(Some(pat)) = bind_pat.syntax().ancestors().find_map(|node| {
|
||||
match_ast! {
|
||||
match node {
|
||||
ast::LetStmt(it) => Some(it.pat()),
|
||||
ast::Param(it) => Some(it.pat()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}) {
|
||||
if pat.syntax().text_range().contains_range(bind_pat.syntax().text_range()) {
|
||||
self.is_pat_binding_or_const = false;
|
||||
self.is_irrefutable_pat_binding = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if is_node::<ast::Param>(name.syntax()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue