1- //! Environment variables and configuration constants for Postgres Tools .
1+ //! Environment variables and configuration constants for Postgres Language Server .
22//!
33//! This module provides:
44//! - Environment variable definitions for runtime configuration
@@ -10,13 +10,14 @@ use pgt_console::{DebugDisplay, KeyValuePair, markup};
1010use std:: env;
1111use std:: sync:: { LazyLock , OnceLock } ;
1212
13- /// Returns `true` if this is an unstable build of Postgres Tools
13+ /// Returns `true` if this is an unstable build of Postgres Language Server
1414pub fn is_unstable ( ) -> bool {
1515 VERSION == "0.0.0"
1616}
1717
18- /// The internal version of Postgres Tools. This is usually supplied during the CI build
19- pub static PGT_VERSION : LazyLock < Option < & str > > = LazyLock :: new ( || option_env ! ( "PGT_VERSION" ) ) ;
18+ /// The internal version of Postgres Language Server. This is usually supplied during the CI build
19+ pub static PGLS_VERSION : LazyLock < Option < & str > > =
20+ LazyLock :: new ( || option_env ! ( "PGLS_VERSION" ) . or ( option_env ! ( "PGT_VERSION" ) ) ) ;
2021
2122/// The version of Postgres Tools with fallback logic
2223pub const VERSION : & str = match option_env ! ( "PGT_VERSION" ) {
@@ -27,44 +28,67 @@ pub const VERSION: &str = match option_env!("PGT_VERSION") {
2728 } ,
2829} ;
2930
30- pub static PGT_WEBSITE : & str = "https://pgtools.dev" ;
31+ pub static PGLS_WEBSITE : & str = "https://pgtools.dev" ;
3132
32- pub struct PgTEnv {
33- pub pgt_log_path : PgTEnvVariable ,
34- pub pgt_log_prefix : PgTEnvVariable ,
35- pub pgt_config_path : PgTEnvVariable ,
33+ pub struct PgLSEnv {
34+ pub pgls_log_path : PgLSEnvVariable ,
35+ pub pgls_log_level : PgLSEnvVariable ,
36+ pub pgls_log_prefix : PgLSEnvVariable ,
37+ pub pgls_config_path : PgLSEnvVariable ,
38+
39+ // DEPRECATED
40+ pub pgt_log_path : PgLSEnvVariable ,
41+ pub pgt_log_prefix : PgLSEnvVariable ,
42+ pub pgt_config_path : PgLSEnvVariable ,
3643}
3744
38- pub static PGT_ENV : OnceLock < PgTEnv > = OnceLock :: new ( ) ;
45+ pub static PGT_ENV : OnceLock < PgLSEnv > = OnceLock :: new ( ) ;
3946
40- impl PgTEnv {
47+ impl PgLSEnv {
4148 fn new ( ) -> Self {
4249 Self {
43- pgt_log_path : PgTEnvVariable :: new (
44- "PGT_LOG_PATH " ,
50+ pgls_log_path : PgLSEnvVariable :: new (
51+ "PGLS_LOG_PATH " ,
4552 "The directory where the Daemon logs will be saved." ,
4653 ) ,
47- pgt_log_prefix : PgTEnvVariable :: new (
48- "PGT_LOG_PREFIX_NAME" ,
54+ pgls_log_level : PgLSEnvVariable :: new (
55+ "PGLS_LOG_LEVEL" ,
56+ "Allows to change the log level. Default is debug. This will only affect \" pgt*\" crates. All others are logged with info level." ,
57+ ) ,
58+ pgls_log_prefix : PgLSEnvVariable :: new (
59+ "PGLS_LOG_PREFIX_NAME" ,
4960 "A prefix that's added to the name of the log. Default: `server.log.`" ,
5061 ) ,
51- pgt_config_path : PgTEnvVariable :: new (
52- "PGT_CONFIG_PATH " ,
62+ pgls_config_path : PgLSEnvVariable :: new (
63+ "PGLS_CONFIG_PATH " ,
5364 "A path to the configuration file" ,
5465 ) ,
66+
67+ pgt_log_path : PgLSEnvVariable :: new (
68+ "PGT_LOG_PATH" ,
69+ "The directory where the Daemon logs will be saved. Deprecated, use PGLS_LOG_PATH instead." ,
70+ ) ,
71+ pgt_log_prefix : PgLSEnvVariable :: new (
72+ "PGT_LOG_PREFIX_NAME" ,
73+ "A prefix that's added to the name of the log. Default: `server.log`. Deprecated, use PGLS_LOG_PREFIX_NAME instead." ,
74+ ) ,
75+ pgt_config_path : PgLSEnvVariable :: new (
76+ "PGT_CONFIG_PATH" ,
77+ "A path to the configuration file. Deprecated, use PGLS_CONFIG_PATH instead." ,
78+ ) ,
5579 }
5680 }
5781}
5882
59- pub struct PgTEnvVariable {
83+ pub struct PgLSEnvVariable {
6084 /// The name of the environment variable
6185 name : & ' static str ,
6286 /// The description of the variable.
6387 // This field will be used in the website to automate its generation
6488 description : & ' static str ,
6589}
6690
67- impl PgTEnvVariable {
91+ impl PgLSEnvVariable {
6892 fn new ( name : & ' static str , description : & ' static str ) -> Self {
6993 Self { name, description }
7094 }
@@ -85,12 +109,41 @@ impl PgTEnvVariable {
85109 }
86110}
87111
88- pub fn pgt_env ( ) -> & ' static PgTEnv {
89- PGT_ENV . get_or_init ( PgTEnv :: new)
112+ pub fn pgls_env ( ) -> & ' static PgLSEnv {
113+ PGT_ENV . get_or_init ( PgLSEnv :: new)
90114}
91115
92- impl Display for PgTEnv {
116+ impl Display for PgLSEnv {
93117 fn fmt ( & self , fmt : & mut Formatter ) -> std:: io:: Result < ( ) > {
118+ match self . pgls_log_path . value ( ) {
119+ None => {
120+ KeyValuePair ( self . pgls_log_path . name , markup ! { <Dim >"unset" </Dim > } ) . fmt ( fmt) ?;
121+ }
122+ Some ( value) => {
123+ KeyValuePair ( self . pgls_log_path . name , markup ! { { DebugDisplay ( value) } } ) . fmt ( fmt) ?;
124+ }
125+ } ;
126+ match self . pgls_log_prefix . value ( ) {
127+ None => {
128+ KeyValuePair ( self . pgls_log_prefix . name , markup ! { <Dim >"unset" </Dim > } ) . fmt ( fmt) ?;
129+ }
130+ Some ( value) => {
131+ KeyValuePair ( self . pgls_log_prefix . name , markup ! { { DebugDisplay ( value) } } )
132+ . fmt ( fmt) ?;
133+ }
134+ } ;
135+
136+ match self . pgls_config_path . value ( ) {
137+ None => {
138+ KeyValuePair ( self . pgls_config_path . name , markup ! { <Dim >"unset" </Dim > } )
139+ . fmt ( fmt) ?;
140+ }
141+ Some ( value) => {
142+ KeyValuePair ( self . pgls_config_path . name , markup ! { { DebugDisplay ( value) } } )
143+ . fmt ( fmt) ?;
144+ }
145+ } ;
146+
94147 match self . pgt_log_path . value ( ) {
95148 None => {
96149 KeyValuePair ( self . pgt_log_path . name , markup ! { <Dim >"unset" </Dim > } ) . fmt ( fmt) ?;
0 commit comments