From c2b44cf31a9357ffe43b4d35194717b2bdb88056 Mon Sep 17 00:00:00 2001 From: psteinroe Date: Wed, 1 Oct 2025 13:02:31 -0700 Subject: [PATCH] chore: support both names --- .github/workflows/release.yml | 2 + CLAUDE.md | 16 ++-- crates/pgt_analyse/src/options.rs | 2 +- crates/pgt_analyser/CONTRIBUTING.md | 6 +- crates/pgt_cli/src/cli_options.rs | 4 +- crates/pgt_cli/src/commands/clean.rs | 8 +- crates/pgt_cli/src/commands/daemon.rs | 8 +- crates/pgt_cli/src/commands/init.rs | 4 +- crates/pgt_cli/src/commands/mod.rs | 37 +++++++-- crates/pgt_cli/src/diagnostics.rs | 6 +- crates/pgt_cli/src/lib.rs | 2 +- crates/pgt_cli/src/reporter/junit.rs | 2 +- crates/pgt_cli/tests/assert_cmd.rs | 2 +- crates/pgt_configuration/src/lib.rs | 4 +- crates/pgt_configuration/src/vcs.rs | 2 +- crates/pgt_flags/src/lib.rs | 75 +++++++++++++++---- crates/pgt_fs/src/fs.rs | 15 +++- crates/pgt_fs/src/path.rs | 6 +- crates/pgt_lsp/src/server.rs | 30 +++++--- crates/pgt_lsp/src/session.rs | 2 +- crates/pgt_lsp/tests/server.rs | 58 ++++++++++---- crates/pgt_workspace/src/configuration.rs | 27 +++++-- crates/pgt_workspace/src/workspace/server.rs | 2 +- docs/codegen/src/cli_doc.rs | 2 +- docs/codegen/src/env_variables.rs | 2 +- docs/configuration.md | 4 +- docs/features/linting.md | 8 +- docs/getting_started.md | 20 ++--- docs/guides/checking_migrations.md | 8 +- docs/guides/configure_database.md | 16 ++-- docs/guides/continuous_integration.md | 6 +- docs/guides/ide_setup.md | 6 +- docs/guides/vcs_integration.md | 6 +- docs/manual_installation.md | 36 ++++----- docs/reference/cli.md | 62 +++++++-------- docs/schema.json | 2 +- justfile | 6 +- package.json | 6 +- .../backend-jsonrpc/src/workspace.ts | 6 +- pyproject.toml | 2 +- xtask/codegen/src/generate_bindings.rs | 2 +- 41 files changed, 323 insertions(+), 197 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9b696c30b..c9b44ed25 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -89,6 +89,8 @@ jobs: # Strip all debug symbols from the resulting binaries RUSTFLAGS: "-C strip=symbols -C codegen-units=1" # Inline the version in the CLI binary + PGLS_VERSION: ${{ needs.extract_version.outputs.version }} + # Inline the version in the CLI binary (deprecated) PGT_VERSION: ${{ needs.extract_version.outputs.version }} # windows is a special snowflake too, it saves binaries as .exe diff --git a/CLAUDE.md b/CLAUDE.md index 057163a94..b828fe366 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -62,11 +62,11 @@ just new-crate ``` ### CLI Usage -The main CLI binary is `postgrestools`: +The main CLI binary is `postgres-language-server`: ```bash cargo run -p pgt_cli -- check file.sql # or after building: -./target/release/postgrestools check file.sql +./target/release/postgres-language-server check file.sql ``` ## Architecture @@ -76,7 +76,7 @@ The project uses a modular Rust workspace with crates prefixed with `pgt_`: **Core Infrastructure:** - `pgt_workspace` - Main API and workspace management -- `pgt_lsp` - Language Server Protocol implementation +- `pgt_lsp` - Language Server Protocol implementation - `pgt_cli` - Command-line interface - `pgt_fs` - Virtual file system abstraction - `pgt_configuration` - Configuration management @@ -103,8 +103,8 @@ The project uses a modular Rust workspace with crates prefixed with `pgt_`: ### TypeScript Packages Located in `packages/` and `editors/`: - VSCode extension in `editors/code/` -- Backend JSON-RPC bridge in `packages/@postgrestools/backend-jsonrpc/` -- Main TypeScript package in `packages/@postgrestools/postgrestools/` +- Backend JSON-RPC bridge in `packages/@postgres-language-server/backend-jsonrpc/` +- Main TypeScript package in `packages/@postgres-language-server/postgres-language-server/` ### Database Integration The server connects to a Postgres database to build an in-memory schema cache containing tables, columns, functions, and type information. This enables accurate autocompletion and type checking. @@ -132,7 +132,7 @@ cargo insta review ### Rust Configuration - `Cargo.toml` - Workspace definition with all crate dependencies -- `rust-toolchain.toml` - Rust version specification +- `rust-toolchain.toml` - Rust version specification - `rustfmt.toml` - Code formatting configuration - `clippy.toml` - Clippy linting configuration @@ -150,6 +150,6 @@ Many parser structures are generated from PostgreSQL's protobuf definitions usin ### Database Schema The `pgt_schema_cache` crate contains SQL queries in `src/queries/` that introspect the database schema to build the in-memory cache. -### Multi-Platform Support +### Multi-Platform Support The project includes platform-specific allocators and build configurations for Windows, macOS, and Linux. -- Seeing the Treesitter tree for an SQL query can be helpful to debug and implement features. To do this, create a file with an SQL query, and run `just tree-print `. \ No newline at end of file +- Seeing the Treesitter tree for an SQL query can be helpful to debug and implement features. To do this, create a file with an SQL query, and run `just tree-print `. 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..c9b8fe6a8 100644 --- a/crates/pgt_cli/src/cli_options.rs +++ b/crates/pgt_cli/src/cli_options.rs @@ -22,7 +22,8 @@ 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, @@ -58,6 +59,7 @@ pub struct CliOptions { #[bpaf( env("PGT_LOG_LEVEL"), + env("PGLS_LOG_LEVEL"), long("log-level"), argument("none|debug|info|warn|error"), fallback(LoggingLevel::default()), diff --git a/crates/pgt_cli/src/commands/clean.rs b/crates/pgt_cli/src/commands/clean.rs index e401f3077..da3da8d2e 100644 --- a/crates/pgt_cli/src/commands/clean.rs +++ b/crates/pgt_cli/src/commands/clean.rs @@ -1,15 +1,15 @@ -use crate::commands::daemon::default_pgt_log_path; +use crate::commands::daemon::default_pgls_log_path; use crate::{CliDiagnostic, CliSession}; -use pgt_flags::pgt_env; +use pgt_flags::pgls_env; use std::fs::{create_dir, remove_dir_all}; use std::path::PathBuf; /// Runs the clean command pub fn clean(_cli_session: CliSession) -> Result<(), CliDiagnostic> { - let logs_path = pgt_env() + let logs_path = pgls_env() .pgt_log_path .value() - .map_or(default_pgt_log_path(), PathBuf::from); + .map_or(default_pgls_log_path(), PathBuf::from); remove_dir_all(logs_path.clone()).and_then(|_| create_dir(logs_path))?; Ok(()) } diff --git a/crates/pgt_cli/src/commands/daemon.rs b/crates/pgt_cli/src/commands/daemon.rs index 988286f46..680906dc6 100644 --- a/crates/pgt_cli/src/commands/daemon.rs +++ b/crates/pgt_cli/src/commands/daemon.rs @@ -233,15 +233,15 @@ fn setup_tracing_subscriber( } } -pub fn default_pgt_log_path() -> PathBuf { - match env::var_os("PGT_LOG_PATH") { +pub fn default_pgls_log_path() -> PathBuf { + match env::var_os("PGLS_LOG_PATH") { Some(directory) => PathBuf::from(directory), - None => pgt_fs::ensure_cache_dir().join("pgt-logs"), + None => pgt_fs::ensure_cache_dir().join("pgls-logs"), } } /// Tracing Filter with two rules: -/// For all crates starting with pgt*, use `PGT_LOG_LEVEL` or CLI option or "info" as default +/// For all crates starting with pgt*, use `PGLS_LOG_LEVEL` or CLI option or "info" as default /// For all other crates, use "info" struct PgtLoggingFilter(LevelFilter); 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..548154f61 100644 --- a/crates/pgt_cli/src/commands/mod.rs +++ b/crates/pgt_cli/src/commands/mod.rs @@ -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, @@ -73,6 +73,7 @@ pub enum PgtCommand { /// Allows to change the prefix applied to the file name of the logs. #[bpaf( env("PGT_LOG_PREFIX_NAME"), + env("PGLS_LOG_PREFIX_NAME"), long("log-prefix-name"), argument("STRING"), hide_usage, @@ -84,6 +85,7 @@ pub enum PgtCommand { /// Allows to change the folder where logs are stored. #[bpaf( env("PGT_LOG_PATH"), + env("PGLS_LOG_PATH"), long("log-path"), argument("PATH"), hide_usage, @@ -91,8 +93,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, }, @@ -110,6 +117,7 @@ pub enum PgtCommand { /// Allows to change the prefix applied to the file name of the logs. #[bpaf( env("PGT_LOG_PREFIX_NAME"), + env("PGLS_LOG_PREFIX_NAME"), long("log-prefix-name"), argument("STRING"), hide_usage, @@ -120,6 +128,7 @@ pub enum PgtCommand { /// Allows to change the folder where logs are stored. #[bpaf( env("PGT_LOG_PATH"), + env("PGLS_LOG_PATH"), long("log-path"), argument("PATH"), hide_usage, @@ -127,8 +136,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)] @@ -144,6 +158,7 @@ pub enum PgtCommand { /// Allows to change the prefix applied to the file name of the logs. #[bpaf( env("PGT_LOG_PREFIX_NAME"), + env("PGLS_LOG_PREFIX_NAME"), long("log-prefix-name"), argument("STRING"), hide_usage, @@ -155,6 +170,7 @@ pub enum PgtCommand { /// Allows to change the folder where logs are stored. #[bpaf( env("PGT_LOG_PATH"), + env("PGLS_LOG_PATH"), long("log-path"), argument("PATH"), hide_usage, @@ -165,6 +181,7 @@ pub enum PgtCommand { /// Allows to change the log level. Default is debug. This will only affect "pgt*" crates. All others are logged with info level. #[bpaf( env("PGT_LOG_LEVEL"), + env("PGLS_LOG_LEVEL"), long("log-level"), argument("trace|debug|info|warn|error|none"), fallback(String::from("debug")) @@ -174,6 +191,7 @@ pub enum PgtCommand { /// Allows to change the logging format kind. Default is hierarchical. #[bpaf( env("PGT_LOG_KIND"), + env("PGLS_LOG_KIND"), long("log-kind"), argument("hierarchical|bunyan"), fallback(String::from("hierarchical")) @@ -183,8 +201,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)] diff --git a/crates/pgt_cli/src/diagnostics.rs b/crates/pgt_cli/src/diagnostics.rs index 20d32113c..318ca37f6 100644 --- a/crates/pgt_cli/src/diagnostics.rs +++ b/crates/pgt_cli/src/diagnostics.rs @@ -11,7 +11,7 @@ fn command_name() -> String { current_exe() .ok() .and_then(|path| Some(path.file_name()?.to_str()?.to_string())) - .unwrap_or_else(|| String::from("postgrestools")) + .unwrap_or_else(|| String::from("postgres-language-server")) } /// A diagnostic that is emitted when running Postgres Tools via CLI. @@ -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_cli/src/lib.rs b/crates/pgt_cli/src/lib.rs index f8a042440..0c1fac275 100644 --- a/crates/pgt_cli/src/lib.rs +++ b/crates/pgt_cli/src/lib.rs @@ -32,7 +32,7 @@ pub use panic::setup_panic_handler; pub use reporter::{DiagnosticsPayload, Reporter, ReporterVisitor, TraversalSummary}; pub use service::{SocketTransport, open_transport}; -pub(crate) const VERSION: &str = match option_env!("PGT_VERSION") { +pub(crate) const VERSION: &str = match option_env!("PGLS_VERSION") { Some(version) => version, None => env!("CARGO_PKG_VERSION"), }; diff --git a/crates/pgt_cli/src/reporter/junit.rs b/crates/pgt_cli/src/reporter/junit.rs index 670bf8d40..d463e34ae 100644 --- a/crates/pgt_cli/src/reporter/junit.rs +++ b/crates/pgt_cli/src/reporter/junit.rs @@ -34,7 +34,7 @@ pub(crate) struct JunitReporterVisitor<'a>(pub(crate) Report, pub(crate) &'a mut impl<'a> JunitReporterVisitor<'a> { pub(crate) fn new(console: &'a mut dyn Console) -> Self { - let report = Report::new("PostgresTools"); + let report = Report::new("Postgres Language Server"); Self(report, console) } } diff --git a/crates/pgt_cli/tests/assert_cmd.rs b/crates/pgt_cli/tests/assert_cmd.rs index a7ddc17fb..0835d43b6 100644 --- a/crates/pgt_cli/tests/assert_cmd.rs +++ b/crates/pgt_cli/tests/assert_cmd.rs @@ -5,7 +5,7 @@ use predicates::prelude::*; #[test] fn test_cli_check_command() { - let mut cmd = Command::cargo_bin("postgrestools").unwrap(); + let mut cmd = Command::cargo_bin("postgres-language-server").unwrap(); let test_sql_path = PathBuf::from("tests/fixtures/test.sql"); diff --git a/crates/pgt_configuration/src/lib.rs b/crates/pgt_configuration/src/lib.rs index 8cac0c3f2..c0a58461b 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", and then it's possible to further customise it //! by language. The language might further options divided by tool. @@ -44,7 +44,7 @@ pub use typecheck::{ }; use vcs::VcsClientKind; -pub const VERSION: &str = match option_env!("PGT_VERSION") { +pub const VERSION: &str = match option_env!("PGLS_VERSION") { Some(version) => version, None => "0.0.0", }; 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_flags/src/lib.rs b/crates/pgt_flags/src/lib.rs index 133df7776..88401c506 100644 --- a/crates/pgt_flags/src/lib.rs +++ b/crates/pgt_flags/src/lib.rs @@ -8,32 +8,47 @@ use std::sync::{LazyLock, OnceLock}; /// Returns `true` if this is an unstable build of Postgres Tools pub fn is_unstable() -> bool { - PGT_VERSION.deref().is_none() + PGLS_VERSION.deref().is_none() } /// The internal version of Postgres Tools. This is usually supplied during the CI build -pub static PGT_VERSION: LazyLock> = LazyLock::new(|| option_env!("PGT_VERSION")); +pub static PGLS_VERSION: LazyLock> = LazyLock::new(|| option_env!("PGLS_VERSION")); -pub struct PgTEnv { - pub pgt_log_path: PgTEnvVariable, - pub pgt_log_prefix: PgTEnvVariable, - pub pgt_config_path: PgTEnvVariable, +pub struct PgLSEnv { + pub pgls_log_path: PgLSEnvVariable, + pub pgt_log_path: PgLSEnvVariable, + pub pgls_log_prefix: PgLSEnvVariable, + pub pgt_log_prefix: PgLSEnvVariable, + pub pgls_config_path: PgLSEnvVariable, + pub pgt_config_path: PgLSEnvVariable, } -pub static PGT_ENV: OnceLock = OnceLock::new(); +pub static PGLS_ENV: OnceLock = OnceLock::new(); -impl PgTEnv { +impl PgLSEnv { fn new() -> Self { Self { - pgt_log_path: PgTEnvVariable::new( + pgls_log_path: PgLSEnvVariable::new( + "PGLS_LOG_PATH", + "The directory where the Daemon logs will be saved.", + ), + pgt_log_path: PgLSEnvVariable::new( "PGT_LOG_PATH", "The directory where the Daemon logs will be saved.", ), - pgt_log_prefix: PgTEnvVariable::new( + pgls_log_prefix: PgLSEnvVariable::new( + "PGLS_LOG_PREFIX_NAME", + "A prefix that's added to the name of the log. Default: `server.log.`", + ), + pgt_log_prefix: PgLSEnvVariable::new( "PGT_LOG_PREFIX_NAME", "A prefix that's added to the name of the log. Default: `server.log.`", ), - pgt_config_path: PgTEnvVariable::new( + pgls_config_path: PgLSEnvVariable::new( + "PGLS_CONFIG_PATH", + "A path to the configuration file", + ), + pgt_config_path: PgLSEnvVariable::new( "PGT_CONFIG_PATH", "A path to the configuration file", ), @@ -41,7 +56,7 @@ impl PgTEnv { } } -pub struct PgTEnvVariable { +pub struct PgLSEnvVariable { /// The name of the environment variable name: &'static str, /// The description of the variable. @@ -49,7 +64,7 @@ pub struct PgTEnvVariable { description: &'static str, } -impl PgTEnvVariable { +impl PgLSEnvVariable { fn new(name: &'static str, description: &'static str) -> Self { Self { name, description } } @@ -70,11 +85,11 @@ impl PgTEnvVariable { } } -pub fn pgt_env() -> &'static PgTEnv { - PGT_ENV.get_or_init(PgTEnv::new) +pub fn pgls_env() -> &'static PgLSEnv { + PGLS_ENV.get_or_init(PgLSEnv::new) } -impl Display for PgTEnv { +impl Display for PgLSEnv { fn fmt(&self, fmt: &mut Formatter) -> std::io::Result<()> { match self.pgt_log_path.value() { None => { @@ -84,6 +99,15 @@ impl Display for PgTEnv { KeyValuePair(self.pgt_log_path.name, markup! {{DebugDisplay(value)}}).fmt(fmt)?; } }; + match self.pgls_log_path.value() { + None => { + KeyValuePair(self.pgls_log_path.name, markup! { "unset" }).fmt(fmt)?; + } + Some(value) => { + KeyValuePair(self.pgls_log_path.name, markup! {{DebugDisplay(value)}}).fmt(fmt)?; + } + }; + match self.pgt_log_prefix.value() { None => { KeyValuePair(self.pgt_log_prefix.name, markup! { "unset" }).fmt(fmt)?; @@ -92,6 +116,15 @@ impl Display for PgTEnv { KeyValuePair(self.pgt_log_prefix.name, markup! {{DebugDisplay(value)}}).fmt(fmt)?; } }; + match self.pgls_log_prefix.value() { + None => { + KeyValuePair(self.pgls_log_prefix.name, markup! { "unset" }).fmt(fmt)?; + } + Some(value) => { + KeyValuePair(self.pgls_log_prefix.name, markup! {{DebugDisplay(value)}}) + .fmt(fmt)?; + } + }; match self.pgt_config_path.value() { None => { @@ -102,6 +135,16 @@ impl Display for PgTEnv { .fmt(fmt)?; } }; + match self.pgls_config_path.value() { + None => { + KeyValuePair(self.pgls_config_path.name, markup! { "unset" }) + .fmt(fmt)?; + } + Some(value) => { + KeyValuePair(self.pgls_config_path.name, markup! {{DebugDisplay(value)}}) + .fmt(fmt)?; + } + }; Ok(()) } diff --git a/crates/pgt_fs/src/fs.rs b/crates/pgt_fs/src/fs.rs index 2bfd2e51b..adc16b9bc 100644 --- a/crates/pgt_fs/src/fs.rs +++ b/crates/pgt_fs/src/fs.rs @@ -19,14 +19,21 @@ mod os; pub struct ConfigName; impl ConfigName { - const PGT_JSONC: [&'static str; 1] = ["postgrestools.jsonc"]; + const CONFIG_FILES: [&'static str; 2] = [ + "postgres-language-server.jsonc", + "postgres-language-server.jsonc", + ]; pub const fn pgt_jsonc() -> &'static str { - Self::PGT_JSONC[0] + Self::CONFIG_FILES[1] } - pub const fn file_names() -> [&'static str; 1] { - Self::PGT_JSONC + pub const fn pgls_jsonc() -> &'static str { + Self::CONFIG_FILES[0] + } + + pub const fn file_names() -> [&'static str; 2] { + Self::CONFIG_FILES } } diff --git a/crates/pgt_fs/src/path.rs b/crates/pgt_fs/src/path.rs index 811bebe59..66ec2f471 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 file_name == ConfigName::pgt_jsonc() || file_name == ConfigName::pgls_jsonc() { 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..d2093dd81 100644 --- a/crates/pgt_lsp/src/server.rs +++ b/crates/pgt_lsp/src/server.rs @@ -71,14 +71,24 @@ impl LSPServer { match self.session.base_path() { Some(base_path) => CapabilityStatus::Enable(Some(json!( DidChangeWatchedFilesRegistrationOptions { - watchers: vec![FileSystemWatcher { - glob_pattern: GlobPattern::String(format!( - "{}/{}", - base_path.display(), - ConfigName::pgt_jsonc() - )), - kind: Some(WatchKind::all()), - },], + watchers: vec![ + FileSystemWatcher { + glob_pattern: GlobPattern::String(format!( + "{}/{}", + base_path.display(), + ConfigName::pgt_jsonc() + )), + kind: Some(WatchKind::all()), + }, + FileSystemWatcher { + glob_pattern: GlobPattern::String(format!( + "{}/{}", + base_path.display(), + ConfigName::pgls_jsonc() + )), + kind: Some(WatchKind::all()), + } + ], } ))), _ => CapabilityStatus::Disable, @@ -135,8 +145,8 @@ impl LanguageServer for LSPServer { let _ = params; info!( - "Attempting to load the configuration from '{}' file", - ConfigName::pgt_jsonc() + "Attempting to load the configuration from {}", + ConfigName::file_names().join(" or ") ); 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..b5441b8b6 100644 --- a/crates/pgt_lsp/src/session.rs +++ b/crates/pgt_lsp/src/session.rs @@ -398,7 +398,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) { diff --git a/crates/pgt_lsp/tests/server.rs b/crates/pgt_lsp/tests/server.rs index 1f972395b..e758ed330 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(), ); @@ -496,7 +498,7 @@ async fn server_shutdown() -> Result<()> { let cancellation = factory.cancellation(); let cancellation = cancellation.notified(); - // this is called when `postgrestools stop` is run by the user + // this is called when `postgres-language-server stop` is run by the user server.pgt_shutdown().await?; cancellation.await; @@ -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 87e77b0ca..7009bbc3c 100644 --- a/crates/pgt_workspace/src/configuration.rs +++ b/crates/pgt_workspace/src/configuration.rs @@ -130,7 +130,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(), @@ -163,7 +163,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,9 +180,17 @@ 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 node_schema_path_depr = + Path::new("./node_modules/@postgrestools/postgrestools/schema.json"); + let node_schema_path = Path::new("./node_modules/@postgres-language-server/cli/schema.json"); + let options_depr = OpenOptions::default().read(true); let options = OpenOptions::default().read(true); - if fs.open_with_options(node_schema_path, options).is_ok() { + if fs + .open_with_options(node_schema_path_depr, options_depr) + .is_ok() + { + configuration.schema = node_schema_path_depr.to_str().map(String::from); + } else if fs.open_with_options(node_schema_path, options).is_ok() { configuration.schema = 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) @@ -520,20 +528,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 b13a34422..4a5b735b3 100644 --- a/crates/pgt_workspace/src/workspace/server.rs +++ b/crates/pgt_workspace/src/workspace/server.rs @@ -164,7 +164,7 @@ impl WorkspaceServer { 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())) && + file_name != Some(ConfigName::pgt_jsonc()) && file_name != Some(ConfigName::pgls_jsonc()) && // Apply top-level `include`/`ignore (self.is_ignored_by_top_level_config(path) || self.is_ignored_by_migration_config(path)) } diff --git a/docs/codegen/src/cli_doc.rs b/docs/codegen/src/cli_doc.rs index b6c4a75b8..246aad36d 100644 --- a/docs/codegen/src/cli_doc.rs +++ b/docs/codegen/src/cli_doc.rs @@ -11,7 +11,7 @@ pub fn generate_cli_doc(docs_dir: &Path) -> anyhow::Result<()> { let new_content = utils::replace_section( &content, "CLI_REF", - &pgt_command().render_markdown("postgrestools"), + &pgt_command().render_markdown("postgres-language-server"), ); fs::write(file_path, &new_content)?; diff --git a/docs/codegen/src/env_variables.rs b/docs/codegen/src/env_variables.rs index fd21ed1b5..e6443e0ac 100644 --- a/docs/codegen/src/env_variables.rs +++ b/docs/codegen/src/env_variables.rs @@ -10,7 +10,7 @@ pub fn generate_env_variables(docs_dir: &Path) -> Result<()> { let mut content = vec![]; - let env = pgt_flags::pgt_env(); + let env = pgt_flags::pgls_env(); writeln!(content, "\n",)?; diff --git a/docs/configuration.md b/docs/configuration.md index 9661d2a87..3d74220a9 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 @@ -54,7 +54,7 @@ You can control the files/folders to process using different strategies, either The first way to control which files and folders are processed is to list them in the CLI. In the following command, we only check `file1.sql` and all the files in the `src` folder, because folders are recursively traversed. ```shell -postgrestools check file1.js src/ +postgres-language-server check file1.js src/ ``` ### Control files via configuration diff --git a/docs/features/linting.md b/docs/features/linting.md index 814ce558e..42ef08dd8 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 { @@ -54,13 +54,13 @@ The linter can also be used via the CLI for CI integration: ```bash # Lint specific files -postgrestools check migrations/ +postgres-language-server check migrations/ # With specific rules -postgrestools check migrations/ --only safety/banDropColumn +postgres-language-server check migrations/ --only safety/banDropColumn # Skip certain rules -postgrestools check migrations/ --skip safety/banDropTable +postgres-language-server check migrations/ --skip safety/banDropTable ``` See the [CLI Reference](../reference/cli.md) for more options, and check the guide on [linting migrations]('../guides/checking_migrations.md'). diff --git a/docs/getting_started.md b/docs/getting_started.md index 8cbe655bd..92405938f 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 +postgres-language-server 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" @@ -45,9 +45,9 @@ You’ll now have a `postgrestools.jsonc` file in your directory: [//]: # "END DEFAULT_CONFIGURATION" -Make sure to edit the database connection settings to connect to your local development database. To see all options, run `postgrestools --help`. +Make sure to edit the database connection settings to connect to your local development database. To see all options, run `postgres-language-server --help`. -You can use your current `postgrestools` version instead of "latest" in the `$schema` URL, e.g. `https://pgtools.dev/0.8.1/schema.json`. +You can use your current `postgres-language-server` version instead of "latest" in the `$schema` URL, e.g. `https://pgtools.dev/0.8.1/schema.json`. ## Usage @@ -59,26 +59,26 @@ The CLI exposes a `check` command that will run all checks on the given files or ```sh # check a specific file -postgrestools check myfile.sql +postgres-language-server check myfile.sql # check a directory -postgrestools check supabase/migrations +postgres-language-server check supabase/migrations ``` -Run `postgrestools --help` for all options. The CLI options take precedence over what is loaded from `postgrestools.jsonc`. +Run `postgres-language-server --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). +- VSCode: The language server is available on the [VSCode Marketplace](https://marketplace.visualstudio.com/items?itemName=Supabase.postgres-language-server). It's published from [this repo](https://github.com/supabase-community/postgres-language-server-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 -Run `postgrestools check` in your CI pipeline to lint your schema changes and enforce code quality across your team. We provide a [GitHub Action](https://github.com/supabase-community/postgrestools-cli-action) to setup the Postgres Language Server in your runner. +Run `postgres-language-server check` in your CI pipeline to lint your schema changes and enforce code quality across your team. We provide a [GitHub Action](https://github.com/supabase-community/postgres-language-server-cli-action) to setup the Postgres Language Server in your runner. See the [Continuous Integration](/guides/continuous_integration) guide for an example. diff --git a/docs/guides/checking_migrations.md b/docs/guides/checking_migrations.md index 6f552f6ed..74583613b 100644 --- a/docs/guides/checking_migrations.md +++ b/docs/guides/checking_migrations.md @@ -5,10 +5,10 @@ Postgres Language Tools comes with a `check` command that can be integrated into To run it, simply point at your migrations directory. ```sh -postgrestools check supabase/migrations +postgres-language-server 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 @@ -23,10 +23,10 @@ When you are setting it up in an existing project, you might want to ignore all Alternatively, pass them directly. ``` -postgrestools check supabase/migrations --migrations-dir="supabase/migrations" --after=1740868021 +postgres-language-server check supabase/migrations --migrations-dir="supabase/migrations" --after=1740868021 ``` 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..86d43b61e 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 { @@ -45,12 +45,12 @@ Configure database connection details in your `postgrestools.jsonc` file: The language server primarily needs read access to your database schema. Consider creating a dedicated user with limited permissions: ```sql -CREATE USER postgrestools_lsp WITH PASSWORD 'secure_password'; -GRANT CONNECT ON DATABASE your_database TO postgrestools_lsp; -GRANT USAGE ON SCHEMA public TO postgrestools_lsp; -GRANT SELECT ON ALL TABLES IN SCHEMA public TO postgrestools_lsp; -GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO postgrestools_lsp; -GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO postgrestools_lsp; +CREATE USER postgres-language-server_lsp WITH PASSWORD 'secure_password'; +GRANT CONNECT ON DATABASE your_database TO postgres-language-server_lsp; +GRANT USAGE ON SCHEMA public TO postgres-language-server_lsp; +GRANT SELECT ON ALL TABLES IN SCHEMA public TO postgres-language-server_lsp; +GRANT SELECT ON ALL SEQUENCES IN SCHEMA public TO postgres-language-server_lsp; +GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO postgres-language-server_lsp; ``` ### Statement Execution Control @@ -79,7 +79,7 @@ If you prefer to work without a database connection, you can disable all databas Or use the command line flag: ```bash -postgrestools check sql/ --disable-db +postgres-language-server check sql/ --disable-db ``` When disabled, you'll still get: diff --git a/docs/guides/continuous_integration.md b/docs/guides/continuous_integration.md index 44ac4c2d3..d538884c3 100644 --- a/docs/guides/continuous_integration.md +++ b/docs/guides/continuous_integration.md @@ -4,7 +4,7 @@ Running the Postgres Language Server in a CI environment can boost your teams co ### GitHub Actions -We provide a first-party [GitHub Action](https://github.com/supabase-community/postgrestools-cli-action) to setup the CLI in your runner. Here’s what a simple workflow might look like: +We provide a first-party [GitHub Action](https://github.com/supabase-community/postgres-language-server-cli-action) to setup the CLI in your runner. Here’s what a simple workflow might look like: ```yaml jobs: @@ -15,7 +15,7 @@ jobs: - uses: supabase-community/pglt-cli-action@main with: version: latest - - run: postgrestools check --skip-db sql/ + - run: postgres-language-server check --skip-db sql/ ``` You likely want to setup Postgres to enable more advanced checks: @@ -38,7 +38,7 @@ jobs: - uses: supabase-community/pglt-cli-action@main with: version: latest - - run: postgrestools check sql/ + - run: postgres-language-server check sql/ ``` A common use-case is to check your migration files. Check out [the dedicated guide](./checking_migrations.md) for details. diff --git a/docs/guides/ide_setup.md b/docs/guides/ide_setup.md index b97c6c249..ef71ebb7d 100644 --- a/docs/guides/ide_setup.md +++ b/docs/guides/ide_setup.md @@ -4,7 +4,7 @@ Th Postgres Language Server has first-class [LSP](https://microsoft.github.io/la ## 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). +The language server is available on the [VSCode Marketplace](https://marketplace.visualstudio.com/items?itemName=Supabase.postgres-language-server). It's published from [this repo](https://github.com/supabase-community/postgres-language-server-vscode). ## Neovim @@ -40,13 +40,13 @@ Using the binary via CLI is very efficient, although you will not be able to pro If order to do so, you first need to start a daemon process with the start command: ```shell -postgrestools start +postgres-language-server start ``` Then, every command needs to add the `--use-server` options, e.g.: ```shell -postgrestools check --use-server --stdin-file-path=dummy.sql +postgres-language-server check --use-server --stdin-file-path=dummy.sql ``` diff --git a/docs/guides/vcs_integration.md b/docs/guides/vcs_integration.md index e22e83676..7366c4012 100644 --- a/docs/guides/vcs_integration.md +++ b/docs/guides/vcs_integration.md @@ -50,13 +50,13 @@ First, you have to update your configuration file with the default branch via th Add the `--changed` option to your command to process only those files that your VCS acknowledged as “changed”. The language server will determine the changed files from the branch `main` and your current revision: ```shell -postgrestools check --changed +postgres-language-server check --changed ``` Alternatively, you can use the option `--since` to specify an arbitrary branch. This option takes precedence over the option `vcs.defaultBranch`. For example, you might want to check your changes against the `next` branch: ```shell -postgrestools check --changed --since=next +postgres-language-server check --changed --since=next ``` ## Process only staged files @@ -64,6 +64,6 @@ postgrestools check --changed --since=next Before committing your changes, you may want to check the files that have been added to the index, also known as staged files. Add the `--staged` option to process only those files: ```shell -postgrestools check --staged +postgres-language-server check --staged ``` diff --git a/docs/manual_installation.md b/docs/manual_installation.md index 2c20f9dc2..d708ffa5f 100644 --- a/docs/manual_installation.md +++ b/docs/manual_installation.md @@ -8,12 +8,12 @@ You have to pick the correct binary for your platform. The following table shoul | CPU Architecture | Operating System | Binary name | |------------------|------------------|-------------| -| x86_64 | Linux | `postgrestools-x86_64-unknown-linux-gnu` | -| aarch64 | Linux | `postgrestools-aarch64-unknown-linux-gnu` | -| x86_64 | macOS | `postgrestools-x86_64-apple-darwin` | -| aarch64 (M1/M2) | macOS | `postgrestools-aarch64-apple-darwin` | -| x86_64 | Windows | `postgrestools-x86_64-pc-windows-msvc.exe` | -| aarch64 | Windows | `postgrestools-aarch64-pc-windows-msvc.exe` | +| x86_64 | Linux | `postgres-language-server-x86_64-unknown-linux-gnu` | +| aarch64 | Linux | `postgres-language-server-aarch64-unknown-linux-gnu` | +| x86_64 | macOS | `postgres-language-server-x86_64-apple-darwin` | +| aarch64 (M1/M2) | macOS | `postgres-language-server-aarch64-apple-darwin` | +| x86_64 | Windows | `postgres-language-server-x86_64-pc-windows-msvc.exe` | +| aarch64 | Windows | `postgres-language-server-aarch64-pc-windows-msvc.exe` | > **Note**: Use the Linux variant for Windows Subsystem for Linux (WSL). @@ -24,30 +24,30 @@ We were not able to publish to Homebrew yet due to naming conflicts. We are acti ### Using a published binary -To install postgrestools, grab the executable for your platform from the latest CLI release on GitHub and give it execution permission. +To install postgres-language-server, grab the executable for your platform from the latest CLI release on GitHub and give it execution permission. ```bash # macOS arm (M1 or newer) -curl -L https://github.com/supabase-community/postgres-language-server/releases/latest/download/postgrestools-aarch64-apple-darwin -o postgrestools -chmod +x postgrestools +curl -L https://github.com/supabase-community/postgres-language-server/releases/latest/download/postgres-language-server-aarch64-apple-darwin -o postgres-language-server +chmod +x postgres-language-server # macOS x86_64 -curl -L https://github.com/supabase-community/postgres-language-server/releases/latest/download/postgrestools-x86_64-apple-darwin -o postgrestools -chmod +x postgrestools +curl -L https://github.com/supabase-community/postgres-language-server/releases/latest/download/postgres-language-server-x86_64-apple-darwin -o postgres-language-server +chmod +x postgres-language-server # Linux (x86_64) -curl -L https://github.com/supabase-community/postgres-language-server/releases/latest/download/postgrestools-x86_64-unknown-linux-gnu -o postgrestools -chmod +x postgrestools +curl -L https://github.com/supabase-community/postgres-language-server/releases/latest/download/postgres-language-server-x86_64-unknown-linux-gnu -o postgres-language-server +chmod +x postgres-language-server # Linux (aarch64) -curl -L https://github.com/supabase-community/postgres-language-server/releases/latest/download/postgrestools-aarch64-unknown-linux-gnu -o postgrestools -chmod +x postgrestools +curl -L https://github.com/supabase-community/postgres-language-server/releases/latest/download/postgres-language-server-aarch64-unknown-linux-gnu -o postgres-language-server +chmod +x postgres-language-server # Windows (x86_64, PowerShell) -Invoke-WebRequest -Uri "https://github.com/supabase-community/postgres-language-server/releases/latest/download/postgrestools-x86_64-pc-windows-msvc.exe" -OutFile "postgrestools.exe" +Invoke-WebRequest -Uri "https://github.com/supabase-community/postgres-language-server/releases/latest/download/postgres-language-server-x86_64-pc-windows-msvc.exe" -OutFile "postgres-language-server.exe" # Windows (aarch64, PowerShell) -Invoke-WebRequest -Uri "https://github.com/supabase-community/postgres-language-server/releases/latest/download/postgrestools-aarch64-pc-windows-msvc.exe" -OutFile "postgrestools.exe" +Invoke-WebRequest -Uri "https://github.com/supabase-community/postgres-language-server/releases/latest/download/postgres-language-server-aarch64-pc-windows-msvc.exe" -OutFile "postgres-language-server.exe" ``` -Now you can use the Postgres Language Server by simply running `./postgrestools`. +Now you can use the Postgres Language Server by simply running `./postgres-language-server`. diff --git a/docs/reference/cli.md b/docs/reference/cli.md index 81db5e1e5..a5283f7b2 100644 --- a/docs/reference/cli.md +++ b/docs/reference/cli.md @@ -4,20 +4,20 @@ # 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) +- [`postgres-language-server`↴](#postgres-language-server) +- [`postgres-language-server version`↴](#postgres-language-server-version) +- [`postgres-language-server check`↴](#postgres-language-server-check) +- [`postgres-language-server start`↴](#postgres-language-server-start) +- [`postgres-language-server stop`↴](#postgres-language-server-stop) +- [`postgres-language-server init`↴](#postgres-language-server-init) +- [`postgres-language-server lsp-proxy`↴](#postgres-language-server-lsp-proxy) +- [`postgres-language-server clean`↴](#postgres-language-server-clean) -## postgrestools +## postgres-language-server -PostgresTools official CLI. Use it to check the health of your project or run it to check single files. +postgres-language-server official CLI. Use it to check the health of your project or run it to check single files. -**Usage**: **`postgrestools`** _`COMMAND ...`_ +**Usage**: **`postgres-language-server`** _`COMMAND ...`_ **Available options:** @@ -43,11 +43,11 @@ PostgresTools official CLI. Use it to check the health of your project or run it - **`clean`** — Cleans the logs emitted by the daemon. -## postgrestools version +## postgres-language-server version Shows the version information and quit. -**Usage**: **`postgrestools`** **`version`** +**Usage**: **`postgres-language-server`** **`version`** **Global options applied to all commands** @@ -60,7 +60,7 @@ Shows the version information and quit. - **` --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. + 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] @@ -91,11 +91,11 @@ Shows the version information and quit. - **`-h`**, **`--help`** — Prints help information -## postgrestools check +## postgres-language-server check Runs everything to the requested files. -**Usage**: **`postgrestools`** **`check`** \[**`--staged`**\] \[**`--changed`**\] \[**`--since`**=_`REF`_\] \[_`PATH`_\]... +**Usage**: **`postgres-language-server`** **`check`** \[**`--staged`**\] \[**`--changed`**\] \[**`--since`**=_`REF`_\] \[_`PATH`_\]... **The configuration that is contained inside the configuration file.** @@ -106,7 +106,7 @@ Runs everything to the requested files. - **` --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`_ — - 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 @@ -143,7 +143,7 @@ Runs everything to the requested files. - **` --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. + 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] @@ -188,15 +188,15 @@ Runs everything to the requested files. - **` --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` + 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 +## postgres-language-server start Starts the daemon server process. -**Usage**: **`postgrestools`** **`start`** \[**`--config-path`**=_`PATH`_\] +**Usage**: **`postgres-language-server`** **`start`** \[**`--config-path`**=_`PATH`_\] **Available options:** @@ -208,38 +208,38 @@ Starts the daemon server process. 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` + 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`** — Prints help information -## postgrestools stop +## postgres-language-server stop Stops the daemon server process. -**Usage**: **`postgrestools`** **`stop`** +**Usage**: **`postgres-language-server`** **`stop`** **Available options:** - **`-h`**, **`--help`** — Prints help information -## postgrestools init +## postgres-language-server init Bootstraps a new project. Creates a configuration file with some defaults. -**Usage**: **`postgrestools`** **`init`** +**Usage**: **`postgres-language-server`** **`init`** **Available options:** - **`-h`**, **`--help`** — Prints help information -## postgrestools lsp-proxy +## postgres-language-server lsp-proxy Acts as a server for the Language Server Protocol over stdin/stdout. -**Usage**: **`postgrestools`** **`lsp-proxy`** \[**`--config-path`**=_`PATH`_\] +**Usage**: **`postgres-language-server`** **`lsp-proxy`** \[**`--config-path`**=_`PATH`_\] **Available options:** @@ -251,16 +251,16 @@ Acts as a server for the Language Server Protocol over stdin/stdout. 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` + 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`** — Prints help information -## postgrestools clean +## postgres-language-server clean Cleans the logs emitted by the daemon. -**Usage**: **`postgrestools`** **`clean`** +**Usage**: **`postgres-language-server`** **`clean`** **Available options:** 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/justfile b/justfile index 970a79281..27813d5c0 100644 --- a/justfile +++ b/justfile @@ -149,12 +149,12 @@ quick-modify: git commit -m "progress" git push -# Make sure to set your PGT_LOG_PATH in your shell profile. -# You can use the PGT_LOG_LEVEL to set your log level. +# Make sure to set your PGLS_LOG_PATH in your shell profile. +# You can use the PGLS_LOG_LEVEL to set your log level. # We recommend to install `bunyan` (npm i -g bunyan) and pipe the output through there for color-coding: # just show-logs | bunyan show-logs: - tail -f $(ls $PGT_LOG_PATH/server.log.* | sort -t- -k2,2 -k3,3 -k4,4 | tail -n 1) + tail -f $(ls $PGLS_LOG_PATH/server.log.* | sort -t- -k2,2 -k3,3 -k4,4 | tail -n 1) # Run a claude agent with the given agentic prompt file. # Commented out by default to avoid accidental usage that may incur costs. diff --git a/package.json b/package.json index bf9303007..a5c2d0ba4 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "@postgrestools/monorepo", + "name": "@postgres-language-server/monorepo", "version": "0.0.0", "private": true, "devDependencies": { @@ -11,7 +11,9 @@ }, "workspaces": [ "packages/@postgrestools/postgrestools", - "packages/@postgrestools/backend-jsonrpc" + "packages/@postgrestools/backend-jsonrpc", + "packages/@postgres-language-server/postgrestools", + "packages/@postgres-language-server/backend-jsonrpc" ], "keywords": [], "author": "Supabase Community", diff --git a/packages/@postgrestools/backend-jsonrpc/src/workspace.ts b/packages/@postgrestools/backend-jsonrpc/src/workspace.ts index 51a4f5663..7cd19a0e2 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; @@ -411,7 +411,7 @@ export interface PartialVcsConfiguration { /** * 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 +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; /** diff --git a/pyproject.toml b/pyproject.toml index 41317471b..a7d03d76b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [project] -name = "postgrestools" +name = "postgres-language-server" version = "0.1.0" description = "A collection of language tools and a Language Server Protocol (LSP) implementation for Postgres, focusing on developer experience and reliable SQL tooling." readme = "README.md" diff --git a/xtask/codegen/src/generate_bindings.rs b/xtask/codegen/src/generate_bindings.rs index 4b66fd004..553d5cd15 100644 --- a/xtask/codegen/src/generate_bindings.rs +++ b/xtask/codegen/src/generate_bindings.rs @@ -15,7 +15,7 @@ use xtask::{project_root, Mode, Result}; pub fn generate_bindings(mode: Mode) -> Result<()> { let bindings_path = - project_root().join("packages/@postgrestools/backend-jsonrpc/src/workspace.ts"); + project_root().join("packages/@postgres-language-server/backend-jsonrpc/src/workspace.ts"); let methods = methods(); let mut declarations = Vec::new();