1 //! Code for representing rust-analyzer's release version number.
5 /// Information about the git repository where rust-analyzer was built from.
6 pub struct CommitInfo {
7 pub short_commit_hash: &'static str,
8 pub commit_hash: &'static str,
9 pub commit_date: &'static str,
13 pub struct VersionInfo {
14 /// rust-analyzer's version, such as "1.57.0", "1.58.0-beta.1", "1.59.0-nightly", etc.
15 pub version: &'static str,
16 /// The release channel we were built for (stable/beta/nightly/dev).
18 /// `None` if not built via rustbuild.
19 pub release_channel: Option<&'static str>,
20 /// Information about the Git repository we may have been built from.
22 /// `None` if not built from a git repo.
23 pub commit_info: Option<CommitInfo>,
26 impl fmt::Display for VersionInfo {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 write!(f, "{}", self.version)?;
30 if let Some(ci) = &self.commit_info {
31 write!(f, " ({} {})", ci.short_commit_hash, ci.commit_date)?;
37 /// Returns information about cargo's version.
38 pub const fn version() -> VersionInfo {
39 let version = match option_env!("CFG_RELEASE") {
44 let release_channel = option_env!("CFG_RELEASE_CHANNEL");
45 let commit_info = match (
46 option_env!("RA_COMMIT_SHORT_HASH"),
47 option_env!("RA_COMMIT_HASH"),
48 option_env!("RA_COMMIT_DATE"),
50 (Some(short_commit_hash), Some(commit_hash), Some(commit_date)) => {
51 Some(CommitInfo { short_commit_hash, commit_hash, commit_date })
56 VersionInfo { version, release_channel, commit_info }