rust_analyzer_proc_macro_srv/
version.rs1#![expect(dead_code)]
3
4use std::fmt;
5
6pub(crate) struct CommitInfo {
8 pub(crate) short_commit_hash: &'static str,
9 pub(crate) commit_hash: &'static str,
10 pub(crate) commit_date: &'static str,
11}
12
13pub(crate) struct VersionInfo {
15 pub(crate) version: &'static str,
17 pub(crate) release_channel: Option<&'static str>,
21 pub(crate) commit_info: Option<CommitInfo>,
25}
26
27impl fmt::Display for VersionInfo {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 write!(f, "{}", self.version)?;
30
31 if let Some(ci) = &self.commit_info {
32 write!(f, " ({} {})", ci.short_commit_hash, ci.commit_date)?;
33 };
34 Ok(())
35 }
36}
37
38pub(crate) const fn version() -> VersionInfo {
40 let version = match option_env!("CFG_RELEASE") {
41 Some(x) => x,
42 None => "0.0.0",
43 };
44
45 let release_channel = option_env!("CFG_RELEASE_CHANNEL");
46 let commit_info = match (
47 option_env!("RA_COMMIT_SHORT_HASH"),
48 option_env!("RA_COMMIT_HASH"),
49 option_env!("RA_COMMIT_DATE"),
50 ) {
51 (Some(short_commit_hash), Some(commit_hash), Some(commit_date)) => {
52 Some(CommitInfo { short_commit_hash, commit_hash, commit_date })
53 }
54 _ => None,
55 };
56
57 VersionInfo { version, release_channel, commit_info }
58}