mirror of
https://github.com/astral-sh/ruff
synced 2026-01-21 21:40:51 -05:00
[ty] Fix completion in decorator without class or function definition
This commit is contained in:
@@ -2914,21 +2914,27 @@ impl<'src> Parser<'src> {
|
||||
self.current_token_range(),
|
||||
);
|
||||
|
||||
// TODO(dhruvmanila): It seems that this recovery drops all the parsed
|
||||
// decorators. Maybe we could convert them into statement expression
|
||||
// with a flag indicating that this expression is part of a decorator.
|
||||
// It's only possible to keep them if it's a function or class definition.
|
||||
// We could possibly keep them if there's indentation error:
|
||||
//
|
||||
// ```python
|
||||
// @decorator
|
||||
// @decorator
|
||||
// def foo(): ...
|
||||
// ```
|
||||
//
|
||||
// Or, parse it as a binary expression where the left side is missing.
|
||||
// We would need to convert each decorator into a binary expression.
|
||||
self.parse_statement()
|
||||
let range = self.node_range(start);
|
||||
|
||||
ast::StmtFunctionDef {
|
||||
node_index: Default::default(),
|
||||
range,
|
||||
is_async: false,
|
||||
decorator_list: decorators,
|
||||
name: ast::Identifier {
|
||||
id: Name::empty(),
|
||||
range: self.missing_node_range(),
|
||||
node_index: AtomicNodeIndex::NONE,
|
||||
},
|
||||
type_params: None,
|
||||
parameters: Box::new(ast::Parameters {
|
||||
range: self.missing_node_range(),
|
||||
..ast::Parameters::default()
|
||||
}),
|
||||
returns: None,
|
||||
body: vec![],
|
||||
}
|
||||
.into()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user