mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Use From to get an owned AST
This commit is contained in:
parent
3ec9f958b3
commit
d685a9b564
3 changed files with 701 additions and 402 deletions
|
@ -11,8 +11,7 @@ use crate::descriptors::{
|
||||||
/// TODO: this should return something more type-safe then `SyntaxNode`
|
/// TODO: this should return something more type-safe then `SyntaxNode`
|
||||||
pub(crate) fn fn_syntax(db: &impl DescriptorDatabase, fn_id: FnId) -> FnDefNode {
|
pub(crate) fn fn_syntax(db: &impl DescriptorDatabase, fn_id: FnId) -> FnDefNode {
|
||||||
let syntax = db.resolve_syntax_ptr(fn_id.0);
|
let syntax = db.resolve_syntax_ptr(fn_id.0);
|
||||||
let fn_def = FnDef::cast(syntax.borrowed()).unwrap();
|
FnDef::cast(syntax.borrowed()).unwrap().into()
|
||||||
FnDefNode::new(fn_def)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn fn_scopes(db: &impl DescriptorDatabase, fn_id: FnId) -> Arc<FnScopes> {
|
pub(crate) fn fn_scopes(db: &impl DescriptorDatabase, fn_id: FnId) -> Arc<FnScopes> {
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -17,15 +17,18 @@ use crate::{
|
||||||
pub struct {{ node }}Node(SyntaxNode);
|
pub struct {{ node }}Node(SyntaxNode);
|
||||||
|
|
||||||
impl {{ node }}Node {
|
impl {{ node }}Node {
|
||||||
pub fn new(ast: {{ node }}) -> {{ node }}Node {
|
|
||||||
let syntax = ast.syntax().owned();
|
|
||||||
{{ node }}Node(syntax)
|
|
||||||
}
|
|
||||||
pub fn ast(&self) -> {{ node }} {
|
pub fn ast(&self) -> {{ node }} {
|
||||||
{{ node }}::cast(self.0.borrowed()).unwrap()
|
{{ node }}::cast(self.0.borrowed()).unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> From<{{ node }}<'a>> for {{ node }}Node {
|
||||||
|
fn from(ast: {{ node}}<'a>) -> {{ node }}Node {
|
||||||
|
let syntax = ast.syntax().owned();
|
||||||
|
{{ node }}Node(syntax)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
{%- if methods.enum %}
|
{%- if methods.enum %}
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub enum {{ node }}<'a> {
|
pub enum {{ node }}<'a> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue