rust_analyzer/cli/
parse.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//! Read Rust code on stdin, print syntax tree on stdout.
use ide::Edition;
use syntax::{AstNode, SourceFile};

use crate::cli::{flags, read_stdin};

impl flags::Parse {
    pub fn run(self) -> anyhow::Result<()> {
        let _p = tracing::info_span!("flags::Parse::run").entered();
        let text = read_stdin()?;
        let file = SourceFile::parse(&text, Edition::CURRENT).tree();
        if !self.no_dump {
            println!("{:#?}", file.syntax());
        }
        std::mem::forget(file);
        Ok(())
    }
}