rust_analyzer/cli/
symbols.rs

1//! Read Rust code on stdin, print syntax tree on stdout.
2use ide::{Analysis, FileStructureConfig};
3
4use crate::cli::{flags, read_stdin};
5
6impl flags::Symbols {
7    pub fn run(self) -> anyhow::Result<()> {
8        let text = read_stdin()?;
9        let (analysis, file_id) = Analysis::from_single_file(text);
10        let structure = analysis
11            // The default setting in config.rs (document_symbol_search_excludeLocals) is to exclude
12            // locals because it is unlikely that users want document search to return the names of
13            // local variables, but here we include them deliberately.
14            .file_structure(&FileStructureConfig { exclude_locals: false }, file_id)
15            .unwrap();
16        for s in structure {
17            println!("{s:?}");
18        }
19        Ok(())
20    }
21}