Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/pgt_analyse/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
6 changes: 3 additions & 3 deletions crates/pgt_analyser/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion crates/pgt_cli/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
Expand Down
4 changes: 2 additions & 2 deletions crates/pgt_cli/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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...

"<Info><Emphasis>"Files created "</Emphasis></Info>"

Expand Down
46 changes: 37 additions & 9 deletions crates/pgt_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<String>,

Expand Down Expand Up @@ -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<PathBuf>,
},

Expand Down Expand Up @@ -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<PathBuf>,
/// Bogus argument to make the command work with vscode-languageclient
#[bpaf(long("stdio"), hide, hide_usage, switch)]
Expand Down Expand Up @@ -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<PathBuf>,
},
#[bpaf(command("__print_socket"), hide)]
Expand Down Expand Up @@ -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! {
<Warn>"Warning: "</Warn>"You are using the deprecated config filename '"<Emphasis>"postgrestools.jsonc"</Emphasis>"'. \
Please rename it to '"<Emphasis>"postgres-language-server.jsonc"</Emphasis>"'. \
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());
Expand Down
4 changes: 2 additions & 2 deletions crates/pgt_cli/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/pgt_configuration/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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".

Expand Down
2 changes: 1 addition & 1 deletion crates/pgt_configuration/src/vcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions crates/pgt_fs/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/pgt_fs/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
24 changes: 13 additions & 11 deletions crates/pgt_lsp/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
);
Expand Down Expand Up @@ -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));

Expand Down
43 changes: 39 additions & 4 deletions crates/pgt_lsp/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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>,

Expand Down Expand Up @@ -165,6 +168,7 @@ impl Session {
cancellation,
config_path: None,
notified_broken_configuration: AtomicBool::new(false),
notified_deprecated_config: AtomicBool::new(false),
}
}

Expand Down Expand Up @@ -398,7 +402,7 @@ impl Session {
.map(|params| &params.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<PartialConfiguration>) {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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("<unknown>".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;
Expand Down
Loading