mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 13:33:31 +00:00
Add gen
modifier to functions
We don't yet lower or maybe even parse them, but blocks already have `gen`, so why not.
This commit is contained in:
parent
506b9663bf
commit
cc07652be5
9 changed files with 38 additions and 4 deletions
|
@ -1617,6 +1617,7 @@ fn format_function(
|
||||||
fun.control_flow.is_async,
|
fun.control_flow.is_async,
|
||||||
fun.mods.is_const,
|
fun.mods.is_const,
|
||||||
fun.control_flow.is_unsafe,
|
fun.control_flow.is_unsafe,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -122,6 +122,7 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
|
||||||
let is_async = method_source.async_token().is_some();
|
let is_async = method_source.async_token().is_some();
|
||||||
let is_const = method_source.const_token().is_some();
|
let is_const = method_source.const_token().is_some();
|
||||||
let is_unsafe = method_source.unsafe_token().is_some();
|
let is_unsafe = method_source.unsafe_token().is_some();
|
||||||
|
let is_gen = method_source.gen_token().is_some();
|
||||||
|
|
||||||
let fn_name = make::name(&name);
|
let fn_name = make::name(&name);
|
||||||
|
|
||||||
|
@ -154,6 +155,7 @@ pub(crate) fn generate_delegate_methods(acc: &mut Assists, ctx: &AssistContext<'
|
||||||
is_async,
|
is_async,
|
||||||
is_const,
|
is_const,
|
||||||
is_unsafe,
|
is_unsafe,
|
||||||
|
is_gen,
|
||||||
)
|
)
|
||||||
.clone_for_update();
|
.clone_for_update();
|
||||||
|
|
||||||
|
|
|
@ -740,6 +740,7 @@ fn func_assoc_item(
|
||||||
item.async_token().is_some(),
|
item.async_token().is_some(),
|
||||||
item.const_token().is_some(),
|
item.const_token().is_some(),
|
||||||
item.unsafe_token().is_some(),
|
item.unsafe_token().is_some(),
|
||||||
|
item.gen_token().is_some(),
|
||||||
)
|
)
|
||||||
.clone_for_update();
|
.clone_for_update();
|
||||||
|
|
||||||
|
|
|
@ -365,6 +365,7 @@ impl FunctionBuilder {
|
||||||
self.is_async,
|
self.is_async,
|
||||||
false, // FIXME : const and unsafe are not handled yet.
|
false, // FIXME : const and unsafe are not handled yet.
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.clone_for_update();
|
.clone_for_update();
|
||||||
|
|
||||||
|
|
|
@ -261,7 +261,19 @@ fn generate_getter_from_info(
|
||||||
let ret_type = Some(make::ret_type(ty));
|
let ret_type = Some(make::ret_type(ty));
|
||||||
let body = make::block_expr([], Some(body));
|
let body = make::block_expr([], Some(body));
|
||||||
|
|
||||||
make::fn_(strukt.visibility(), fn_name, None, None, params, body, ret_type, false, false, false)
|
make::fn_(
|
||||||
|
strukt.visibility(),
|
||||||
|
fn_name,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
params,
|
||||||
|
body,
|
||||||
|
ret_type,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn generate_setter_from_info(info: &AssistInfo, record_field_info: &RecordFieldInfo) -> ast::Fn {
|
fn generate_setter_from_info(info: &AssistInfo, record_field_info: &RecordFieldInfo) -> ast::Fn {
|
||||||
|
@ -285,7 +297,19 @@ fn generate_setter_from_info(info: &AssistInfo, record_field_info: &RecordFieldI
|
||||||
let body = make::block_expr([assign_stmt.into()], None);
|
let body = make::block_expr([assign_stmt.into()], None);
|
||||||
|
|
||||||
// Make the setter fn
|
// Make the setter fn
|
||||||
make::fn_(strukt.visibility(), fn_name, None, None, params, body, None, false, false, false)
|
make::fn_(
|
||||||
|
strukt.visibility(),
|
||||||
|
fn_name,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
params,
|
||||||
|
body,
|
||||||
|
None,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extract_and_parse(
|
fn extract_and_parse(
|
||||||
|
|
|
@ -115,6 +115,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
false,
|
||||||
)
|
)
|
||||||
.clone_for_update();
|
.clone_for_update();
|
||||||
fn_.indent(1.into());
|
fn_.indent(1.into());
|
||||||
|
|
|
@ -186,7 +186,7 @@ UseTreeList =
|
||||||
|
|
||||||
Fn =
|
Fn =
|
||||||
Attr* Visibility?
|
Attr* Visibility?
|
||||||
'default'? 'const'? 'async'? 'unsafe'? Abi?
|
'default'? 'const'? 'async'? 'gen'? 'unsafe'? Abi?
|
||||||
'fn' Name GenericParamList? ParamList RetType? WhereClause?
|
'fn' Name GenericParamList? ParamList RetType? WhereClause?
|
||||||
(body:BlockExpr | ';')
|
(body:BlockExpr | ';')
|
||||||
|
|
||||||
|
|
|
@ -484,6 +484,8 @@ impl Fn {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn fn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![fn]) }
|
pub fn fn_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![fn]) }
|
||||||
#[inline]
|
#[inline]
|
||||||
|
pub fn gen_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![gen]) }
|
||||||
|
#[inline]
|
||||||
pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
|
pub fn unsafe_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![unsafe]) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1035,6 +1035,7 @@ pub fn fn_(
|
||||||
is_async: bool,
|
is_async: bool,
|
||||||
is_const: bool,
|
is_const: bool,
|
||||||
is_unsafe: bool,
|
is_unsafe: bool,
|
||||||
|
is_gen: bool,
|
||||||
) -> ast::Fn {
|
) -> ast::Fn {
|
||||||
let type_params = match type_params {
|
let type_params = match type_params {
|
||||||
Some(type_params) => format!("{type_params}"),
|
Some(type_params) => format!("{type_params}"),
|
||||||
|
@ -1056,9 +1057,10 @@ pub fn fn_(
|
||||||
let async_literal = if is_async { "async " } else { "" };
|
let async_literal = if is_async { "async " } else { "" };
|
||||||
let const_literal = if is_const { "const " } else { "" };
|
let const_literal = if is_const { "const " } else { "" };
|
||||||
let unsafe_literal = if is_unsafe { "unsafe " } else { "" };
|
let unsafe_literal = if is_unsafe { "unsafe " } else { "" };
|
||||||
|
let gen_literal = if is_gen { "gen " } else { "" };
|
||||||
|
|
||||||
ast_from_text(&format!(
|
ast_from_text(&format!(
|
||||||
"{visibility}{async_literal}{const_literal}{unsafe_literal}fn {fn_name}{type_params}{params} {ret_type}{where_clause}{body}",
|
"{visibility}{const_literal}{async_literal}{gen_literal}{unsafe_literal}fn {fn_name}{type_params}{params} {ret_type}{where_clause}{body}",
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
pub fn struct_(
|
pub fn struct_(
|
||||||
|
|
Loading…
Reference in a new issue