Skip to main content

rust_analyzer/cli/
highlight.rs

1//! Read Rust code on stdin, print HTML highlighted version to stdout.
2
3use ide::Analysis;
4use ide_db::base_db::AbsPathBuf;
5use triomphe::Arc;
6
7use crate::cli::{flags, read_stdin};
8
9impl flags::Highlight {
10    pub fn run(self) -> anyhow::Result<()> {
11        let cwd = AbsPathBuf::assert_utf8(std::env::current_dir()?);
12        let (analysis, file_id) = Analysis::from_single_file(read_stdin()?, Arc::new(cwd));
13        let html = analysis.highlight_as_html(file_id, self.rainbow).unwrap();
14        println!("{html}");
15        Ok(())
16    }
17}