- Notifications
You must be signed in to change notification settings - Fork109
chore: rename env vars#558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| //! Environment variables and configuration constants for PostgresLanguage Server. | ||
| //! | ||
| //! This module provides: | ||
| //! - Environment variable definitions for runtime configuration | ||
| @@ -10,13 +10,14 @@ use pgt_console::{DebugDisplay, KeyValuePair, markup}; | ||
| use std::env; | ||
| use std::sync::{LazyLock, OnceLock}; | ||
| /// Returns `true` if this is an unstable build of PostgresLanguage Server | ||
| pub fn is_unstable() -> bool { | ||
| VERSION == "0.0.0" | ||
| } | ||
| /// The internal version of Postgres Language Server. This is usually supplied during the CI build | ||
| pub static PGLS_VERSION: LazyLock<Option<&str>> = | ||
| LazyLock::new(|| option_env!("PGLS_VERSION").or(option_env!("PGT_VERSION"))); | ||
| /// The version of Postgres Tools with fallback logic | ||
| pub const VERSION: &str = match option_env!("PGT_VERSION") { | ||
| @@ -27,44 +28,72 @@ pub const VERSION: &str = match option_env!("PGT_VERSION") { | ||
| }, | ||
| }; | ||
| pub staticPGLS_WEBSITE: &str = "https://pgtools.dev"; | ||
| pub struct PgLSEnv { | ||
| pub pgls_log_path: PgLSEnvVariable, | ||
| pub pgls_log_level: PgLSEnvVariable, | ||
| pub pgls_log_prefix: PgLSEnvVariable, | ||
| pub pgls_config_path: PgLSEnvVariable, | ||
| // DEPRECATED | ||
| pub pgt_log_path: PgLSEnvVariable, | ||
| pub pgt_log_level: PgLSEnvVariable, | ||
| pub pgt_log_prefix: PgLSEnvVariable, | ||
| pub pgt_config_path: PgLSEnvVariable, | ||
| } | ||
| pub static PGT_ENV: OnceLock<PgLSEnv> = OnceLock::new(); | ||
| implPgLSEnv { | ||
| fn new() -> Self { | ||
| Self { | ||
| pgls_log_path: PgLSEnvVariable::new( | ||
| "PGLS_LOG_PATH", | ||
| "The directory where the Daemon logs will be saved.", | ||
| ), | ||
| pgls_log_level: PgLSEnvVariable::new( | ||
Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I think the | ||
| "PGLS_LOG_LEVEL", | ||
| "Allows to change the log level. Default is debug. This will only affect \"pgt*\" crates. All others are logged with info level.", | ||
| ), | ||
| pgls_log_prefix: PgLSEnvVariable::new( | ||
| "PGLS_LOG_PREFIX_NAME", | ||
| "A prefix that's added to the name of the log. Default: `server.log.`", | ||
| ), | ||
| pgls_config_path: PgLSEnvVariable::new( | ||
| "PGLS_CONFIG_PATH", | ||
| "A path to the configuration file", | ||
| ), | ||
| pgt_log_path: PgLSEnvVariable::new( | ||
| "PGT_LOG_PATH", | ||
| "The directory where the Daemon logs will be saved. Deprecated, use PGLS_LOG_PATH instead.", | ||
| ), | ||
| pgt_log_level: PgLSEnvVariable::new( | ||
| "PGT_LOG_LEVEL", | ||
| "Allows to change the log level. Default is debug. This will only affect \"pgt*\" crates. All others are logged with info level. Deprecated, use PGLS_LOG_LEVEL instead.", | ||
| ), | ||
| pgt_log_prefix: PgLSEnvVariable::new( | ||
| "PGT_LOG_PREFIX_NAME", | ||
| "A prefix that's added to the name of the log. Default: `server.log`. Deprecated, use PGLS_LOG_PREFIX_NAME instead.", | ||
| ), | ||
| pgt_config_path: PgLSEnvVariable::new( | ||
| "PGT_CONFIG_PATH", | ||
| "A path to the configuration file. Deprecated, use PGLS_CONFIG_PATH instead.", | ||
| ), | ||
| } | ||
| } | ||
| } | ||
| pub structPgLSEnvVariable { | ||
| /// The name of the environment variable | ||
| name: &'static str, | ||
| /// The description of the variable. | ||
| // This field will be used in the website to automate its generation | ||
| description: &'static str, | ||
| } | ||
| implPgLSEnvVariable { | ||
| fn new(name: &'static str, description: &'static str) -> Self { | ||
| Self { name, description } | ||
| } | ||
| @@ -85,12 +114,49 @@ impl PgTEnvVariable { | ||
| } | ||
| } | ||
| pub fnpgls_env() -> &'staticPgLSEnv { | ||
| PGT_ENV.get_or_init(PgLSEnv::new) | ||
| } | ||
| impl Display forPgLSEnv { | ||
| fn fmt(&self, fmt: &mut Formatter) -> std::io::Result<()> { | ||
| match self.pgls_log_path.value() { | ||
| None => { | ||
| KeyValuePair(self.pgls_log_path.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?; | ||
| } | ||
| Some(value) => { | ||
| KeyValuePair(self.pgls_log_path.name, markup! {{DebugDisplay(value)}}).fmt(fmt)?; | ||
| } | ||
| }; | ||
| match self.pgls_log_level.value() { | ||
| None => { | ||
| KeyValuePair(self.pgls_log_level.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?; | ||
| } | ||
| Some(value) => { | ||
| KeyValuePair(self.pgls_log_level.name, markup! {{DebugDisplay(value)}}).fmt(fmt)?; | ||
| } | ||
| }; | ||
| match self.pgls_log_prefix.value() { | ||
| None => { | ||
| KeyValuePair(self.pgls_log_prefix.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?; | ||
| } | ||
| Some(value) => { | ||
| KeyValuePair(self.pgls_log_prefix.name, markup! {{DebugDisplay(value)}}) | ||
| .fmt(fmt)?; | ||
| } | ||
| }; | ||
| match self.pgls_config_path.value() { | ||
| None => { | ||
| KeyValuePair(self.pgls_config_path.name, markup! { <Dim>"unset"</Dim> }) | ||
| .fmt(fmt)?; | ||
| } | ||
| Some(value) => { | ||
| KeyValuePair(self.pgls_config_path.name, markup! {{DebugDisplay(value)}}) | ||
| .fmt(fmt)?; | ||
| } | ||
| }; | ||
| match self.pgt_log_path.value() { | ||
| None => { | ||
| KeyValuePair(self.pgt_log_path.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?; | ||
| @@ -99,6 +165,14 @@ impl Display for PgTEnv { | ||
| KeyValuePair(self.pgt_log_path.name, markup! {{DebugDisplay(value)}}).fmt(fmt)?; | ||
| } | ||
| }; | ||
| match self.pgt_log_level.value() { | ||
| None => { | ||
| KeyValuePair(self.pgt_log_level.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?; | ||
| } | ||
| Some(value) => { | ||
| KeyValuePair(self.pgt_log_level.name, markup! {{DebugDisplay(value)}}).fmt(fmt)?; | ||
| } | ||
| }; | ||
| match self.pgt_log_prefix.value() { | ||
| None => { | ||
| KeyValuePair(self.pgt_log_prefix.name, markup! { <Dim>"unset"</Dim> }).fmt(fmt)?; | ||
Uh oh!
There was an error while loading.Please reload this page.