mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
default method name to type name
This commit is contained in:
parent
05a9d42f54
commit
78d60a549d
4 changed files with 51 additions and 84 deletions
|
@ -78,8 +78,7 @@ impl<'a> AstNode<'a> for Attr<'a> {
|
|||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> Attr<'a> {
|
||||
pub fn value(self) -> Option<TokenTree<'a>> {
|
||||
impl<'a> Attr<'a> {pub fn value(self) -> Option<TokenTree<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
@ -141,8 +140,7 @@ impl<'a> Block<'a> {
|
|||
pub fn statements(self) -> impl Iterator<Item = Stmt<'a>> + 'a {
|
||||
super::children(self)
|
||||
}
|
||||
|
||||
pub fn expr(self) -> Option<Expr<'a>> {
|
||||
pub fn expr(self) -> Option<Expr<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
@ -163,8 +161,7 @@ impl<'a> AstNode<'a> for BlockExpr<'a> {
|
|||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> BlockExpr<'a> {
|
||||
pub fn block(self) -> Option<Block<'a>> {
|
||||
impl<'a> BlockExpr<'a> {pub fn block(self) -> Option<Block<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
@ -203,12 +200,10 @@ impl<'a> AstNode<'a> for CallExpr<'a> {
|
|||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> CallExpr<'a> {
|
||||
pub fn expr(self) -> Option<Expr<'a>> {
|
||||
impl<'a> CallExpr<'a> {pub fn expr(self) -> Option<Expr<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
|
||||
pub fn arg_list(self) -> Option<ArgList<'a>> {
|
||||
pub fn arg_list(self) -> Option<ArgList<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
@ -247,12 +242,10 @@ impl<'a> AstNode<'a> for Condition<'a> {
|
|||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> Condition<'a> {
|
||||
pub fn pat(self) -> Option<Pat<'a>> {
|
||||
impl<'a> Condition<'a> {pub fn pat(self) -> Option<Pat<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
|
||||
pub fn expr(self) -> Option<Expr<'a>> {
|
||||
pub fn expr(self) -> Option<Expr<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
@ -466,8 +459,7 @@ impl<'a> AstNode<'a> for ExprStmt<'a> {
|
|||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> ExprStmt<'a> {
|
||||
pub fn expr(self) -> Option<Expr<'a>> {
|
||||
impl<'a> ExprStmt<'a> {pub fn expr(self) -> Option<Expr<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
@ -545,16 +537,13 @@ impl<'a> AstNode<'a> for FnDef<'a> {
|
|||
impl<'a> ast::NameOwner<'a> for FnDef<'a> {}
|
||||
impl<'a> ast::TypeParamsOwner<'a> for FnDef<'a> {}
|
||||
impl<'a> ast::AttrsOwner<'a> for FnDef<'a> {}
|
||||
impl<'a> FnDef<'a> {
|
||||
pub fn param_list(self) -> Option<ParamList<'a>> {
|
||||
impl<'a> FnDef<'a> {pub fn param_list(self) -> Option<ParamList<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
|
||||
pub fn body(self) -> Option<Block<'a>> {
|
||||
pub fn body(self) -> Option<Block<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
|
||||
pub fn ret_type(self) -> Option<RetType<'a>> {
|
||||
pub fn ret_type(self) -> Option<RetType<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
@ -594,12 +583,10 @@ impl<'a> AstNode<'a> for ForExpr<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ast::LoopBodyOwner<'a> for ForExpr<'a> {}
|
||||
impl<'a> ForExpr<'a> {
|
||||
pub fn pat(self) -> Option<Pat<'a>> {
|
||||
impl<'a> ForExpr<'a> {pub fn pat(self) -> Option<Pat<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
|
||||
pub fn iterable(self) -> Option<Expr<'a>> {
|
||||
pub fn iterable(self) -> Option<Expr<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
@ -638,8 +625,7 @@ impl<'a> AstNode<'a> for IfExpr<'a> {
|
|||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> IfExpr<'a> {
|
||||
pub fn condition(self) -> Option<Condition<'a>> {
|
||||
impl<'a> IfExpr<'a> {pub fn condition(self) -> Option<Condition<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
@ -732,12 +718,10 @@ impl<'a> AstNode<'a> for LambdaExpr<'a> {
|
|||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> LambdaExpr<'a> {
|
||||
pub fn param_list(self) -> Option<ParamList<'a>> {
|
||||
impl<'a> LambdaExpr<'a> {pub fn param_list(self) -> Option<ParamList<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
|
||||
pub fn body(self) -> Option<Expr<'a>> {
|
||||
pub fn body(self) -> Option<Expr<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
@ -758,12 +742,10 @@ impl<'a> AstNode<'a> for LetStmt<'a> {
|
|||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> LetStmt<'a> {
|
||||
pub fn pat(self) -> Option<Pat<'a>> {
|
||||
impl<'a> LetStmt<'a> {pub fn pat(self) -> Option<Pat<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
|
||||
pub fn initializer(self) -> Option<Expr<'a>> {
|
||||
pub fn initializer(self) -> Option<Expr<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
@ -802,8 +784,7 @@ impl<'a> AstNode<'a> for LifetimeParam<'a> {
|
|||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> LifetimeParam<'a> {
|
||||
pub fn lifetime(self) -> Option<Lifetime<'a>> {
|
||||
impl<'a> LifetimeParam<'a> {pub fn lifetime(self) -> Option<Lifetime<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
@ -1162,8 +1143,7 @@ impl<'a> AstNode<'a> for Param<'a> {
|
|||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> Param<'a> {
|
||||
pub fn pat(self) -> Option<Pat<'a>> {
|
||||
impl<'a> Param<'a> {pub fn pat(self) -> Option<Pat<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
@ -1291,8 +1271,7 @@ impl<'a> AstNode<'a> for Path<'a> {
|
|||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> Path<'a> {
|
||||
pub fn segment(self) -> Option<PathSegment<'a>> {
|
||||
impl<'a> Path<'a> {pub fn segment(self) -> Option<PathSegment<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
@ -1349,8 +1328,7 @@ impl<'a> AstNode<'a> for PathSegment<'a> {
|
|||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> PathSegment<'a> {
|
||||
pub fn name_ref(self) -> Option<NameRef<'a>> {
|
||||
impl<'a> PathSegment<'a> {pub fn name_ref(self) -> Option<NameRef<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
@ -2012,8 +1990,7 @@ impl<'a> AstNode<'a> for UseItem<'a> {
|
|||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> UseItem<'a> {
|
||||
pub fn use_tree(self) -> Option<UseTree<'a>> {
|
||||
impl<'a> UseItem<'a> {pub fn use_tree(self) -> Option<UseTree<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
@ -2034,12 +2011,10 @@ impl<'a> AstNode<'a> for UseTree<'a> {
|
|||
fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
|
||||
}
|
||||
|
||||
impl<'a> UseTree<'a> {
|
||||
pub fn path(self) -> Option<Path<'a>> {
|
||||
impl<'a> UseTree<'a> {pub fn path(self) -> Option<Path<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
|
||||
pub fn use_tree_list(self) -> Option<UseTreeList<'a>> {
|
||||
pub fn use_tree_list(self) -> Option<UseTreeList<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
@ -2101,8 +2076,7 @@ impl<'a> AstNode<'a> for WhileExpr<'a> {
|
|||
}
|
||||
|
||||
impl<'a> ast::LoopBodyOwner<'a> for WhileExpr<'a> {}
|
||||
impl<'a> WhileExpr<'a> {
|
||||
pub fn condition(self) -> Option<Condition<'a>> {
|
||||
impl<'a> WhileExpr<'a> {pub fn condition(self) -> Option<Condition<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,8 +65,15 @@ impl<'a> {{ node }}<'a> {
|
|||
|
||||
{%- if methods.options -%}
|
||||
{%- for m in methods.options -%}
|
||||
|
||||
{%- if m is string -%}
|
||||
{%- set method_name = m | snake -%}
|
||||
{%- set ChildName = m %}
|
||||
{%- else -%}
|
||||
{%- set method_name = m.0 -%}
|
||||
{%- set ChildName = m.1 %}
|
||||
{%- endif -%}
|
||||
|
||||
pub fn {{ method_name }}(self) -> Option<{{ ChildName }}<'a>> {
|
||||
super::child_opt(self)
|
||||
}
|
||||
|
|
|
@ -250,11 +250,7 @@ Grammar(
|
|||
"TypeParamsOwner",
|
||||
"AttrsOwner",
|
||||
],
|
||||
options: [
|
||||
["param_list", "ParamList"],
|
||||
["body", "Block"],
|
||||
["ret_type", "RetType"]
|
||||
],
|
||||
options: [ "ParamList", ["body", "Block"], "RetType" ],
|
||||
),
|
||||
"RetType": (),
|
||||
"StructDef": (
|
||||
|
@ -346,12 +342,12 @@ Grammar(
|
|||
"PathExpr": (),
|
||||
"LambdaExpr": (
|
||||
options: [
|
||||
["param_list", "ParamList"],
|
||||
"ParamList",
|
||||
["body", "Expr"],
|
||||
]
|
||||
),
|
||||
"IfExpr": (
|
||||
options: [ ["condition", "Condition"] ]
|
||||
options: [ "Condition" ]
|
||||
),
|
||||
"LoopExpr": (
|
||||
traits: ["LoopBodyOwner"],
|
||||
|
@ -359,21 +355,19 @@ Grammar(
|
|||
"ForExpr": (
|
||||
traits: ["LoopBodyOwner"],
|
||||
options: [
|
||||
["pat", "Pat"],
|
||||
"Pat",
|
||||
["iterable", "Expr"],
|
||||
]
|
||||
),
|
||||
"WhileExpr": (
|
||||
traits: ["LoopBodyOwner"],
|
||||
options: [
|
||||
["condition", "Condition"],
|
||||
]
|
||||
options: [ "Condition" ]
|
||||
),
|
||||
"ContinueExpr": (),
|
||||
"BreakExpr": (),
|
||||
"Label": (),
|
||||
"BlockExpr": (
|
||||
options: [ ["block", "Block"] ]
|
||||
options: [ "Block" ]
|
||||
),
|
||||
"ReturnExpr": (),
|
||||
"MatchExpr": (),
|
||||
|
@ -384,10 +378,7 @@ Grammar(
|
|||
"NamedFieldList": (),
|
||||
"NamedField": (),
|
||||
"CallExpr": (
|
||||
options: [
|
||||
[ "expr", "Expr" ],
|
||||
[ "arg_list", "ArgList" ],
|
||||
]
|
||||
options: [ "Expr", "ArgList" ]
|
||||
),
|
||||
"IndexExpr": (),
|
||||
"MethodCallExpr": (),
|
||||
|
@ -474,7 +465,7 @@ Grammar(
|
|||
]
|
||||
),
|
||||
"TypeParam": ( traits: ["NameOwner"] ),
|
||||
"LifetimeParam": ( options: [ ["lifetime", "Lifetime"] ] ),
|
||||
"LifetimeParam": ( options: [ "Lifetime" ] ),
|
||||
"Lifetime": (),
|
||||
"WhereClause": (),
|
||||
"ExprStmt": (
|
||||
|
@ -485,16 +476,13 @@ Grammar(
|
|||
["initializer", "Expr"],
|
||||
]),
|
||||
"Condition": (
|
||||
options: [
|
||||
[ "pat", "Pat" ],
|
||||
[ "expr", "Expr" ],
|
||||
]
|
||||
options: [ "Pat", "Expr" ]
|
||||
),
|
||||
"Stmt": (
|
||||
enum: ["ExprStmt", "LetStmt"],
|
||||
),
|
||||
"Block": (
|
||||
options: [["expr", "Expr"]],
|
||||
options: [ "Expr" ],
|
||||
collections: [
|
||||
["statements", "Stmt"],
|
||||
]
|
||||
|
@ -505,16 +493,13 @@ Grammar(
|
|||
]
|
||||
),
|
||||
"Param": (
|
||||
options: [["pat", "Pat"]],
|
||||
options: [ "Pat" ],
|
||||
),
|
||||
"UseItem": (
|
||||
options: [["use_tree", "UseTree"]]
|
||||
options: [ "UseTree" ]
|
||||
),
|
||||
"UseTree": (
|
||||
options: [
|
||||
["path", "Path"],
|
||||
["use_tree_list", "UseTreeList"],
|
||||
]
|
||||
options: [ "Path", "UseTreeList" ]
|
||||
),
|
||||
"UseTreeList": (
|
||||
collections: [["use_trees", "UseTree"]]
|
||||
|
@ -531,9 +516,7 @@ Grammar(
|
|||
]
|
||||
),
|
||||
"PathSegment": (
|
||||
options: [
|
||||
["name_ref", "NameRef"]
|
||||
]
|
||||
options: [ "NameRef" ]
|
||||
),
|
||||
},
|
||||
)
|
||||
|
|
|
@ -10,7 +10,7 @@ extern crate commandspec;
|
|||
extern crate heck;
|
||||
|
||||
use clap::{App, Arg, SubCommand};
|
||||
use heck::{CamelCase, ShoutySnakeCase};
|
||||
use heck::{CamelCase, ShoutySnakeCase, SnakeCase};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fs,
|
||||
|
@ -91,6 +91,9 @@ fn render_template(template: &str) -> Result<String> {
|
|||
tera.register_filter("camel", |arg, _| {
|
||||
Ok(arg.as_str().unwrap().to_camel_case().into())
|
||||
});
|
||||
tera.register_filter("snake", |arg, _| {
|
||||
Ok(arg.as_str().unwrap().to_snake_case().into())
|
||||
});
|
||||
tera.register_filter("SCREAM", |arg, _| {
|
||||
Ok(arg.as_str().unwrap().to_shouty_snake_case().into())
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue