diff --git a/crates/pgt_analyse/src/options.rs b/crates/pgt_analyse/src/options.rs index 211cb1dc2..e46b7104f 100644 --- a/crates/pgt_analyse/src/options.rs +++ b/crates/pgt_analyse/src/options.rs @@ -45,7 +45,7 @@ impl AnalyserRules { /// A set of information useful to the analyser infrastructure #[derive(Debug, Default)] pub struct AnalyserOptions { - /// A data structured derived from the [`postgrestools.jsonc`] file + /// A data structured derived from the [`postgres-language-server.jsonc`] file pub rules: AnalyserRules, } diff --git a/crates/pgt_analyser/CONTRIBUTING.md b/crates/pgt_analyser/CONTRIBUTING.md index b0929eda9..8eadbc4b1 100644 --- a/crates/pgt_analyser/CONTRIBUTING.md +++ b/crates/pgt_analyser/CONTRIBUTING.md @@ -81,7 +81,7 @@ Let's assume that the rule we implement support the following options: - `threshold`: an integer between 0 and 255; - `behaviorExceptions`: an array of strings. -We would like to set the options in the `postgrestools.jsonc` configuration file: +We would like to set the options in the `postgres-language-server.jsonc` configuration file: ```json { @@ -143,9 +143,9 @@ We currently require implementing _serde_'s traits `Deserialize`/`Serialize`. Also, we use other `serde` macros to adjust the JSON configuration: -- `rename_all = "camelCase"`: it renames all fields in camel-case, so they are in line with the naming style of the `postgrestools.jsonc`. +- `rename_all = "camelCase"`: it renames all fields in camel-case, so they are in line with the naming style of the `postgres-language-server.jsonc`. - `deny_unknown_fields`: it raises an error if the configuration contains extraneous fields. -- `default`: it uses the `Default` value when the field is missing from `postgrestools.jsonc`. This macro makes the field optional. +- `default`: it uses the `Default` value when the field is missing from `postgres-language-server.jsonc`. This macro makes the field optional. You can simply use a derive macros: diff --git a/crates/pgt_cli/src/cli_options.rs b/crates/pgt_cli/src/cli_options.rs index 5c41c7fc1..f0040c094 100644 --- a/crates/pgt_cli/src/cli_options.rs +++ b/crates/pgt_cli/src/cli_options.rs @@ -22,7 +22,7 @@ pub struct CliOptions { #[bpaf(long("verbose"), switch, fallback(false))] pub verbose: bool, - /// Set the file path to the configuration file, or the directory path to find `postgrestools.jsonc`. + /// Set the file path to the configuration file, or the directory path to find `postgres-language-server.jsonc`. /// If used, it disables the default configuration file resolution. #[bpaf(long("config-path"), argument("PATH"), optional)] pub config_path: Option, diff --git a/crates/pgt_cli/src/commands/init.rs b/crates/pgt_cli/src/commands/init.rs index 15b1b8a50..154b3e0b7 100644 --- a/crates/pgt_cli/src/commands/init.rs +++ b/crates/pgt_cli/src/commands/init.rs @@ -8,10 +8,10 @@ pub(crate) fn init(mut session: CliSession) -> Result<(), CliDiagnostic> { let fs = &mut session.app.fs; let config = &mut PartialConfiguration::init(); create_config(fs, config)?; - let file_created = ConfigName::pgt_jsonc(); + let file_created = ConfigName::pgls_jsonc(); session.app.console.log(markup! { " -Welcome to the Postgres Language Tools! Let's get you started... +Welcome to the Postgres Language Server! Let's get you started... ""Files created "" diff --git a/crates/pgt_cli/src/commands/mod.rs b/crates/pgt_cli/src/commands/mod.rs index 19dc56ade..1457cf77e 100644 --- a/crates/pgt_cli/src/commands/mod.rs +++ b/crates/pgt_cli/src/commands/mod.rs @@ -7,8 +7,8 @@ use crate::{ }; use bpaf::Bpaf; use pgt_configuration::{PartialConfiguration, partial_configuration}; -use pgt_console::Console; -use pgt_fs::FileSystem; +use pgt_console::{Console, ConsoleExt, markup}; +use pgt_fs::{ConfigName, FileSystem}; use pgt_workspace::PartialConfigurationExt; use pgt_workspace::configuration::{LoadedConfiguration, load_configuration}; use pgt_workspace::workspace::{RegisterProjectFolderParams, UpdateSettingsParams}; @@ -58,7 +58,7 @@ pub enum PgtCommand { changed: bool, /// Use this to specify the base branch to compare against when you're using the --changed - /// flag and the `defaultBranch` is not set in your `postgrestools.jsonc` + /// flag and the `defaultBranch` is not set in your `postgres-language-server.jsonc` #[bpaf(long("since"), argument("REF"))] since: Option, @@ -91,8 +91,13 @@ pub enum PgtCommand { )] log_path: PathBuf, /// Allows to set a custom file path to the configuration file, - /// or a custom directory path to find `postgrestools.jsonc` - #[bpaf(env("PGT_LOG_PREFIX_NAME"), long("config-path"), argument("PATH"))] + /// or a custom directory path to find `postgres-language-server.jsonc` + #[bpaf( + env("PGT_LOG_PREFIX_NAME"), + env("PGLS_LOG_PREFIX_NAME"), + long("config-path"), + argument("PATH") + )] config_path: Option, }, @@ -127,8 +132,13 @@ pub enum PgtCommand { )] log_path: PathBuf, /// Allows to set a custom file path to the configuration file, - /// or a custom directory path to find `postgrestools.jsonc` - #[bpaf(env("PGT_CONFIG_PATH"), long("config-path"), argument("PATH"))] + /// or a custom directory path to find `postgres-language-server.jsonc` + #[bpaf( + env("PGT_CONFIG_PATH"), + env("PGLS_CONFIG_PATH"), + long("config-path"), + argument("PATH") + )] config_path: Option, /// Bogus argument to make the command work with vscode-languageclient #[bpaf(long("stdio"), hide, hide_usage, switch)] @@ -183,8 +193,13 @@ pub enum PgtCommand { #[bpaf(long("stop-on-disconnect"), hide_usage)] stop_on_disconnect: bool, /// Allows to set a custom file path to the configuration file, - /// or a custom directory path to find `postgrestools.jsonc` - #[bpaf(env("PGT_CONFIG_PATH"), long("config-path"), argument("PATH"))] + /// or a custom directory path to find `postgres-language-server.jsonc` + #[bpaf( + env("PGT_CONFIG_PATH"), + env("PGLS_CONFIG_PATH"), + long("config-path"), + argument("PATH") + )] config_path: Option, }, #[bpaf(command("__print_socket"), hide)] @@ -295,6 +310,19 @@ pub(crate) trait CommandRunner: Sized { let loaded_configuration = load_configuration(fs, cli_options.as_configuration_path_hint())?; + // Check for deprecated config filename + if let Some(config_path) = &loaded_configuration.file_path { + if let Some(file_name) = config_path.file_name().and_then(|n| n.to_str()) { + if ConfigName::is_deprecated(file_name) { + console.log(markup! { + "Warning: ""You are using the deprecated config filename '""postgrestools.jsonc""'. \ + Please rename it to '""postgres-language-server.jsonc""'. \ + Support for the old filename will be removed in a future version.\n" + }); + } + } + } + let configuration_path = loaded_configuration.directory_path.clone(); let configuration = self.merge_configuration(loaded_configuration, fs, console)?; let vcs_base_path = configuration_path.or(fs.working_directory()); diff --git a/crates/pgt_cli/src/diagnostics.rs b/crates/pgt_cli/src/diagnostics.rs index 20d32113c..c716d0028 100644 --- a/crates/pgt_cli/src/diagnostics.rs +++ b/crates/pgt_cli/src/diagnostics.rs @@ -47,7 +47,7 @@ pub enum CliDiagnostic { IoError(IoDiagnostic), /// The daemon is not running ServerNotRunning(ServerNotRunning), - /// The end configuration (`postgrestools.jsonc` + other options) is incompatible with the command + /// The end configuration (`postgres-language-server.jsonc` + other options) is incompatible with the command IncompatibleEndConfiguration(IncompatibleEndConfiguration), /// No files processed during the file system traversal NoFilesWereProcessed(NoFilesWereProcessed), @@ -390,7 +390,7 @@ impl CliDiagnostic { Self::ServerNotRunning(ServerNotRunning) } - /// Emitted when the end configuration (`postgrestools.jsonc` file + CLI arguments + LSP configuration) + /// Emitted when the end configuration (`postgres-language-server.jsonc` file + CLI arguments + LSP configuration) /// results in a combination of options that doesn't allow to run the command correctly. /// /// A reason needs to be provided diff --git a/crates/pgt_configuration/src/lib.rs b/crates/pgt_configuration/src/lib.rs index 2fe8b399a..c5e8b9f1a 100644 --- a/crates/pgt_configuration/src/lib.rs +++ b/crates/pgt_configuration/src/lib.rs @@ -1,4 +1,4 @@ -//! This module contains the configuration of `postgrestools.jsonc` +//! This module contains the configuration of `postgres-language-server.jsonc` //! //! The configuration is divided by "tool". diff --git a/crates/pgt_configuration/src/vcs.rs b/crates/pgt_configuration/src/vcs.rs index b665a36f5..1dfc5245a 100644 --- a/crates/pgt_configuration/src/vcs.rs +++ b/crates/pgt_configuration/src/vcs.rs @@ -28,7 +28,7 @@ pub struct VcsConfiguration { pub use_ignore_file: bool, /// The folder where we should check for VCS files. By default, we will use the same - /// folder where `postgrestools.jsonc` was found. + /// folder where `postgres-language-server.jsonc` was found. /// /// If we can't find the configuration, it will attempt to use the current working directory. /// If no current working directory can't be found, we won't use the VCS integration, and a diagnostic diff --git a/crates/pgt_fs/src/fs.rs b/crates/pgt_fs/src/fs.rs index 2bfd2e51b..d7f1a24de 100644 --- a/crates/pgt_fs/src/fs.rs +++ b/crates/pgt_fs/src/fs.rs @@ -19,14 +19,18 @@ mod os; pub struct ConfigName; impl ConfigName { - const PGT_JSONC: [&'static str; 1] = ["postgrestools.jsonc"]; + const PGLS_JSONC: [&'static str; 2] = ["postgres-language-server.jsonc", "postgrestools.jsonc"]; - pub const fn pgt_jsonc() -> &'static str { - Self::PGT_JSONC[0] + pub fn is_deprecated(file_name: &str) -> bool { + file_name == Self::PGLS_JSONC[1] } - pub const fn file_names() -> [&'static str; 1] { - Self::PGT_JSONC + pub const fn pgls_jsonc() -> &'static str { + Self::PGLS_JSONC[0] + } + + pub const fn file_names() -> [&'static str; 2] { + Self::PGLS_JSONC } } diff --git a/crates/pgt_fs/src/path.rs b/crates/pgt_fs/src/path.rs index 811bebe59..ed7f7e16d 100644 --- a/crates/pgt_fs/src/path.rs +++ b/crates/pgt_fs/src/path.rs @@ -21,7 +21,7 @@ use crate::ConfigName; #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] // NOTE: The order of the variants is important, the one on the top has the highest priority pub enum FileKind { - /// A configuration file has the highest priority. It's usually `postgrestools.jsonc` + /// A configuration file has the highest priority. It's usually `postgres-language-server.jsonc` /// /// Other third-party configuration files might be added in the future Config, @@ -173,10 +173,10 @@ impl PgTPath { } /// The priority of the file. - /// - `postgrestools.jsonc` has the highest priority + /// - `postgres-language-server.jsonc` has the highest priority /// - Other files are considered as files to handle fn priority(file_name: &OsStr) -> FileKinds { - if file_name == ConfigName::pgt_jsonc() { + if ConfigName::file_names().iter().any(|f| *f == file_name) { FileKind::Config.into() } else { FileKind::Handleable.into() diff --git a/crates/pgt_lsp/src/server.rs b/crates/pgt_lsp/src/server.rs index 76d9bd9a6..a95911cea 100644 --- a/crates/pgt_lsp/src/server.rs +++ b/crates/pgt_lsp/src/server.rs @@ -69,18 +69,23 @@ impl LSPServer { "pgt_did_change_workspace_settings", "workspace/didChangeWatchedFiles", match self.session.base_path() { - Some(base_path) => CapabilityStatus::Enable(Some(json!( - DidChangeWatchedFilesRegistrationOptions { - watchers: vec![FileSystemWatcher { + Some(base_path) => { + let watchers = ConfigName::file_names() + .iter() + .map(|config_name| FileSystemWatcher { glob_pattern: GlobPattern::String(format!( "{}/{}", base_path.display(), - ConfigName::pgt_jsonc() + config_name )), kind: Some(WatchKind::all()), - },], - } - ))), + }) + .collect(); + + CapabilityStatus::Enable(Some(json!( + DidChangeWatchedFilesRegistrationOptions { watchers } + ))) + } _ => CapabilityStatus::Disable, }, ); @@ -134,10 +139,7 @@ impl LanguageServer for LSPServer { async fn initialized(&self, params: InitializedParams) { let _ = params; - info!( - "Attempting to load the configuration from '{}' file", - ConfigName::pgt_jsonc() - ); + info!("Attempting to load the configuration",); futures::join!(self.session.load_workspace_settings(None)); diff --git a/crates/pgt_lsp/src/session.rs b/crates/pgt_lsp/src/session.rs index ede0469f2..b7188d1ab 100644 --- a/crates/pgt_lsp/src/session.rs +++ b/crates/pgt_lsp/src/session.rs @@ -9,7 +9,7 @@ use futures::stream::FuturesUnordered; use pgt_analyse::RuleCategoriesBuilder; use pgt_configuration::{ConfigurationPathHint, PartialConfiguration}; use pgt_diagnostics::{DiagnosticExt, Error}; -use pgt_fs::{FileSystem, PgTPath}; +use pgt_fs::{ConfigName, FileSystem, PgTPath}; use pgt_workspace::PartialConfigurationExt; use pgt_workspace::Workspace; use pgt_workspace::configuration::{LoadedConfiguration, load_configuration}; @@ -64,6 +64,9 @@ pub(crate) struct Session { /// to update the diagnostics notified_broken_configuration: AtomicBool, + /// A flag to notify a message to the user when they are using the deprecated config filename + notified_deprecated_config: AtomicBool, + /// File system to read files inside the workspace pub(crate) fs: DynRef<'static, dyn FileSystem>, @@ -165,6 +168,7 @@ impl Session { cancellation, config_path: None, notified_broken_configuration: AtomicBool::new(false), + notified_deprecated_config: AtomicBool::new(false), } } @@ -398,7 +402,7 @@ impl Session { .map(|params| ¶ms.client_capabilities) } - /// This function attempts to read the `postgrestools.jsonc` configuration file from + /// This function attempts to read the `postgres-language-server.jsonc` configuration file from /// the root URI and update the workspace settings accordingly #[tracing::instrument(level = "trace", skip(self))] pub(crate) async fn load_workspace_settings(&self, extra_config: Option) { @@ -413,7 +417,10 @@ impl Session { info!("Detected workspace folder."); self.set_configuration_status(ConfigurationStatus::Loading); for folder in folders { - info!("Attempt to load the configuration file in {:?}", folder.uri); + info!( + "Attempt to load the configuration file in {:?}", + folder.uri.to_string() + ); let base_path = folder.uri.to_file_path(); match base_path { Ok(base_path) => { @@ -455,9 +462,37 @@ impl Session { let LoadedConfiguration { configuration: mut fs_configuration, directory_path: configuration_path, + file_path: configuration_file_path, .. } = loaded_configuration; - info!("Configuration loaded successfully from disk."); + + info!( + "Configuration loaded successfully from disk at {}", + configuration_file_path + .as_ref() + .map_or("".to_string(), |p| p.display().to_string()) + ); + + // Check if using deprecated config filename and notify user (once) + if !self.notified_deprecated_config.load(Ordering::Relaxed) { + if let Some(config_path) = &configuration_file_path { + if let Some(file_name) = config_path.file_name().and_then(|n| n.to_str()) { + if ConfigName::is_deprecated(file_name) { + self.client + .show_message( + MessageType::WARNING, + "You are using the deprecated config filename 'postgrestools.jsonc'. \ + Please rename it to 'postgres-language-server.jsonc'. \ + Support for the old filename will be removed in a future version." + ) + .await; + self.notified_deprecated_config + .store(true, Ordering::Relaxed); + } + } + } + } + info!("Update workspace settings."); let fs = &self.fs; diff --git a/crates/pgt_lsp/tests/server.rs b/crates/pgt_lsp/tests/server.rs index 1f972395b..ac2e8f936 100644 --- a/crates/pgt_lsp/tests/server.rs +++ b/crates/pgt_lsp/tests/server.rs @@ -427,7 +427,9 @@ async fn test_database_connection(test_db: PgPool) -> Result<()> { ..Default::default() }); fs.insert( - url!("postgrestools.jsonc").to_file_path().unwrap(), + url!("postgres-language-server.jsonc") + .to_file_path() + .unwrap(), serde_json::to_string_pretty(&conf).unwrap(), ); @@ -538,7 +540,9 @@ async fn test_completions(test_db: PgPool) -> Result<()> { ..Default::default() }); fs.insert( - url!("postgrestools.jsonc").to_file_path().unwrap(), + url!("postgres-language-server.jsonc") + .to_file_path() + .unwrap(), serde_json::to_string_pretty(&conf).unwrap(), ); @@ -638,7 +642,9 @@ async fn test_issue_271(test_db: PgPool) -> Result<()> { ..Default::default() }); fs.insert( - url!("postgrestools.jsonc").to_file_path().unwrap(), + url!("postgres-language-server.jsonc") + .to_file_path() + .unwrap(), serde_json::to_string_pretty(&conf).unwrap(), ); @@ -830,7 +836,9 @@ async fn test_execute_statement(test_db: PgPool) -> Result<()> { }); fs.insert( - url!("postgrestools.jsonc").to_file_path().unwrap(), + url!("postgres-language-server.jsonc") + .to_file_path() + .unwrap(), serde_json::to_string_pretty(&conf).unwrap(), ); @@ -977,7 +985,9 @@ async fn test_issue_281(test_db: PgPool) -> Result<()> { ..Default::default() }); fs.insert( - url!("postgrestools.jsonc").to_file_path().unwrap(), + url!("postgres-language-server.jsonc") + .to_file_path() + .unwrap(), serde_json::to_string_pretty(&conf).unwrap(), ); @@ -1060,7 +1070,9 @@ async fn test_issue_303(test_db: PgPool) -> Result<()> { ..Default::default() }); fs.insert( - url!("postgrestools.jsonc").to_file_path().unwrap(), + url!("postgres-language-server.jsonc") + .to_file_path() + .unwrap(), serde_json::to_string_pretty(&conf).unwrap(), ); @@ -1192,7 +1204,9 @@ async fn multiple_projects(test_db: PgPool) -> Result<()> { ..Default::default() }); fs.insert( - url!("test_one/postgrestools.jsonc").to_file_path().unwrap(), + url!("test_one/postgres-language-server.jsonc") + .to_file_path() + .unwrap(), serde_json::to_string_pretty(&conf_with_db).unwrap(), ); @@ -1206,7 +1220,9 @@ async fn multiple_projects(test_db: PgPool) -> Result<()> { ..Default::default() }); fs.insert( - url!("test_two/postgrestools.jsonc").to_file_path().unwrap(), + url!("test_two/postgres-language-server.jsonc") + .to_file_path() + .unwrap(), serde_json::to_string_pretty(&conf_without_db).unwrap(), ); @@ -1357,14 +1373,16 @@ async fn extends_config(test_db: PgPool) -> Result<()> { // shared config with default db connection let conf_with_db = PartialConfiguration::init(); fs.insert( - url!("postgrestools.jsonc").to_file_path().unwrap(), + url!("postgres-language-server.jsonc") + .to_file_path() + .unwrap(), serde_json::to_string_pretty(&conf_with_db).unwrap(), ); let relative_path = if cfg!(windows) { - "..\\postgrestools.jsonc" + "..\\postgres-language-server.jsonc" } else { - "../postgrestools.jsonc" + "../postgres-language-server.jsonc" }; // test_one extends the shared config but sets our test db @@ -1385,7 +1403,9 @@ async fn extends_config(test_db: PgPool) -> Result<()> { }); fs.insert( - url!("test_one/postgrestools.jsonc").to_file_path().unwrap(), + url!("test_one/postgres-language-server.jsonc") + .to_file_path() + .unwrap(), serde_json::to_string_pretty(&conf_with_db).unwrap(), ); @@ -1396,7 +1416,9 @@ async fn extends_config(test_db: PgPool) -> Result<()> { ..Default::default() }); fs.insert( - url!("test_two/postgrestools.jsonc").to_file_path().unwrap(), + url!("test_two/postgres-language-server.jsonc") + .to_file_path() + .unwrap(), serde_json::to_string_pretty(&conf_without_db).unwrap(), ); @@ -1585,7 +1607,9 @@ async fn test_multiple_content_changes_single_request(test_db: PgPool) -> Result ..Default::default() }); fs.insert( - url!("postgrestools.jsonc").to_file_path().unwrap(), + url!("postgres-language-server.jsonc") + .to_file_path() + .unwrap(), serde_json::to_string_pretty(&conf).unwrap(), ); @@ -1712,7 +1736,9 @@ async fn test_plpgsql(test_db: PgPool) -> Result<()> { ..Default::default() }); fs.insert( - url!("postgrestools.jsonc").to_file_path().unwrap(), + url!("postgres-language-server.jsonc") + .to_file_path() + .unwrap(), serde_json::to_string_pretty(&conf).unwrap(), ); diff --git a/crates/pgt_workspace/src/configuration.rs b/crates/pgt_workspace/src/configuration.rs index 8b9556cc4..6bd11078c 100644 --- a/crates/pgt_workspace/src/configuration.rs +++ b/crates/pgt_workspace/src/configuration.rs @@ -131,7 +131,7 @@ fn load_config( ConfigurationPathHint::None => file_system.working_directory().unwrap_or_default(), }; - // We first search for `postgrestools.jsonc` files + // We first search for `postgres-language-server.jsonc` files if let Some(auto_search_result) = file_system.auto_search( &configuration_directory, ConfigName::file_names().as_slice(), @@ -164,7 +164,7 @@ pub fn create_config( fs: &mut DynRef, configuration: &mut PartialConfiguration, ) -> Result<(), WorkspaceError> { - let path = PathBuf::from(ConfigName::pgt_jsonc()); + let path = PathBuf::from(ConfigName::pgls_jsonc()); if fs.path_exists(&path) { return Err(ConfigurationDiagnostic::new_already_exists().into()); @@ -180,11 +180,24 @@ pub fn create_config( } })?; - // we now check if postgrestools is installed inside `node_modules` and if so, we use the schema from there - let node_schema_path = Path::new("./node_modules/@postgrestools/postgrestools/schema.json"); - let options = OpenOptions::default().read(true); - if fs.open_with_options(node_schema_path, options).is_ok() { - configuration.schema = node_schema_path.to_str().map(String::from); + // we now check if postgres-language-server or postgrestools is installed inside `node_modules` and if so, we use the schema from there + let postgrestools_node_schema_path = + Path::new("./node_modules/@postgrestools/postgrestools/schema.json"); + let pgls_node_schema_path = + Path::new("./node_modules/@postgres-language-server/cli/schema.json"); + if fs + .open_with_options(pgls_node_schema_path, OpenOptions::default().read(true)) + .is_ok() + { + configuration.schema = pgls_node_schema_path.to_str().map(String::from); + } else if fs + .open_with_options( + postgrestools_node_schema_path, + OpenOptions::default().read(true), + ) + .is_ok() + { + configuration.schema = postgrestools_node_schema_path.to_str().map(String::from); } else if VERSION == "0.0.0" { // VERSION is 0.0.0 if it has not been explicitly set (e.g local dev, as fallback) configuration.schema = Some(format!("{}/latest/schema.json", PGT_WEBSITE)); @@ -521,20 +534,23 @@ mod tests { #[test] fn test_normalize_path_windows_drive() { if cfg!(windows) { - let path = Path::new(r"z:\workspace\test_one\..\postgrestools.jsonc"); + let path = Path::new(r"z:\workspace\test_one\..\postgres-language-server.jsonc"); let normalized = normalize_path(path); assert_eq!( normalized, - PathBuf::from(r"z:\workspace\postgrestools.jsonc") + PathBuf::from(r"z:\workspace\postgres-language-server.jsonc") ); } } #[test] fn test_normalize_path_relative() { - let path = Path::new("workspace/test_one/../postgrestools.jsonc"); + let path = Path::new("workspace/test_one/../postgres-language-server.jsonc"); let normalized = normalize_path(path); - assert_eq!(normalized, PathBuf::from("workspace/postgrestools.jsonc")); + assert_eq!( + normalized, + PathBuf::from("workspace/postgres-language-server.jsonc") + ); } #[test] diff --git a/crates/pgt_workspace/src/workspace/server.rs b/crates/pgt_workspace/src/workspace/server.rs index 12b8310e4..c88f4509e 100644 --- a/crates/pgt_workspace/src/workspace/server.rs +++ b/crates/pgt_workspace/src/workspace/server.rs @@ -162,11 +162,24 @@ impl WorkspaceServer { /// Check whether a file is ignored in the top-level config `files.ignore`/`files.include` fn is_ignored(&self, path: &Path) -> bool { - let file_name = path.file_name().and_then(|s| s.to_str()); - // Never ignore Postgres Tools's config file regardless `include`/`ignore` - (file_name != Some(ConfigName::pgt_jsonc())) && - // Apply top-level `include`/`ignore - (self.is_ignored_by_top_level_config(path) || self.is_ignored_by_migration_config(path)) + // Never ignore config files regardless `include`/`ignore` + if self.is_config_file(path) { + return false; + } + + // Apply top-level `include`/`ignore` + self.is_ignored_by_top_level_config(path) || self.is_ignored_by_migration_config(path) + } + + /// Check whether a file is a configuration file + fn is_config_file(&self, path: &Path) -> bool { + path.file_name() + .and_then(|s| s.to_str()) + .is_some_and(|file_name| { + ConfigName::file_names() + .iter() + .any(|config_name| file_name == *config_name) + }) } /// Check whether a file is ignored in the top-level config `files.ignore`/`files.include` diff --git a/docs/configuration.md b/docs/configuration.md index 9661d2a87..16a9c137b 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -2,7 +2,7 @@ This guide will help you to understand how to configure the Postgres Language Server. It explains the structure of the configuration file and how the configuration is resolved. -The Postgres Language Server allows you to customize its behavior using CLI options or a configuration file named `postgrestools.jsonc`. We recommend that you create a configuration file for each project. This ensures that each team member has the same configuration in the CLI and in any editor that allows Biome integration. Many of the options available in a configuration file are also available in the CLI. +The Postgres Language Server allows you to customize its behavior using CLI options or a configuration file named `postgres-language-server.jsonc`. We recommend that you create a configuration file for each project. This ensures that each team member has the same configuration in the CLI and in any editor that allows Biome integration. Many of the options available in a configuration file are also available in the CLI. ## Configuration file structure diff --git a/docs/features/linting.md b/docs/features/linting.md index 814ce558e..3e27fffd9 100644 --- a/docs/features/linting.md +++ b/docs/features/linting.md @@ -10,7 +10,7 @@ See the [Rules Reference](../reference/rules.md) for the complete list of availa ## Configuration -Configure linting behavior in your `postgrestools.jsonc`: +Configure linting behavior in your `postgres-language-server.jsonc`: ```json { diff --git a/docs/getting_started.md b/docs/getting_started.md index 8cbe655bd..21fefb778 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -4,13 +4,13 @@ The Postgres Language Server can be installed as a development dependency of you ## Configuration -We recommend creating a `postgrestools.jsonc` configuration file for each project. This eliminates repetitive CLI options and ensures that consistent configuration in your editor. Some options are only available from a configuration file. This step is optional though: if you are happy with the defaults, you don’t need a configuration file. To create the `postgrestools.jsonc` file, run the `init` command in the root folder of your project: +We recommend creating a `postgres-language-server.jsonc` configuration file for each project. This eliminates repetitive CLI options and ensures that consistent configuration in your editor. Some options are only available from a configuration file. This step is optional though: if you are happy with the defaults, you don’t need a configuration file. To create the `postgres-language-server.jsonc` file, run the `init` command in the root folder of your project: ```sh postgrestools init ``` -You’ll now have a `postgrestools.jsonc` file in your directory: +You’ll now have a `postgres-language-server.jsonc` file in your directory: [//]: # "BEGIN DEFAULT_CONFIGURATION" @@ -65,15 +65,15 @@ postgrestools check myfile.sql postgrestools check supabase/migrations ``` -Run `postgrestools --help` for all options. The CLI options take precedence over what is loaded from `postgrestools.jsonc`. +Run `postgrestools --help` for all options. The CLI options take precedence over what is loaded from `postgres-language-server.jsonc`. ### Editor Integrations The Postgres Language Server is available as an extension in your favorite editors. -- VSCode: The language server is available on the [VSCode Marketplace](https://marketplace.visualstudio.com/items?itemName=Supabase.postgrestools). It's published from [this repo](https://github.com/supabase-community/postgrestools-vscode). -- Neovim: You will have to install `nvim-lspconfig`, and follow the [instructions](https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md#postgres_lsp). -- Emacs: The language client is available through [lsp-mode](https://github.com/emacs-lsp/lsp-mode). For more details, refer to their [manual page](https://emacs-lsp.github.io/lsp-mode/page/lsp-postgres/). +- VSCode: The language server is available on the [VSCode Marketplace](https://marketplace.visualstudio.com/items?itemName=Supabase.postgrestools). It's published from [this repo](https://github.com/supabase-community/postgrestools-vscode). +- Neovim: You will have to install `nvim-lspconfig`, and follow the [instructions](https://github.com/neovim/nvim-lspconfig/blob/master/doc/configs.md#postgres_lsp). +- Emacs: The language client is available through [lsp-mode](https://github.com/emacs-lsp/lsp-mode). For more details, refer to their [manual page](https://emacs-lsp.github.io/lsp-mode/page/lsp-postgres/). - Zed: The language server is available as an Extension. It's published from [this repo](https://github.com/LoamStudios/zed-postgres-language-server). ### Continuous Integration diff --git a/docs/guides/checking_migrations.md b/docs/guides/checking_migrations.md index 6f552f6ed..07b651bfe 100644 --- a/docs/guides/checking_migrations.md +++ b/docs/guides/checking_migrations.md @@ -8,7 +8,7 @@ To run it, simply point at your migrations directory. postgrestools check supabase/migrations ``` -When you are setting it up in an existing project, you might want to ignore all migrations that are already applied. To do so, add `migrationsDir` and `after` to your `postgrestools.jsonc` file +When you are setting it up in an existing project, you might want to ignore all migrations that are already applied. To do so, add `migrationsDir` and `after` to your `postgres-language-server.jsonc` file ```json @@ -28,5 +28,5 @@ postgrestools check supabase/migrations --migrations-dir="supabase/migrations" - This will only check migrations after the specified timestamp. -For pre-commit hooks and when working locally, use `--staged` to only lint files that have been staged. In CI environments, you most likely want to use `--changed` to only lint files that have been changed compared to your `vcs.default_branch` configuration. If `default_branch` is not set in your `postgrestools.jsonc`, use `--since=REF` to specify the base branch to compare against. +For pre-commit hooks and when working locally, use `--staged` to only lint files that have been staged. In CI environments, you most likely want to use `--changed` to only lint files that have been changed compared to your `vcs.default_branch` configuration. If `default_branch` is not set in your `postgres-language-server.jsonc`, use `--since=REF` to specify the base branch to compare against. diff --git a/docs/guides/configure_database.md b/docs/guides/configure_database.md index ae4d6d0c2..da4b69d2d 100644 --- a/docs/guides/configure_database.md +++ b/docs/guides/configure_database.md @@ -13,7 +13,7 @@ The language server requires a database connection for schema-dependent features ## Configuration -Configure database connection details in your `postgrestools.jsonc` file: +Configure database connection details in your `postgres-language-server.jsonc` file: ```json { diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 81db5e1e5..d2e8bdb5a 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -4,14 +4,14 @@ # Command summary -- [`postgrestools`↴](#postgrestools) -- [`postgrestools version`↴](#postgrestools-version) -- [`postgrestools check`↴](#postgrestools-check) -- [`postgrestools start`↴](#postgrestools-start) -- [`postgrestools stop`↴](#postgrestools-stop) -- [`postgrestools init`↴](#postgrestools-init) -- [`postgrestools lsp-proxy`↴](#postgrestools-lsp-proxy) -- [`postgrestools clean`↴](#postgrestools-clean) +- [`postgrestools`↴](#postgrestools) +- [`postgrestools version`↴](#postgrestools-version) +- [`postgrestools check`↴](#postgrestools-check) +- [`postgrestools start`↴](#postgrestools-start) +- [`postgrestools stop`↴](#postgrestools-stop) +- [`postgrestools init`↴](#postgrestools-init) +- [`postgrestools lsp-proxy`↴](#postgrestools-lsp-proxy) +- [`postgrestools clean`↴](#postgrestools-clean) ## postgrestools @@ -21,26 +21,26 @@ PostgresTools official CLI. Use it to check the health of your project or run it **Available options:** -- **`-h`**, **`--help`** — +- **`-h`**, **`--help`** — Prints help information -- **`-V`**, **`--version`** — +- **`-V`**, **`--version`** — Prints version information **Available commands:** -- **`version`** — +- **`version`** — Shows the version information and quit. -- **`check`** — +- **`check`** — Runs everything to the requested files. -- **`start`** — +- **`start`** — Starts the daemon server process. -- **`stop`** — +- **`stop`** — Stops the daemon server process. -- **`init`** — +- **`init`** — Bootstraps a new project. Creates a configuration file with some defaults. -- **`lsp-proxy`** — +- **`lsp-proxy`** — Acts as a server for the Language Server Protocol over stdin/stdout. -- **`clean`** — +- **`clean`** — Cleans the logs emitted by the daemon. ## postgrestools version @@ -51,44 +51,44 @@ Shows the version information and quit. **Global options applied to all commands** -- **` --colors`**=_``_ — +- **` --colors`**=_``_ — Set the formatting mode for markup: "off" prints everything as plain text, "force" forces the formatting of markup using ANSI even if the console output is determined to be incompatible -- **` --use-server`** — +- **` --use-server`** — Connect to a running instance of the daemon server. -- **` --skip-db`** — +- **` --skip-db`** — Skip connecting to the database and only run checks that don't require a database connection. -- **` --verbose`** — +- **` --verbose`** — Print additional diagnostics, and some diagnostics show more information. Also, print out what files were processed and which ones were modified. -- **` --config-path`**=_`PATH`_ — +- **` --config-path`**=_`PATH`_ — Set the file path to the configuration file, or the directory path to find `postgrestools.jsonc`. If used, it disables the default configuration file resolution. -- **` --max-diagnostics`**=_`>`_ — +- **` --max-diagnostics`**=_`>`_ — Cap the amount of diagnostics displayed. When `none` is provided, the limit is lifted. [default: 20] -- **` --skip-errors`** — +- **` --skip-errors`** — Skip over files containing syntax errors instead of emitting an error diagnostic. -- **` --no-errors-on-unmatched`** — +- **` --no-errors-on-unmatched`** — Silence errors that would be emitted in case no files were processed during the execution of the command. -- **` --error-on-warnings`** — +- **` --error-on-warnings`** — Tell Postgres Tools to exit with an error code if some diagnostics emit warnings. -- **` --reporter`**=_``_ — +- **` --reporter`**=_``_ — Allows to change how diagnostics and summary are reported. -- **` --log-level`**=_``_ — +- **` --log-level`**=_``_ — The level of logging. In order, from the most verbose to the least verbose: debug, info, warn, error. The value `none` won't show any logging. [default: none] -- **` --log-kind`**=_``_ — +- **` --log-kind`**=_``_ — How the log should look like. [default: pretty] -- **` --diagnostic-level`**=_``_ — +- **` --diagnostic-level`**=_``_ — The level of diagnostics to show. In order, from the lowest to the most important: info, warn, error. Passing `--diagnostic-level=error` will cause Postgres Tools to print only diagnostics that contain only errors. [default: info] **Available options:** -- **`-h`**, **`--help`** — +- **`-h`**, **`--help`** — Prints help information ## postgrestools check @@ -99,97 +99,97 @@ Runs everything to the requested files. **The configuration that is contained inside the configuration file.** -- **` --vcs-enabled`**=_``_ — +- **` --vcs-enabled`**=_``_ — Whether we should integrate itself with the VCS client -- **` --vcs-client-kind`**=_``_ — +- **` --vcs-client-kind`**=_``_ — The kind of client. -- **` --vcs-use-ignore-file`**=_``_ — +- **` --vcs-use-ignore-file`**=_``_ — Whether we should use the VCS ignore file. When [true], we will ignore the files specified in the ignore file. -- **` --vcs-root`**=_`PATH`_ — +- **` --vcs-root`**=_`PATH`_ — The folder where we should check for VCS files. By default, we will use the same folder where `postgrestools.jsonc` was found. If we can't find the configuration, it will attempt to use the current working directory. If no current working directory can't be found, we won't use the VCS integration, and a diagnostic will be emitted -- **` --vcs-default-branch`**=_`BRANCH`_ — +- **` --vcs-default-branch`**=_`BRANCH`_ — The main branch of the project -- **` --files-max-size`**=_`NUMBER`_ — +- **` --files-max-size`**=_`NUMBER`_ — The maximum allowed size for source code files in bytes. Files above this limit will be ignored for performance reasons. Defaults to 1 MiB -- **` --migrations-dir`**=_`ARG`_ — +- **` --migrations-dir`**=_`ARG`_ — The directory where the migration files are stored -- **` --after`**=_`ARG`_ — +- **` --after`**=_`ARG`_ — Ignore any migrations before this timestamp -- **` --host`**=_`ARG`_ — +- **` --host`**=_`ARG`_ — The host of the database. -- **` --port`**=_`ARG`_ — +- **` --port`**=_`ARG`_ — The port of the database. -- **` --username`**=_`ARG`_ — +- **` --username`**=_`ARG`_ — The username to connect to the database. -- **` --password`**=_`ARG`_ — +- **` --password`**=_`ARG`_ — The password to connect to the database. -- **` --database`**=_`ARG`_ — +- **` --database`**=_`ARG`_ — The name of the database. -- **` --conn_timeout_secs`**=_`ARG`_ — +- **` --conn_timeout_secs`**=_`ARG`_ — The connection timeout in seconds. [default: Some(10)] **Global options applied to all commands** -- **` --colors`**=_``_ — +- **` --colors`**=_``_ — Set the formatting mode for markup: "off" prints everything as plain text, "force" forces the formatting of markup using ANSI even if the console output is determined to be incompatible -- **` --use-server`** — +- **` --use-server`** — Connect to a running instance of the daemon server. -- **` --skip-db`** — +- **` --skip-db`** — Skip connecting to the database and only run checks that don't require a database connection. -- **` --verbose`** — +- **` --verbose`** — Print additional diagnostics, and some diagnostics show more information. Also, print out what files were processed and which ones were modified. -- **` --config-path`**=_`PATH`_ — - Set the file path to the configuration file, or the directory path to find `postgrestools.jsonc`. If used, it disables the default configuration file resolution. -- **` --max-diagnostics`**=_`>`_ — +- **` --config-path`**=_`PATH`_ — + Set the file path to the configuration file, or the directory path to find `postgres-language-server.jsonc`. If used, it disables the default configuration file resolution. +- **` --max-diagnostics`**=_`>`_ — Cap the amount of diagnostics displayed. When `none` is provided, the limit is lifted. [default: 20] -- **` --skip-errors`** — +- **` --skip-errors`** — Skip over files containing syntax errors instead of emitting an error diagnostic. -- **` --no-errors-on-unmatched`** — +- **` --no-errors-on-unmatched`** — Silence errors that would be emitted in case no files were processed during the execution of the command. -- **` --error-on-warnings`** — +- **` --error-on-warnings`** — Tell Postgres Tools to exit with an error code if some diagnostics emit warnings. -- **` --reporter`**=_``_ — +- **` --reporter`**=_``_ — Allows to change how diagnostics and summary are reported. -- **` --log-level`**=_``_ — +- **` --log-level`**=_``_ — The level of logging. In order, from the most verbose to the least verbose: debug, info, warn, error. The value `none` won't show any logging. [default: none] -- **` --log-kind`**=_``_ — +- **` --log-kind`**=_``_ — How the log should look like. [default: pretty] -- **` --diagnostic-level`**=_``_ — +- **` --diagnostic-level`**=_``_ — The level of diagnostics to show. In order, from the lowest to the most important: info, warn, error. Passing `--diagnostic-level=error` will cause Postgres Tools to print only diagnostics that contain only errors. [default: info] **Available positional items:** -- _`PATH`_ — +- _`PATH`_ — Single file, single path or list of paths **Available options:** -- **` --stdin-file-path`**=_`PATH`_ — +- **` --stdin-file-path`**=_`PATH`_ — Use this option when you want to format code piped from `stdin`, and print the output to `stdout`. The file doesn't need to exist on disk, what matters is the extension of the file. Based on the extension, we know how to check the code. Example: `echo 'let a;' | pgt_cli check --stdin-file-path=test.sql` -- **` --staged`** — +- **` --staged`** — When set to true, only the files that have been staged (the ones prepared to be committed) will be linted. This option should be used when working locally. -- **` --changed`** — +- **` --changed`** — When set to true, only the files that have been changed compared to your `defaultBranch` configuration will be linted. This option should be used in CI environments. -- **` --since`**=_`REF`_ — - Use this to specify the base branch to compare against when you're using the --changed flag and the `defaultBranch` is not set in your `postgrestools.jsonc` -- **`-h`**, **`--help`** — +- **` --since`**=_`REF`_ — + Use this to specify the base branch to compare against when you're using the --changed flag and the `defaultBranch` is not set in your `postgres-language-server.jsonc` +- **`-h`**, **`--help`** — Prints help information ## postgrestools start @@ -200,17 +200,17 @@ Starts the daemon server process. **Available options:** -- **` --log-prefix-name`**=_`STRING`_ — +- **` --log-prefix-name`**=_`STRING`_ — Allows to change the prefix applied to the file name of the logs. Uses environment variable **`PGT_LOG_PREFIX_NAME`** [default: server.log] -- **` --log-path`**=_`PATH`_ — +- **` --log-path`**=_`PATH`_ — Allows to change the folder where logs are stored. Uses environment variable **`PGT_LOG_PATH`** -- **` --config-path`**=_`PATH`_ — - Allows to set a custom file path to the configuration file, or a custom directory path to find `postgrestools.jsonc` +- **` --config-path`**=_`PATH`_ — + Allows to set a custom file path to the configuration file, or a custom directory path to find `postgres-language-server.jsonc` Uses environment variable **`PGT_LOG_PREFIX_NAME`** -- **`-h`**, **`--help`** — +- **`-h`**, **`--help`** — Prints help information ## postgrestools stop @@ -221,7 +221,7 @@ Stops the daemon server process. **Available options:** -- **`-h`**, **`--help`** — +- **`-h`**, **`--help`** — Prints help information ## postgrestools init @@ -232,7 +232,7 @@ Bootstraps a new project. Creates a configuration file with some defaults. **Available options:** -- **`-h`**, **`--help`** — +- **`-h`**, **`--help`** — Prints help information ## postgrestools lsp-proxy @@ -243,17 +243,17 @@ Acts as a server for the Language Server Protocol over stdin/stdout. **Available options:** -- **` --log-prefix-name`**=_`STRING`_ — +- **` --log-prefix-name`**=_`STRING`_ — Allows to change the prefix applied to the file name of the logs. Uses environment variable **`PGT_LOG_PREFIX_NAME`** [default: server.log] -- **` --log-path`**=_`PATH`_ — +- **` --log-path`**=_`PATH`_ — Allows to change the folder where logs are stored. Uses environment variable **`PGT_LOG_PATH`** -- **` --config-path`**=_`PATH`_ — - Allows to set a custom file path to the configuration file, or a custom directory path to find `postgrestools.jsonc` +- **` --config-path`**=_`PATH`_ — + Allows to set a custom file path to the configuration file, or a custom directory path to find `postgres-language-server.jsonc` Uses environment variable **`PGT_CONFIG_PATH`** -- **`-h`**, **`--help`** — +- **`-h`**, **`--help`** — Prints help information ## postgrestools clean @@ -264,7 +264,7 @@ Cleans the logs emitted by the daemon. **Available options:** -- **`-h`**, **`--help`** — +- **`-h`**, **`--help`** — Prints help information [//]: # "END CLI_REF" diff --git a/docs/schema.json b/docs/schema.json index 2d40cf9ed..55f1abbfb 100644 --- a/docs/schema.json +++ b/docs/schema.json @@ -754,7 +754,7 @@ ] }, "root": { - "description": "The folder where we should check for VCS files. By default, we will use the same folder where `postgrestools.jsonc` was found.\n\nIf we can't find the configuration, it will attempt to use the current working directory. If no current working directory can't be found, we won't use the VCS integration, and a diagnostic will be emitted", + "description": "The folder where we should check for VCS files. By default, we will use the same folder where `postgres-language-server.jsonc` was found.\n\nIf we can't find the configuration, it will attempt to use the current working directory. If no current working directory can't be found, we won't use the VCS integration, and a diagnostic will be emitted", "type": [ "string", "null" diff --git a/packages/@postgrestools/backend-jsonrpc/src/workspace.ts b/packages/@postgrestools/backend-jsonrpc/src/workspace.ts index 51a4f5663..24ea5d503 100644 --- a/packages/@postgrestools/backend-jsonrpc/src/workspace.ts +++ b/packages/@postgrestools/backend-jsonrpc/src/workspace.ts @@ -122,7 +122,7 @@ export type DiagnosticTags = DiagnosticTag[]; /** * Serializable representation of a [Diagnostic](super::Diagnostic) advice -See the [Visitor] trait for additional documentation on all the supported advice types. +See the [Visitor] trait for additional documentation on all the supported advice types. */ export type Advice = | { log: [LogCategory, MarkupBuf] } @@ -227,7 +227,7 @@ export interface CompletionItem { /** * The text that the editor should fill in. If `None`, the `label` should be used. Tables, for example, might have different completion_texts: -label: "users", description: "Schema: auth", completion_text: "auth.users". +label: "users", description: "Schema: auth", completion_text: "auth.users". */ export interface CompletionText { is_snippet: boolean; @@ -409,9 +409,9 @@ export interface PartialVcsConfiguration { */ enabled?: boolean; /** - * The folder where we should check for VCS files. By default, we will use the same folder where `postgrestools.jsonc` was found. + * The folder where we should check for VCS files. By default, we will use the same folder where `postgres-language-server.jsonc` was found. -If we can't find the configuration, it will attempt to use the current working directory. If no current working directory can't be found, we won't use the VCS integration, and a diagnostic will be emitted +If we can't find the configuration, it will attempt to use the current working directory. If no current working directory can't be found, we won't use the VCS integration, and a diagnostic will be emitted */ root?: string; /**