diff --git a/Cargo.lock b/Cargo.lock index 28e0a3d65..8b01e85fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -972,7 +972,6 @@ dependencies = [ "schemars", "serde", "serde_json", - "toml", ] [[package]] @@ -2315,7 +2314,6 @@ dependencies = [ "schemars", "serde", "serde_json", - "toml", ] [[package]] @@ -2438,7 +2436,6 @@ dependencies = [ "serde_json", "sqlx", "tokio", - "toml", "tower", "tower-lsp", "tracing", @@ -2620,12 +2617,12 @@ dependencies = [ "pglt_text_size", "pglt_typecheck", "rustc-hash 2.1.0", + "schemars", "serde", "serde_json", "sqlx", "tempfile", "tokio", - "toml", "tracing", "tree-sitter", "tree_sitter_sql", diff --git a/crates/pglt_analyse/Cargo.toml b/crates/pglt_analyse/Cargo.toml index 4574d90c1..96c4ea880 100644 --- a/crates/pglt_analyse/Cargo.toml +++ b/crates/pglt_analyse/Cargo.toml @@ -27,4 +27,5 @@ schemars = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"], optional = true } [features] -serde = ["dep:serde", "dep:schemars", "dep:biome_deserialize", "dep:biome_deserialize_macros"] +schema = ["dep:schemars"] +serde = ["dep:serde", "dep:biome_deserialize", "dep:biome_deserialize_macros"] diff --git a/crates/pglt_analyse/src/categories.rs b/crates/pglt_analyse/src/categories.rs index 0b539eac4..d13e1a3da 100644 --- a/crates/pglt_analyse/src/categories.rs +++ b/crates/pglt_analyse/src/categories.rs @@ -2,10 +2,8 @@ use enumflags2::{BitFlags, bitflags}; use std::borrow::Cow; #[derive(Copy, Clone, Debug, Eq, PartialEq)] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema) -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub enum RuleCategory { /// This rule performs static analysis of the source code to detect /// invalid or error-prone patterns, and emits diagnostics along with @@ -26,10 +24,8 @@ pub const SUPPRESSION_ACTION_CATEGORY: &str = "quickfix.suppressRule"; /// /// [CodeActionKind]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#codeActionKind #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema) -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub enum ActionCategory { /// Base kind for quickfix actions: 'quickfix'. /// @@ -110,10 +106,8 @@ impl ActionCategory { /// /// [Check the LSP spec](https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#codeActionKind) for more information: #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema) -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub enum RefactorKind { /// This action describes a refactor with no particular sub-category None, @@ -150,10 +144,8 @@ pub enum RefactorKind { /// The sub-category of a source code action #[derive(Clone, Debug, PartialEq, Eq)] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema) -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub enum SourceActionKind { /// This action describes a source action with no particular sub-category None, @@ -282,7 +274,7 @@ impl<'de> serde::Deserialize<'de> for RuleCategories { } } -#[cfg(feature = "serde")] +#[cfg(feature = "schema")] impl schemars::JsonSchema for RuleCategories { fn schema_name() -> String { String::from("RuleCategories") diff --git a/crates/pglt_analyse/src/options.rs b/crates/pglt_analyse/src/options.rs index 20ac7236f..9645799a0 100644 --- a/crates/pglt_analyse/src/options.rs +++ b/crates/pglt_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 [`pglt.toml`] file + /// A data structured derived from the [`pglt.jsonc`] file pub rules: AnalyserRules, } diff --git a/crates/pglt_analyse/src/rule.rs b/crates/pglt_analyse/src/rule.rs index 1f70cf844..c7f384898 100644 --- a/crates/pglt_analyse/src/rule.rs +++ b/crates/pglt_analyse/src/rule.rs @@ -12,7 +12,11 @@ use std::fmt::Debug; use crate::{categories::RuleCategory, context::RuleContext, registry::RegistryVisitor}; #[derive(Clone, Debug)] -#[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize), + serde(rename_all = "camelCase") +)] /// Static metadata containing information about a rule pub struct RuleMetadata { /// It marks if a rule is deprecated, and if so a reason has to be provided. @@ -271,8 +275,8 @@ impl RuleDiagnostic { } #[derive(Debug, Clone, Eq)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, schemars::JsonSchema))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] +#[cfg_attr(feature = "serde", derive(serde::Serialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub enum RuleSource { /// Rules from [Squawk](https://squawkhq.com) Squawk(&'static str), diff --git a/crates/pglt_analyser/CONTRIBUTING.md b/crates/pglt_analyser/CONTRIBUTING.md index c855ac592..8bf1f7854 100644 --- a/crates/pglt_analyser/CONTRIBUTING.md +++ b/crates/pglt_analyser/CONTRIBUTING.md @@ -79,15 +79,24 @@ 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 `pglt.toml` configuration file: - -```toml -[linter.rules.safety.myRule] -level = "warn" -options = { - behavior = "A" - threshold = 20 - behaviorExceptions = ["one", "two"] +We would like to set the options in the `pglt.jsonc` configuration file: + +```json +{ + "linter": { + "rules": { + "safety": { + "myRule": { + "level": "warn", + "options": { + "behavior": "A", + "threshold": 20, + "behaviorExceptions": ["one", "two"] + } + } + } + } + } } ``` @@ -132,16 +141,16 @@ We currently require implementing _serde_'s traits `Deserialize`/`Serialize`. Also, we use other `serde` macros to adjust the JSON configuration: -- `rename_all = "snake_case"`: it renames all fields in camel-case, so they are in line with the naming style of the `pglt.toml`. +- `rename_all = "camelCase"`: it renames all fields in camel-case, so they are in line with the naming style of the `pglt.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 `pglt.toml`. This macro makes the field optional. +- `default`: it uses the `Default` value when the field is missing from `pglt.jsonc`. This macro makes the field optional. You can simply use a derive macros: ```rust #[derive(Debug, Default, Clone, Serialize, Deserialize)] #[cfg_attr(feature = "schemars", derive(JsonSchema))] -#[serde(rename_all = "snake_case", deny_unknown_fields, default)] +#[serde(rename_all = "camelCase", deny_unknown_fields, default)] pub struct MyRuleOptions { #[serde(default, skip_serializing_if = "is_default")] main_behavior: Behavior, diff --git a/crates/pglt_cli/Cargo.toml b/crates/pglt_cli/Cargo.toml index d4ccc5e1f..204d20918 100644 --- a/crates/pglt_cli/Cargo.toml +++ b/crates/pglt_cli/Cargo.toml @@ -55,8 +55,6 @@ tikv-jemallocator = "0.6.0" [lib] doctest = false -[features] - [[bin]] name = "pglt" path = "src/main.rs" diff --git a/crates/pglt_cli/src/cli_options.rs b/crates/pglt_cli/src/cli_options.rs index de28072a5..0527e96f4 100644 --- a/crates/pglt_cli/src/cli_options.rs +++ b/crates/pglt_cli/src/cli_options.rs @@ -26,7 +26,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 `pglt.toml`. + /// Set the file path to the configuration file, or the directory path to find `pglt.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/pglt_cli/src/commands/init.rs b/crates/pglt_cli/src/commands/init.rs index a4a6d8510..b94f6179e 100644 --- a/crates/pglt_cli/src/commands/init.rs +++ b/crates/pglt_cli/src/commands/init.rs @@ -6,8 +6,9 @@ use pglt_workspace::configuration::create_config; pub(crate) fn init(mut session: CliSession) -> Result<(), CliDiagnostic> { let fs = &mut session.app.fs; - create_config(fs, PartialConfiguration::init())?; - let file_created = ConfigName::pglt_toml(); + let config = &mut PartialConfiguration::init(); + create_config(fs, config)?; + let file_created = ConfigName::pglt_jsonc(); session.app.console.log(markup! { " Welcome to the Postgres Language Tools! Let's get you started... diff --git a/crates/pglt_cli/src/commands/mod.rs b/crates/pglt_cli/src/commands/mod.rs index a925b2c6b..16b7b9768 100644 --- a/crates/pglt_cli/src/commands/mod.rs +++ b/crates/pglt_cli/src/commands/mod.rs @@ -58,7 +58,7 @@ pub enum PgltCommand { 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 `pglt.toml` + /// flag and the `defaultBranch` is not set in your `pglt.jsonc` #[bpaf(long("since"), argument("REF"))] since: Option, @@ -91,7 +91,7 @@ pub enum PgltCommand { )] log_path: PathBuf, /// Allows to set a custom file path to the configuration file, - /// or a custom directory path to find `pglt.toml` + /// or a custom directory path to find `pglt.jsonc` #[bpaf(env("PGLT_LOG_PREFIX_NAME"), long("config-path"), argument("PATH"))] config_path: Option, }, @@ -127,7 +127,7 @@ pub enum PgltCommand { )] log_path: PathBuf, /// Allows to set a custom file path to the configuration file, - /// or a custom directory path to find `pglt.toml` + /// or a custom directory path to find `pglt.jsonc` #[bpaf(env("PGLT_CONFIG_PATH"), long("config-path"), argument("PATH"))] config_path: Option, /// Bogus argument to make the command work with vscode-languageclient @@ -164,7 +164,7 @@ pub enum PgltCommand { #[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 `pglt.toml` + /// or a custom directory path to find `pglt.jsonc` #[bpaf(env("PGLT_CONFIG_PATH"), long("config-path"), argument("PATH"))] config_path: Option, }, diff --git a/crates/pglt_cli/src/diagnostics.rs b/crates/pglt_cli/src/diagnostics.rs index 07e43b7dc..374dac38c 100644 --- a/crates/pglt_cli/src/diagnostics.rs +++ b/crates/pglt_cli/src/diagnostics.rs @@ -48,7 +48,7 @@ pub enum CliDiagnostic { IoError(IoDiagnostic), /// The daemon is not running ServerNotRunning(ServerNotRunning), - /// The end configuration (`pglt.toml` + other options) is incompatible with the command + /// The end configuration (`pglt.jsonc` + other options) is incompatible with the command IncompatibleEndConfiguration(IncompatibleEndConfiguration), /// No files processed during the file system traversal NoFilesWereProcessed(NoFilesWereProcessed), @@ -410,7 +410,7 @@ impl CliDiagnostic { Self::ServerNotRunning(ServerNotRunning) } - /// Emitted when the end configuration (`pglt.toml` file + CLI arguments + LSP configuration) + /// Emitted when the end configuration (`pglt.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/pglt_commands/Cargo.toml b/crates/pglt_commands/Cargo.toml index 2507b9147..972158aee 100644 --- a/crates/pglt_commands/Cargo.toml +++ b/crates/pglt_commands/Cargo.toml @@ -19,5 +19,3 @@ sqlx.workspace = true [lib] doctest = false - -[features] diff --git a/crates/pglt_completions/Cargo.toml b/crates/pglt_completions/Cargo.toml index eec3d903e..4c8e6ef26 100644 --- a/crates/pglt_completions/Cargo.toml +++ b/crates/pglt_completions/Cargo.toml @@ -33,5 +33,3 @@ pglt_test_utils.workspace = true [lib] doctest = false - -[features] diff --git a/crates/pglt_configuration/Cargo.toml b/crates/pglt_configuration/Cargo.toml index dde8592f1..27c61167d 100644 --- a/crates/pglt_configuration/Cargo.toml +++ b/crates/pglt_configuration/Cargo.toml @@ -25,7 +25,6 @@ rustc-hash = { workspace = true } schemars = { workspace = true, features = ["indexmap1"], optional = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, features = ["raw_value"] } -toml = { workspace = true } [lib] doctest = false diff --git a/crates/pglt_configuration/src/database.rs b/crates/pglt_configuration/src/database.rs index 2cf6cbd48..6ec5773f5 100644 --- a/crates/pglt_configuration/src/database.rs +++ b/crates/pglt_configuration/src/database.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Deserialize, Eq, Partial, PartialEq, Serialize)] #[partial(derive(Bpaf, Clone, Eq, PartialEq, Merge))] #[partial(cfg_attr(feature = "schema", derive(schemars::JsonSchema)))] -#[partial(serde(rename_all = "snake_case", default, deny_unknown_fields))] +#[partial(serde(rename_all = "camelCase", default, deny_unknown_fields))] pub struct DatabaseConfiguration { /// The host of the database. #[partial(bpaf(long("host")))] diff --git a/crates/pglt_configuration/src/diagnostics.rs b/crates/pglt_configuration/src/diagnostics.rs index fe21c5a60..868783706 100644 --- a/crates/pglt_configuration/src/diagnostics.rs +++ b/crates/pglt_configuration/src/diagnostics.rs @@ -24,9 +24,9 @@ pub enum ConfigurationDiagnostic { } impl ConfigurationDiagnostic { - pub fn new_deserialization_error(error: toml::de::Error) -> Self { + pub fn new_deserialization_error(error: serde_json::Error) -> Self { Self::DeserializationError(DeserializationError { - message: error.message().to_string(), + message: error.to_string(), }) } diff --git a/crates/pglt_configuration/src/files.rs b/crates/pglt_configuration/src/files.rs index 9997695d6..c8e3cde29 100644 --- a/crates/pglt_configuration/src/files.rs +++ b/crates/pglt_configuration/src/files.rs @@ -14,7 +14,7 @@ pub const DEFAULT_FILE_SIZE_LIMIT: NonZeroU64 = #[derive(Clone, Debug, Deserialize, Eq, Partial, PartialEq, Serialize)] #[partial(derive(Bpaf, Clone, Eq, PartialEq, Merge))] #[partial(cfg_attr(feature = "schema", derive(schemars::JsonSchema)))] -#[partial(serde(rename_all = "snake_case", default, deny_unknown_fields))] +#[partial(serde(rename_all = "camelCase", default, deny_unknown_fields))] pub struct FilesConfiguration { /// The maximum allowed size for source code files in bytes. Files above /// this limit will be ignored for performance reasons. Defaults to 1 MiB diff --git a/crates/pglt_configuration/src/lib.rs b/crates/pglt_configuration/src/lib.rs index 1ffb672a4..75b4578c0 100644 --- a/crates/pglt_configuration/src/lib.rs +++ b/crates/pglt_configuration/src/lib.rs @@ -1,4 +1,4 @@ -//! This module contains the configuration of `pglt.toml` +//! This module contains the configuration of `pglt.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. @@ -43,8 +43,13 @@ pub const VERSION: &str = match option_env!("PGLT_VERSION") { #[derive(Clone, Debug, Default, Deserialize, Eq, Partial, PartialEq, Serialize)] #[partial(derive(Bpaf, Clone, Eq, PartialEq, Merge))] #[partial(cfg_attr(feature = "schema", derive(schemars::JsonSchema)))] -#[partial(serde(deny_unknown_fields, rename_all = "snake_case"))] +#[partial(serde(deny_unknown_fields, rename_all = "camelCase"))] pub struct Configuration { + /// A field for the [JSON schema](https://json-schema.org/) specification + #[partial(serde(rename = "$schema"))] + #[partial(bpaf(hide))] + pub schema: String, + /// The configuration of the VCS integration #[partial(type, bpaf(external(partial_vcs_configuration), optional, hide_usage))] pub vcs: VcsConfiguration, @@ -79,6 +84,10 @@ impl PartialConfiguration { /// Returns the initial configuration. pub fn init() -> Self { Self { + // TODO: Update this once we have a static url + schema: Some(format!( + "https://supabase-community.github.io/postgres_lsp/schemas/{VERSION}/schema.json" + )), files: Some(PartialFilesConfiguration { ignore: Some(Default::default()), ..Default::default() diff --git a/crates/pglt_configuration/src/migrations.rs b/crates/pglt_configuration/src/migrations.rs index 2fa99c695..c134e1a41 100644 --- a/crates/pglt_configuration/src/migrations.rs +++ b/crates/pglt_configuration/src/migrations.rs @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize}; /// The configuration of the filesystem #[derive(Clone, Debug, Deserialize, Eq, Partial, PartialEq, Serialize, Default)] #[partial(derive(Bpaf, Clone, Eq, PartialEq, Merge))] -#[partial(serde(rename_all = "snake_case", default, deny_unknown_fields))] +#[partial(serde(rename_all = "camelCase", default, deny_unknown_fields))] #[partial(cfg_attr(feature = "schema", derive(schemars::JsonSchema)))] pub struct MigrationsConfiguration { /// The directory where the migration files are stored diff --git a/crates/pglt_configuration/src/vcs.rs b/crates/pglt_configuration/src/vcs.rs index be61abdaf..61f9aa209 100644 --- a/crates/pglt_configuration/src/vcs.rs +++ b/crates/pglt_configuration/src/vcs.rs @@ -11,7 +11,7 @@ const GIT_IGNORE_FILE_NAME: &str = ".gitignore"; #[partial(derive(Bpaf, Clone, Deserializable, Eq, Merge, PartialEq))] #[partial(deserializable(with_validator))] #[partial(cfg_attr(feature = "schema", derive(schemars::JsonSchema)))] -#[partial(serde(deny_unknown_fields))] +#[partial(serde(deny_unknown_fields, rename_all = "camelCase"))] pub struct VcsConfiguration { /// Whether we should integrate itself with the VCS client #[partial(bpaf(long("vcs-enabled"), argument("true|false")))] @@ -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 `pglt.toml` was found. + /// folder where `pglt.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 @@ -91,7 +91,7 @@ impl DeserializableValidator for PartialVcsConfiguration { Clone, Copy, Debug, Default, Deserialize, Deserializable, Eq, Merge, PartialEq, Serialize, )] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[serde(rename_all = "snake_case")] +#[serde(rename_all = "camelCase")] pub enum VcsClientKind { #[default] /// Integration with the git client as VCS diff --git a/crates/pglt_console/Cargo.toml b/crates/pglt_console/Cargo.toml index ab4ce461e..2b5cfa864 100644 --- a/crates/pglt_console/Cargo.toml +++ b/crates/pglt_console/Cargo.toml @@ -25,7 +25,8 @@ unicode-width = { workspace = true } trybuild = "1.0.99" [features] -serde_markup = ["serde", "schemars"] +schema = ["dep:schemars", "pglt_text_size/schema"] +serde = ["dep:serde"] [lib] doctest = false diff --git a/crates/pglt_console/src/markup.rs b/crates/pglt_console/src/markup.rs index 4c046ba86..b4caadf7e 100644 --- a/crates/pglt_console/src/markup.rs +++ b/crates/pglt_console/src/markup.rs @@ -11,10 +11,8 @@ use crate::fmt::{Display, Formatter, MarkupElements, Write}; /// Enumeration of all the supported markup elements #[derive(Clone, Debug, PartialEq, Eq, Hash)] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema) -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub enum MarkupElement<'fmt> { Emphasis, Dim, @@ -122,10 +120,8 @@ pub struct MarkupNode<'fmt> { } #[derive(Clone, PartialEq, Eq, Hash)] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema) -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct MarkupNodeBuf { pub elements: Vec>, pub content: String, @@ -181,10 +177,8 @@ impl Markup<'_> { } #[derive(Clone, Default, PartialEq, Eq, Hash)] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema) -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct MarkupBuf(pub Vec); impl MarkupBuf { diff --git a/crates/pglt_diagnostics/Cargo.toml b/crates/pglt_diagnostics/Cargo.toml index c477bfd7e..ef01ba54b 100644 --- a/crates/pglt_diagnostics/Cargo.toml +++ b/crates/pglt_diagnostics/Cargo.toml @@ -15,10 +15,10 @@ version = "0.0.0" backtrace = "0.3.74" bpaf = { workspace = true } enumflags2 = { workspace = true } -pglt_console = { workspace = true, features = ["serde_markup"] } +pglt_console = { workspace = true, features = ["serde"] } pglt_diagnostics_categories = { workspace = true, features = ["serde"] } pglt_diagnostics_macros = { workspace = true } -pglt_text_edit = { workspace = true } +pglt_text_edit = { workspace = true, features = ["serde"] } pglt_text_size.workspace = true schemars = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } @@ -27,7 +27,7 @@ termcolor = { workspace = true } unicode-width = { workspace = true } [features] -schema = ["schemars", "pglt_text_edit/schemars", "pglt_diagnostics_categories/schemars"] +schema = ["dep:schemars", "pglt_text_edit/schema", "pglt_diagnostics_categories/schema", "pglt_console/schema"] [dev-dependencies] diff --git a/crates/pglt_diagnostics/src/advice.rs b/crates/pglt_diagnostics/src/advice.rs index afaa7ca6c..b7b4babc8 100644 --- a/crates/pglt_diagnostics/src/advice.rs +++ b/crates/pglt_diagnostics/src/advice.rs @@ -86,7 +86,7 @@ pub trait Visit { /// to the user. #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] -#[serde(rename_all = "snake_case")] +#[serde(rename_all = "camelCase")] pub enum LogCategory { /// The advice doesn't have any specific category, the message will be /// printed as plain markup. diff --git a/crates/pglt_diagnostics/src/diagnostic.rs b/crates/pglt_diagnostics/src/diagnostic.rs index 5eb40da23..0914e72ea 100644 --- a/crates/pglt_diagnostics/src/diagnostic.rs +++ b/crates/pglt_diagnostics/src/diagnostic.rs @@ -117,7 +117,7 @@ pub trait Diagnostic: Debug { #[derive( Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Default, )] -#[serde(rename_all = "snake_case")] +#[serde(rename_all = "camelCase")] /// The severity to associate to a diagnostic. pub enum Severity { /// Reports a hint. @@ -164,7 +164,7 @@ impl Display for Severity { /// Internal enum used to automatically generate bit offsets for [DiagnosticTags] /// and help with the implementation of `serde` and `schemars` for tags. #[derive(Debug, Copy, Clone, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] +#[serde(rename_all = "camelCase")] #[bitflags] #[repr(u8)] pub(super) enum DiagnosticTag { diff --git a/crates/pglt_diagnostics/src/location.rs b/crates/pglt_diagnostics/src/location.rs index 6678912d4..3b847975d 100644 --- a/crates/pglt_diagnostics/src/location.rs +++ b/crates/pglt_diagnostics/src/location.rs @@ -39,7 +39,7 @@ impl Eq for Location<'_> {} /// Represents the resource a diagnostic is associated with. #[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] +#[serde(rename_all = "camelCase")] pub enum Resource

{ /// The diagnostic is related to the content of the command line arguments. Argv, diff --git a/crates/pglt_diagnostics/src/serde.rs b/crates/pglt_diagnostics/src/serde.rs index d564f8321..aa67ebdef 100644 --- a/crates/pglt_diagnostics/src/serde.rs +++ b/crates/pglt_diagnostics/src/serde.rs @@ -15,7 +15,7 @@ use crate::{ /// Serializable representation for a [Diagnostic](super::Diagnostic). #[derive(Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(not(target_arch = "wasm32"), serde(rename_all = "snake_case"))] +#[cfg_attr(not(target_arch = "wasm32"), serde(rename_all = "camelCase"))] #[cfg_attr(test, derive(Eq, PartialEq))] pub struct Diagnostic { category: Option<&'static Category>, @@ -137,7 +137,7 @@ impl std::fmt::Display for PrintDescription<'_, D } #[derive(Clone, Debug, Serialize, Deserialize)] -#[cfg_attr(not(target_arch = "wasm32"), serde(rename_all = "snake_case"))] +#[cfg_attr(not(target_arch = "wasm32"), serde(rename_all = "camelCase"))] #[cfg_attr(test, derive(Eq, PartialEq))] struct Location { path: Option>, @@ -159,7 +159,7 @@ impl From> for Location { /// Implementation of [Visitor] collecting serializable [Advice] into a vector. #[derive(Clone, Debug, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] +#[serde(rename_all = "camelCase")] #[cfg_attr(test, derive(Eq, PartialEq))] struct Advices { advices: Vec, @@ -245,7 +245,7 @@ impl super::Advices for Advices { /// See the [Visitor] trait for additional documentation on all the supported /// advice types. #[derive(Clone, Debug, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] +#[serde(rename_all = "camelCase")] #[cfg_attr(test, derive(Eq, PartialEq))] enum Advice { Log(LogCategory, MarkupBuf), diff --git a/crates/pglt_diagnostics_categories/Cargo.toml b/crates/pglt_diagnostics_categories/Cargo.toml index 0771c05f6..fbc0d7834 100644 --- a/crates/pglt_diagnostics_categories/Cargo.toml +++ b/crates/pglt_diagnostics_categories/Cargo.toml @@ -15,5 +15,9 @@ version = "0.0.0" schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } +[features] +schema = ["dep:schemars"] +serde = ["dep:serde"] + [build-dependencies] quote = "1.0.14" diff --git a/crates/pglt_diagnostics_categories/build.rs b/crates/pglt_diagnostics_categories/build.rs index 1b2970c6d..9daa5413c 100644 --- a/crates/pglt_diagnostics_categories/build.rs +++ b/crates/pglt_diagnostics_categories/build.rs @@ -64,7 +64,7 @@ pub fn main() -> io::Result<()> { } } - #[cfg(feature = "schemars")] + #[cfg(feature = "schema")] impl schemars::JsonSchema for &'static Category { fn schema_name() -> String { String::from("Category") diff --git a/crates/pglt_diagnostics_macros/Cargo.toml b/crates/pglt_diagnostics_macros/Cargo.toml index 8cc10058c..3f77a86da 100644 --- a/crates/pglt_diagnostics_macros/Cargo.toml +++ b/crates/pglt_diagnostics_macros/Cargo.toml @@ -21,5 +21,3 @@ quote = { workspace = true } syn = { workspace = true } [dev-dependencies] - -[features] diff --git a/crates/pglt_flags/Cargo.toml b/crates/pglt_flags/Cargo.toml index eac82a48a..f3f5e40b6 100644 --- a/crates/pglt_flags/Cargo.toml +++ b/crates/pglt_flags/Cargo.toml @@ -15,5 +15,3 @@ version = "0.0.0" pglt_console = { workspace = true } [dev-dependencies] - -[features] diff --git a/crates/pglt_fs/Cargo.toml b/crates/pglt_fs/Cargo.toml index 11edb8778..8c3b237c5 100644 --- a/crates/pglt_fs/Cargo.toml +++ b/crates/pglt_fs/Cargo.toml @@ -20,14 +20,13 @@ pglt_diagnostics = { workspace = true } rayon = { workspace = true } rustc-hash = { workspace = true } schemars = { workspace = true, optional = true } -serde = { workspace = true } +serde = { workspace = true, optional = true } smallvec = { workspace = true } tracing = { workspace = true } [features] -serde = ["schemars", "pglt_diagnostics/schema"] - -[dev-dependencies] +schema = ["dep:schemars", "pglt_diagnostics/schema"] +serde = ["dep:serde"] [lib] doctest = false diff --git a/crates/pglt_fs/src/fs.rs b/crates/pglt_fs/src/fs.rs index 749e4fd7c..06844accd 100644 --- a/crates/pglt_fs/src/fs.rs +++ b/crates/pglt_fs/src/fs.rs @@ -18,14 +18,14 @@ mod os; pub struct ConfigName; impl ConfigName { - const PGLT_TOML: [&'static str; 1] = ["pglt.toml"]; + const PGLT_JSONC: [&'static str; 1] = ["pglt.jsonc"]; - pub const fn pglt_toml() -> &'static str { - Self::PGLT_TOML[0] + pub const fn pglt_jsonc() -> &'static str { + Self::PGLT_JSONC[0] } pub const fn file_names() -> [&'static str; 1] { - Self::PGLT_TOML + Self::PGLT_JSONC } } diff --git a/crates/pglt_fs/src/path.rs b/crates/pglt_fs/src/path.rs index cc481aea2..5d1cb20c6 100644 --- a/crates/pglt_fs/src/path.rs +++ b/crates/pglt_fs/src/path.rs @@ -17,13 +17,11 @@ use crate::ConfigName; #[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Ord, PartialOrd, Hash)] #[repr(u8)] #[bitflags] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema) -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[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 `pglt.toml` + /// A configuration file has the highest priority. It's usually `pglt.jsonc` /// /// Other third-party configuration files might be added in the future Config, @@ -85,10 +83,8 @@ impl From for FileKinds { } #[derive(Debug, Clone, Eq, PartialEq, Hash, Default)] -#[cfg_attr( - feature = "serde", - derive(serde::Serialize, serde::Deserialize, schemars::JsonSchema) -)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct PgLTPath { path: PathBuf, /// Determines the kind of the file inside PgLT. Some files are considered as configuration files, others as manifest files, and others as files to handle @@ -177,11 +173,10 @@ impl PgLTPath { } /// The priority of the file. - /// - `pglt.toml` has the highest priority - /// - `package.json` and `tsconfig.json`/`jsconfig.json` have the second-highest priority, and they are considered as manifest files + /// - `pglt.jsonc` has the highest priority /// - Other files are considered as files to handle fn priority(file_name: &OsStr) -> FileKinds { - if file_name == ConfigName::pglt_toml() { + if file_name == ConfigName::pglt_jsonc() { FileKind::Config.into() } else { FileKind::Handleable.into() @@ -201,7 +196,7 @@ impl PgLTPath { } } -#[cfg(feature = "serde")] +#[cfg(feature = "schema")] impl schemars::JsonSchema for FileKinds { fn schema_name() -> String { String::from("FileKind") diff --git a/crates/pglt_lsp/Cargo.toml b/crates/pglt_lsp/Cargo.toml index ddef9f9ac..29eb0e3ee 100644 --- a/crates/pglt_lsp/Cargo.toml +++ b/crates/pglt_lsp/Cargo.toml @@ -36,10 +36,7 @@ tracing = { workspace = true, features = ["attributes"] } pglt_test_utils = { workspace = true } sqlx = { workspace = true } tokio = { workspace = true, features = ["macros"] } -toml = { workspace = true } tower = { version = "0.4.13", features = ["timeout"] } [lib] doctest = false - -[features] diff --git a/crates/pglt_lsp/src/handlers/text_document.rs b/crates/pglt_lsp/src/handlers/text_document.rs index 78279cd11..8f28d6c80 100644 --- a/crates/pglt_lsp/src/handlers/text_document.rs +++ b/crates/pglt_lsp/src/handlers/text_document.rs @@ -7,7 +7,7 @@ use pglt_workspace::workspace::{ ChangeFileParams, ChangeParams, CloseFileParams, GetFileContentParams, OpenFileParams, }; use tower_lsp::lsp_types; -use tracing::{error, field}; +use tracing::error; /// Handler for `textDocument/didOpen` LSP notification #[tracing::instrument(level = "debug", skip(session), err)] diff --git a/crates/pglt_lsp/src/server.rs b/crates/pglt_lsp/src/server.rs index 584b7a95e..5fe0e1721 100644 --- a/crates/pglt_lsp/src/server.rs +++ b/crates/pglt_lsp/src/server.rs @@ -74,8 +74,9 @@ impl LSPServer { DidChangeWatchedFilesRegistrationOptions { watchers: vec![FileSystemWatcher { glob_pattern: GlobPattern::String(format!( - "{}/pglt.toml", - base_path.display() + "{}/{}", + base_path.display(), + ConfigName::pglt_jsonc() )), kind: Some(WatchKind::all()), },], @@ -148,7 +149,10 @@ impl LanguageServer for LSPServer { async fn initialized(&self, params: InitializedParams) { let _ = params; - info!("Attempting to load the configuration from 'pglt.toml' file"); + info!( + "Attempting to load the configuration from '{}' file", + ConfigName::pglt_jsonc() + ); futures::join!(self.session.load_workspace_settings()); @@ -188,8 +192,8 @@ impl LanguageServer for LSPServer { Ok(file_path) => { let base_path = self.session.base_path(); if let Some(base_path) = base_path { - let possible_config_toml = file_path.strip_prefix(&base_path); - if let Ok(watched_file) = possible_config_toml { + let possible_config_json = file_path.strip_prefix(&base_path); + if let Ok(watched_file) = possible_config_json { if ConfigName::file_names() .contains(&&*watched_file.display().to_string()) { diff --git a/crates/pglt_lsp/src/session.rs b/crates/pglt_lsp/src/session.rs index c74ab46bd..48457bcfb 100644 --- a/crates/pglt_lsp/src/session.rs +++ b/crates/pglt_lsp/src/session.rs @@ -400,7 +400,7 @@ impl Session { .map(|params| ¶ms.client_capabilities) } - /// This function attempts to read the `pglt.toml` configuration file from + /// This function attempts to read the `pglt.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) { diff --git a/crates/pglt_lsp/tests/server.rs b/crates/pglt_lsp/tests/server.rs index 6a4a76542..60bdb70cb 100644 --- a/crates/pglt_lsp/tests/server.rs +++ b/crates/pglt_lsp/tests/server.rs @@ -372,8 +372,8 @@ async fn test_database_connection() -> Result<()> { ..Default::default() }); fs.insert( - url!("pglt.toml").to_file_path().unwrap(), - toml::to_string(&conf).unwrap(), + url!("pglt.jsonc").to_file_path().unwrap(), + serde_json::to_string_pretty(&conf).unwrap(), ); let (service, client) = factory @@ -484,8 +484,8 @@ async fn test_completions() -> Result<()> { ..Default::default() }); fs.insert( - url!("pglt.toml").to_file_path().unwrap(), - toml::to_string(&conf).unwrap(), + url!("pglt.jsonc").to_file_path().unwrap(), + serde_json::to_string_pretty(&conf).unwrap(), ); let (service, client) = factory diff --git a/crates/pglt_lsp_converters/Cargo.toml b/crates/pglt_lsp_converters/Cargo.toml index c8bace046..9c83bf68a 100644 --- a/crates/pglt_lsp_converters/Cargo.toml +++ b/crates/pglt_lsp_converters/Cargo.toml @@ -21,5 +21,3 @@ tower-lsp = { version = "0.20.0" } [lib] doctest = false - -[features] diff --git a/crates/pglt_markup/Cargo.toml b/crates/pglt_markup/Cargo.toml index 80ef7ed24..f206c8e69 100644 --- a/crates/pglt_markup/Cargo.toml +++ b/crates/pglt_markup/Cargo.toml @@ -20,5 +20,3 @@ quote = "1.0.14" [lib] proc-macro = true - -[features] diff --git a/crates/pglt_text_edit/Cargo.toml b/crates/pglt_text_edit/Cargo.toml index 01bc0bbb7..7dc110efc 100644 --- a/crates/pglt_text_edit/Cargo.toml +++ b/crates/pglt_text_edit/Cargo.toml @@ -12,13 +12,14 @@ version = "0.0.0" [dependencies] -pglt_text_size = { workspace = true, features = ["serde"] } +pglt_text_size = { workspace = true } schemars = { workspace = true, optional = true } -serde = { workspace = true, features = ["derive"] } +serde = { workspace = true, features = ["derive"], optional = true } similar = { workspace = true, features = ["unicode"] } [features] -schemars = ["dep:schemars"] +schema = ["dep:schemars", "pglt_text_size/schema"] +serde = ["dep:serde", "pglt_text_size/serde"] [dev-dependencies] diff --git a/crates/pglt_text_edit/src/lib.rs b/crates/pglt_text_edit/src/lib.rs index 185bc1ca5..d5612114e 100644 --- a/crates/pglt_text_edit/src/lib.rs +++ b/crates/pglt_text_edit/src/lib.rs @@ -11,26 +11,40 @@ use std::{cmp::Ordering, num::NonZeroU32}; use pglt_text_size::{TextRange, TextSize}; -use serde::{Deserialize, Serialize}; pub use similar::ChangeTag; use similar::{TextDiff, utils::TextDiffRemapper}; -#[derive(Default, Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] +#[derive(Default, Debug, Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "camelCase") +)] pub struct TextEdit { dictionary: String, ops: Vec, } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "camelCase") +)] pub enum CompressedOp { DiffOp(DiffOp), EqualLines { line_count: NonZeroU32 }, } -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] -#[serde(rename_all = "snake_case")] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] +#[cfg_attr( + feature = "serde", + derive(serde::Serialize, serde::Deserialize), + serde(rename_all = "camelCase") +)] pub enum DiffOp { Equal { range: TextRange }, Insert { range: TextRange }, diff --git a/crates/pglt_text_size/Cargo.toml b/crates/pglt_text_size/Cargo.toml index ec5ce81f4..3e398fdb6 100644 --- a/crates/pglt_text_size/Cargo.toml +++ b/crates/pglt_text_size/Cargo.toml @@ -15,7 +15,7 @@ schemars = { workspace = true, optional = true } serde = { workspace = true, optional = true } [features] -schema = ["dep:schemars", "serde"] +schema = ["dep:schemars"] serde = ["dep:serde"] [dev-dependencies] diff --git a/crates/pglt_text_size/src/lib.rs b/crates/pglt_text_size/src/lib.rs index 92bd36b19..133f6192e 100644 --- a/crates/pglt_text_size/src/lib.rs +++ b/crates/pglt_text_size/src/lib.rs @@ -26,6 +26,9 @@ mod traits; #[cfg(feature = "serde")] mod serde_impls; +#[cfg(feature = "schema")] +mod schemars_impls; + pub use crate::{range::TextRange, size::TextSize, traits::TextLen}; #[cfg(target_pointer_width = "16")] diff --git a/crates/pglt_treesitter_queries/Cargo.toml b/crates/pglt_treesitter_queries/Cargo.toml index ed6e65b98..056b066a8 100644 --- a/crates/pglt_treesitter_queries/Cargo.toml +++ b/crates/pglt_treesitter_queries/Cargo.toml @@ -20,5 +20,3 @@ tree_sitter_sql.workspace = true [lib] doctest = false - -[features] diff --git a/crates/pglt_type_resolver/Cargo.toml b/crates/pglt_type_resolver/Cargo.toml index 929e8a919..d5afdc6da 100644 --- a/crates/pglt_type_resolver/Cargo.toml +++ b/crates/pglt_type_resolver/Cargo.toml @@ -19,5 +19,3 @@ pglt_schema_cache.workspace = true [lib] doctest = false - -[features] diff --git a/crates/pglt_typecheck/Cargo.toml b/crates/pglt_typecheck/Cargo.toml index 19fc7b65b..367939886 100644 --- a/crates/pglt_typecheck/Cargo.toml +++ b/crates/pglt_typecheck/Cargo.toml @@ -28,5 +28,3 @@ pglt_test_utils.workspace = true [lib] doctest = false - -[features] diff --git a/crates/pglt_workspace/Cargo.toml b/crates/pglt_workspace/Cargo.toml index a31d0141b..c746c0eff 100644 --- a/crates/pglt_workspace/Cargo.toml +++ b/crates/pglt_workspace/Cargo.toml @@ -29,19 +29,21 @@ pglt_statement_splitter = { workspace = true } pglt_text_size.workspace = true pglt_typecheck = { workspace = true } rustc-hash = { workspace = true } +schemars = { workspace = true, optional = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true, features = ["raw_value"] } sqlx.workspace = true tokio = { workspace = true, features = ["rt", "rt-multi-thread"] } -toml = { workspace = true } tracing = { workspace = true, features = ["attributes", "log"] } tree-sitter.workspace = true tree_sitter_sql.workspace = true + +[features] +schema = ["dep:schemars", "pglt_configuration/schema", "pglt_fs/schema"] + [dev-dependencies] tempfile = "3.15.0" [lib] doctest = false - -[features] diff --git a/crates/pglt_workspace/src/configuration.rs b/crates/pglt_workspace/src/configuration.rs index f9df091fe..45a3feca0 100644 --- a/crates/pglt_workspace/src/configuration.rs +++ b/crates/pglt_workspace/src/configuration.rs @@ -7,7 +7,7 @@ use std::{ use pglt_analyse::AnalyserRules; use pglt_configuration::{ ConfigurationDiagnostic, ConfigurationPathHint, ConfigurationPayload, PartialConfiguration, - push_to_analyser_rules, + VERSION, push_to_analyser_rules, }; use pglt_fs::{AutoSearchResult, ConfigName, FileSystem, OpenOptions}; @@ -97,9 +97,9 @@ fn load_config( // we'll load it directly if let ConfigurationPathHint::FromUser(ref config_file_path) = base_path { if file_system.path_is_file(config_file_path) { - let content = file_system.read_file_from_path(config_file_path)?; + let content = strip_jsonc_comments(&file_system.read_file_from_path(config_file_path)?); - let deserialized = toml::from_str::(&content) + let deserialized = serde_json::from_str::(&content) .map_err(ConfigurationDiagnostic::new_deserialization_error)?; return Ok(Some(ConfigurationPayload { @@ -120,7 +120,7 @@ fn load_config( ConfigurationPathHint::None => file_system.working_directory().unwrap_or_default(), }; - // We first search for `pgtoml.json` + // We first search for `pglt.jsonc` if let Some(auto_search_result) = file_system.auto_search( &configuration_directory, ConfigName::file_names().as_slice(), @@ -128,8 +128,9 @@ fn load_config( )? { let AutoSearchResult { content, file_path } = auto_search_result; - let deserialized = toml::from_str::(&content) - .map_err(ConfigurationDiagnostic::new_deserialization_error)?; + let deserialized = + serde_json::from_str::(&strip_jsonc_comments(&content)) + .map_err(ConfigurationDiagnostic::new_deserialization_error)?; Ok(Some(ConfigurationPayload { deserialized, @@ -150,9 +151,9 @@ fn load_config( /// - the program doesn't have the write rights pub fn create_config( fs: &mut DynRef, - configuration: PartialConfiguration, + configuration: &mut PartialConfiguration, ) -> Result<(), WorkspaceError> { - let path = PathBuf::from(ConfigName::pglt_toml()); + let path = PathBuf::from(ConfigName::pglt_jsonc()); if fs.path_exists(&path) { return Err(ConfigurationDiagnostic::new_already_exists().into()); @@ -168,7 +169,20 @@ pub fn create_config( } })?; - let contents = toml::ser::to_string_pretty(&configuration) + // we now check if pglt is installed inside `node_modules` and if so, we use the schema from there + if VERSION == "0.0.0" { + let schema_path = Path::new("./node_modules/@pglt/pglt/schema.json"); + let options = OpenOptions::default().read(true); + if fs.open_with_options(schema_path, options).is_ok() { + configuration.schema = schema_path.to_str().map(String::from); + } + } else { + configuration.schema = Some(format!( + "https://supabase-community.github.io/postgres_lsp/schemas/{VERSION}/schema.json" + )); + } + + let contents = serde_json::to_string_pretty(&configuration) .map_err(|_| ConfigurationDiagnostic::new_serialization_error())?; config_file @@ -186,3 +200,175 @@ pub fn to_analyser_rules(settings: &Settings) -> AnalyserRules { } analyser_rules } + +/// Takes a string of jsonc content and returns a comment free version +/// which should parse fine as regular json. +/// Nested block comments are supported. +pub fn strip_jsonc_comments(jsonc_input: &str) -> String { + let mut json_output = String::new(); + + let mut block_comment_depth: u8 = 0; + let mut is_in_string: bool = false; // Comments cannot be in strings + + for line in jsonc_input.split('\n') { + let mut last_char: Option = None; + for cur_char in line.chars() { + // Check whether we're in a string + if block_comment_depth == 0 && last_char != Some('\\') && cur_char == '"' { + is_in_string = !is_in_string; + } + + // Check for line comment start + if !is_in_string && last_char == Some('/') && cur_char == '/' { + last_char = None; + json_output.push_str(" "); + break; // Stop outputting or parsing this line + } + // Check for block comment start + if !is_in_string && last_char == Some('/') && cur_char == '*' { + block_comment_depth += 1; + last_char = None; + json_output.push_str(" "); + // Check for block comment end + } else if !is_in_string && last_char == Some('*') && cur_char == '/' { + block_comment_depth = block_comment_depth.saturating_sub(1); + last_char = None; + json_output.push_str(" "); + // Output last char if not in any block comment + } else { + if block_comment_depth == 0 { + if let Some(last_char) = last_char { + json_output.push(last_char); + } + } else { + json_output.push_str(" "); + } + last_char = Some(cur_char); + } + } + + // Add last char and newline if not in any block comment + if let Some(last_char) = last_char { + if block_comment_depth == 0 { + json_output.push(last_char); + } else { + json_output.push(' '); + } + } + + // Remove trailing whitespace from line + while json_output.ends_with(' ') { + json_output.pop(); + } + json_output.push('\n'); + } + + json_output +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_strip_jsonc_comments_line_comments() { + let input = r#"{ + "name": "test", // This is a line comment + "value": 42 // Another comment +}"#; + + let expected = r#"{ + "name": "test", + "value": 42 +} +"#; + + assert_eq!(strip_jsonc_comments(input), expected); + } + + #[test] + fn test_strip_jsonc_comments_block_comments() { + let input = r#"{ + /* This is a block comment */ + "name": "test", + "value": /* inline comment */ 42 +}"#; + + let expected = r#"{ + + "name": "test", + "value": 42 +} +"#; + + assert_eq!(strip_jsonc_comments(input), expected); + } + + #[test] + fn test_strip_jsonc_comments_nested_block_comments() { + let input = r#"{ + /* Outer comment /* Nested comment */ still outer */ + "name": "test" +}"#; + + let expected = r#"{ + + "name": "test" +} +"#; + + assert_eq!(strip_jsonc_comments(input), expected); + } + + #[test] + fn test_strip_jsonc_comments_in_strings() { + let input = r#"{ + "comment_like": "This is not a // comment", + "another": "This is not a /* block comment */ either" +}"#; + + let expected = r#"{ + "comment_like": "This is not a // comment", + "another": "This is not a /* block comment */ either" +} +"#; + + assert_eq!(strip_jsonc_comments(input), expected); + } + + #[test] + fn test_strip_jsonc_comments_escaped_quotes() { + let input = r#"{ + "escaped\": \"quote": "value", // Comment after escaped quotes + "normal": "value" // Normal comment +}"#; + + let expected = r#"{ + "escaped\": \"quote": "value", + "normal": "value" +} +"#; + + assert_eq!(strip_jsonc_comments(input), expected); + } + + #[test] + fn test_strip_jsonc_comments_multiline_block() { + let input = r#"{ + /* This is a + multiline block + comment */ + "name": "test" +}"#; + + let expected = r#"{ + + + + "name": "test" +} +"#; + + assert_eq!(strip_jsonc_comments(input), expected); + } +} diff --git a/crates/pglt_workspace/src/workspace.rs b/crates/pglt_workspace/src/workspace.rs index b765ee74e..1bd67cda4 100644 --- a/crates/pglt_workspace/src/workspace.rs +++ b/crates/pglt_workspace/src/workspace.rs @@ -13,6 +13,7 @@ mod client; mod server; #[derive(Debug, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct OpenFileParams { pub path: PgLTPath, pub content: String, @@ -20,11 +21,13 @@ pub struct OpenFileParams { } #[derive(Debug, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct CloseFileParams { pub path: PgLTPath, } #[derive(Debug, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct ChangeFileParams { pub path: PgLTPath, pub version: i32, @@ -32,6 +35,7 @@ pub struct ChangeFileParams { } #[derive(Debug, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct PullDiagnosticsParams { pub path: PgLTPath, pub categories: RuleCategories, @@ -41,6 +45,7 @@ pub struct PullDiagnosticsParams { } #[derive(Debug, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct CompletionParams { /// The File for which a completion is requested. pub path: PgLTPath, @@ -49,24 +54,15 @@ pub struct CompletionParams { } #[derive(Debug, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct PullDiagnosticsResult { pub diagnostics: Vec, pub errors: usize, pub skipped_diagnostics: u64, } -#[derive(Debug, Clone, Copy, serde::Serialize, serde::Deserialize, PartialEq)] -/// Which fixes should be applied during the analyzing phase -pub enum FixFileMode { - /// Applies [safe](pglt_diagnostics::Applicability::Always) fixes - SafeFixes, - /// Applies [safe](pglt_diagnostics::Applicability::Always) and [unsafe](pglt_diagnostics::Applicability::MaybeIncorrect) fixes - SafeAndUnsafeFixes, - /// Applies suppression comments to existing diagnostics when using `--suppress` - ApplySuppressions, -} - #[derive(Debug, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct ChangeParams { /// The range of the file that changed. If `None`, the whole file changed. pub range: Option, @@ -80,11 +76,13 @@ impl ChangeParams { } #[derive(Debug, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct IsPathIgnoredParams { pub pglt_path: PgLTPath, } #[derive(Debug, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct UpdateSettingsParams { pub configuration: PartialConfiguration, pub vcs_base_path: Option, @@ -94,11 +92,13 @@ pub struct UpdateSettingsParams { } #[derive(Debug, serde::Serialize, serde::Deserialize)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct GetFileContentParams { pub path: PgLTPath, } #[derive(Debug, Eq, PartialEq, Clone, Default, Deserialize, Serialize)] +#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct ServerInfo { /// The name of the server as defined by the server. pub name: String, diff --git a/crates/pglt_workspace/src/workspace/server.rs b/crates/pglt_workspace/src/workspace/server.rs index 4b4b9a6ee..bb90a2369 100644 --- a/crates/pglt_workspace/src/workspace/server.rs +++ b/crates/pglt_workspace/src/workspace/server.rs @@ -3,7 +3,7 @@ use std::{fs, panic::RefUnwindSafe, path::Path, sync::RwLock}; use analyser::AnalyserVisitorBuilder; use async_helper::run_async; use change::StatementChange; -use dashmap::{DashMap, DashSet}; +use dashmap::DashMap; use db_connection::DbConnection; use document::{Document, Statement}; use futures::{StreamExt, stream}; @@ -108,7 +108,7 @@ impl WorkspaceServer { fn is_ignored(&self, path: &Path) -> bool { let file_name = path.file_name().and_then(|s| s.to_str()); // Never ignore PgLT's config file regardless `include`/`ignore` - (file_name != Some(ConfigName::pglt_toml())) && + (file_name != Some(ConfigName::pglt_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/checking_migrations.md b/docs/checking_migrations.md index cf96614a2..6bd2c2483 100644 --- a/docs/checking_migrations.md +++ b/docs/checking_migrations.md @@ -8,13 +8,16 @@ To run it, simply point at your migrations directory. pglt 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 `migrations_dir` and `after` to your `pglt.toml` 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 `pglt.jsonc` file -```toml -[migrations] -migrations_dir = "supabase/migrations" -after = 1740868021 +```json +{ + "migrations": { + "migrationsDir": "supabase/migrations", + "after": 1740868021 + } +} ``` Alternatively, pass them directly. @@ -25,5 +28,5 @@ pglt check supabase/migrations --migrations-dir="supabase/migrations" --after=17 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 `pglt.toml`, 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 `pglt.jsonc`, use `--since=REF` to specify the base branch to compare against. diff --git a/docs/cli_reference.md b/docs/cli_reference.md index 2dfe7ee6d..919b0d3e3 100644 --- a/docs/cli_reference.md +++ b/docs/cli_reference.md @@ -62,7 +62,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 `pglt.toml`. If used, it disables the default configuration file resolution. + Set the file path to the configuration file, or the directory path to find `pglt.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. @@ -111,7 +111,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 `pglt.toml` was found. + The folder where we should check for VCS files. By default, we will use the same folder where `pglt.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`_ — @@ -149,7 +149,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 `pglt.toml`. If used, it disables the default configuration file resolution. + Set the file path to the configuration file, or the directory path to find `pglt.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. @@ -197,7 +197,7 @@ 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 `pglt.toml` + 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 `pglt.jsonc` - **`-h`**, **`--help`** — Prints help information @@ -220,7 +220,7 @@ Starts the daemon server process. Uses environment variable **`PGLT_LOG_PATH`** - **` --config-path`**=_`PATH`_ — - Allows to set a custom file path to the configuration file, or a custom directory path to find `pglt.toml` + Allows to set a custom file path to the configuration file, or a custom directory path to find `pglt.jsonc` Uses environment variable **`PGLT_LOG_PREFIX_NAME`** - **`-h`**, **`--help`** — @@ -267,7 +267,7 @@ Acts as a server for the Language Server Protocol over stdin/stdout. Uses environment variable **`PGLT_LOG_PATH`** - **` --config-path`**=_`PATH`_ — - Allows to set a custom file path to the configuration file, or a custom directory path to find `pglt.toml` + Allows to set a custom file path to the configuration file, or a custom directory path to find `pglt.jsonc` Uses environment variable **`PGLT_CONFIG_PATH`** - **`-h`**, **`--help`** — diff --git a/docs/codegen/Cargo.toml b/docs/codegen/Cargo.toml index 646490f82..ba1bc52f3 100644 --- a/docs/codegen/Cargo.toml +++ b/docs/codegen/Cargo.toml @@ -13,7 +13,6 @@ version = "0.0.0" [dependencies] regex = { workspace = true } -toml = { workspace = true } anyhow = { workspace = true } bpaf = { workspace = true, features = ["docgen"] } schemars = { workspace = true } diff --git a/docs/codegen/src/default_configuration.rs b/docs/codegen/src/default_configuration.rs index 12f305b82..1a9bdadd7 100644 --- a/docs/codegen/src/default_configuration.rs +++ b/docs/codegen/src/default_configuration.rs @@ -8,8 +8,8 @@ pub fn generate_default_configuration(docs_dir: &Path) -> anyhow::Result<()> { let index_path = docs_dir.join("index.md"); let printed_config = format!( - "\n```toml\n{}```\n", - toml::ser::to_string_pretty(&PartialConfiguration::init())? + "\n```json\n{}```\n", + serde_json::to_string_pretty(&PartialConfiguration::init())? ); let data = fs::read_to_string(&index_path)?; diff --git a/docs/codegen/src/rules_docs.rs b/docs/codegen/src/rules_docs.rs index d62435921..c9dc1615d 100644 --- a/docs/codegen/src/rules_docs.rs +++ b/docs/codegen/src/rules_docs.rs @@ -113,14 +113,22 @@ fn write_how_to_configure( content: &mut Vec, ) -> io::Result<()> { writeln!(content, "## How to configure")?; - let toml = format!( - r#"[linter.rules.{group}] -{rule} = "error" + let json = format!( + r#" +{{ + "linter": {{ + "rules": {{ + "{group}": {{ + "{rule}": "error" + }} + }} + }} +}} "# ); - writeln!(content, "```toml")?; - writeln!(content, "{}", toml)?; + writeln!(content, "```json")?; + writeln!(content, "{}", json)?; writeln!(content, "```")?; Ok(()) diff --git a/docs/codegen/src/utils.rs b/docs/codegen/src/utils.rs index 5646468eb..ac8cef08b 100644 --- a/docs/codegen/src/utils.rs +++ b/docs/codegen/src/utils.rs @@ -12,8 +12,13 @@ pub(crate) fn replace_section( section_identifier, section_identifier ); let re = Regex::new(&pattern).unwrap(); - re.replace_all(content, format!("${{1}}{}${{2}}", replacement)) - .to_string() + + // Use a replacement function instead of a replacement string to avoid + // issues with special characters like $ in the replacement text + re.replace_all(content, |caps: ®ex::Captures| { + format!("{}{}{}", &caps[1], replacement, &caps[2]) + }) + .to_string() } #[derive(Default)] diff --git a/docs/index.md b/docs/index.md index 0e417a21d..ffbafd3ce 100644 --- a/docs/index.md +++ b/docs/index.md @@ -29,39 +29,42 @@ Our current focus is on refining and enhancing these core features while buildin ## Configuration -We recommend that you create a `pglt.toml` configuration file for each project. This eliminates the need to repeat the CLI options each time you run a command, and ensures that we use the same configuration in your editor. Some options are also only available from a configuration file. If you are happy with the defaults, you don’t need to create a configuration file. To create the `pglt.toml` file, run the `init` command in the root folder of your project: +We recommend that you create a `pglt.jsonc` configuration file for each project. This eliminates the need to repeat the CLI options each time you run a command, and ensures that we use the same configuration in your editor. Some options are also only available from a configuration file. If you are happy with the defaults, you don’t need to create a configuration file. To create the `pglt.jsonc` file, run the `init` command in the root folder of your project: ```sh pglt init ``` -After running the `init` command, you’ll have a new `pglt.toml` file in your directory: +After running the `init` command, you’ll have a `pglt.jsonc` file in your directory: [//]: # (BEGIN DEFAULT_CONFIGURATION) -```toml -[vcs] -enabled = false -client_kind = "git" -use_ignore_file = false - -[files] -ignore = [] - -[linter] -enabled = true - -[linter.rules] -recommended = true - -[db] -host = "127.0.0.1" -port = 5432 -username = "postgres" -password = "postgres" -database = "postgres" -conn_timeout_secs = 10 -``` +```json +{ + "$schema": "https://supabase-community.github.io/postgres_lsp/schemas/0.0.0/schema.json", + "vcs": { + "enabled": false, + "clientKind": "git", + "useIgnoreFile": false + }, + "files": { + "ignore": [] + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true + } + }, + "db": { + "host": "127.0.0.1", + "port": 5432, + "username": "postgres", + "password": "postgres", + "database": "postgres", + "connTimeoutSecs": 10 + } +}``` [//]: # (END DEFAULT_CONFIGURATION) diff --git a/docs/linting_migrations.md b/docs/linting_migrations.md deleted file mode 100644 index ce69283a6..000000000 --- a/docs/linting_migrations.md +++ /dev/null @@ -1,29 +0,0 @@ -# Linting Migrations - -Postgres Language Tools comes with a `check` command that can be integrated into your development workflow to catch problematic schema changes and encourage best practices. - -To run it, simply point at your migrations directory. - -```sh -pglt 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 `migrations_dir` and `after` to your `pglt.toml` file - - -```toml -[migrations] -migrations_dir = "supabase/migrations" -after = 1740868021 -``` - -Alternatively, pass them directly. - -``` -pglt 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 `defaultBranch` configuration. If `defaultBranch` is not set in your `pglt.toml`, use `--since=REF` to specify the base branch to compare against. - diff --git a/docs/rules/adding-required-field.md b/docs/rules/adding-required-field.md index ee4a85182..63dea2818 100644 --- a/docs/rules/adding-required-field.md +++ b/docs/rules/adding-required-field.md @@ -24,8 +24,16 @@ alter table test add column count int not null; alter table test add column count int not null default 0; ## How to configure -```toml -[linter.rules.safety] -addingRequiredField = "error" +```json + +{ + "linter": { + "rules": { + "safety": { + "addingRequiredField": "error" + } + } + } +} ``` diff --git a/docs/rules/ban-drop-column.md b/docs/rules/ban-drop-column.md index a06ae41dc..49a0d054b 100644 --- a/docs/rules/ban-drop-column.md +++ b/docs/rules/ban-drop-column.md @@ -35,8 +35,16 @@ code-block.sql lint/safety/banDropColumn ━━━━━━━━━━━━━ ``` ## How to configure -```toml -[linter.rules.safety] -banDropColumn = "error" +```json + +{ + "linter": { + "rules": { + "safety": { + "banDropColumn": "error" + } + } + } +} ``` diff --git a/docs/rules/ban-drop-not-null.md b/docs/rules/ban-drop-not-null.md index 449812fe0..ccf49f956 100644 --- a/docs/rules/ban-drop-not-null.md +++ b/docs/rules/ban-drop-not-null.md @@ -35,8 +35,16 @@ code-block.sql lint/safety/banDropNotNull ━━━━━━━━━━━━ ``` ## How to configure -```toml -[linter.rules.safety] -banDropNotNull = "error" +```json + +{ + "linter": { + "rules": { + "safety": { + "banDropNotNull": "error" + } + } + } +} ``` diff --git a/docs/rules/ban-drop-table.md b/docs/rules/ban-drop-table.md index d814b8bc9..f2f341561 100644 --- a/docs/rules/ban-drop-table.md +++ b/docs/rules/ban-drop-table.md @@ -36,8 +36,16 @@ code-block.sql lint/safety/banDropTable ━━━━━━━━━━━━━ ``` ## How to configure -```toml -[linter.rules.safety] -banDropTable = "error" +```json + +{ + "linter": { + "rules": { + "safety": { + "banDropTable": "error" + } + } + } +} ``` diff --git a/docs/schemas/0.0.0/schema.json b/docs/schemas/0.0.0/schema.json index 05981eb0b..5595cb6b9 100644 --- a/docs/schemas/0.0.0/schema.json +++ b/docs/schemas/0.0.0/schema.json @@ -4,6 +4,13 @@ "description": "The configuration that is contained inside the configuration file.", "type": "object", "properties": { + "$schema": { + "description": "A field for the [JSON schema](https://json-schema.org/) specification", + "type": [ + "string", + "null" + ] + }, "db": { "description": "The configuration of the database connection", "anyOf": [ @@ -66,7 +73,7 @@ "description": "The configuration of the database connection.", "type": "object", "properties": { - "conn_timeout_secs": { + "connTimeoutSecs": { "description": "The connection timeout in seconds.", "type": [ "integer", @@ -141,7 +148,7 @@ } ] }, - "max_size": { + "maxSize": { "description": "The maximum allowed size for source code files in bytes. Files above this limit will be ignored for performance reasons. Defaults to 1 MiB", "type": [ "integer", @@ -212,7 +219,7 @@ "format": "uint64", "minimum": 0.0 }, - "migrations_dir": { + "migrationsDir": { "description": "The directory where the migration files are stored", "type": [ "string", @@ -375,7 +382,7 @@ "description": "Set of properties to integrate with a VCS software.", "type": "object", "properties": { - "client_kind": { + "clientKind": { "description": "The kind of client.", "anyOf": [ { @@ -386,7 +393,7 @@ } ] }, - "default_branch": { + "defaultBranch": { "description": "The main branch of the project", "type": [ "string", @@ -401,13 +408,13 @@ ] }, "root": { - "description": "The folder where we should check for VCS files. By default, we will use the same folder where `pglt.toml` 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 `pglt.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" ] }, - "use_ignore_file": { + "useIgnoreFile": { "description": "Whether we should use the VCS ignore file. When [true], we will ignore the files specified in the ignore file.", "type": [ "boolean", diff --git a/docs/schemas/latest/schema.json b/docs/schemas/latest/schema.json index 05981eb0b..5595cb6b9 100644 --- a/docs/schemas/latest/schema.json +++ b/docs/schemas/latest/schema.json @@ -4,6 +4,13 @@ "description": "The configuration that is contained inside the configuration file.", "type": "object", "properties": { + "$schema": { + "description": "A field for the [JSON schema](https://json-schema.org/) specification", + "type": [ + "string", + "null" + ] + }, "db": { "description": "The configuration of the database connection", "anyOf": [ @@ -66,7 +73,7 @@ "description": "The configuration of the database connection.", "type": "object", "properties": { - "conn_timeout_secs": { + "connTimeoutSecs": { "description": "The connection timeout in seconds.", "type": [ "integer", @@ -141,7 +148,7 @@ } ] }, - "max_size": { + "maxSize": { "description": "The maximum allowed size for source code files in bytes. Files above this limit will be ignored for performance reasons. Defaults to 1 MiB", "type": [ "integer", @@ -212,7 +219,7 @@ "format": "uint64", "minimum": 0.0 }, - "migrations_dir": { + "migrationsDir": { "description": "The directory where the migration files are stored", "type": [ "string", @@ -375,7 +382,7 @@ "description": "Set of properties to integrate with a VCS software.", "type": "object", "properties": { - "client_kind": { + "clientKind": { "description": "The kind of client.", "anyOf": [ { @@ -386,7 +393,7 @@ } ] }, - "default_branch": { + "defaultBranch": { "description": "The main branch of the project", "type": [ "string", @@ -401,13 +408,13 @@ ] }, "root": { - "description": "The folder where we should check for VCS files. By default, we will use the same folder where `pglt.toml` 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 `pglt.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" ] }, - "use_ignore_file": { + "useIgnoreFile": { "description": "Whether we should use the VCS ignore file. When [true], we will ignore the files specified in the ignore file.", "type": [ "boolean", diff --git a/pglt.jsonc b/pglt.jsonc new file mode 100644 index 000000000..ee9eccc16 --- /dev/null +++ b/pglt.jsonc @@ -0,0 +1,26 @@ +{ + "$schema": "./docs/schemas/latest/schema.json", + "vcs": { + "enabled": false, + "clientKind": "git", + "useIgnoreFile": false + }, + "files": { + "ignore": [] + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true + } + }, + // YOU CAN COMMENT ME OUT :) + "db": { + "host": "127.0.0.1", + "port": 5432, + "username": "postgres", + "password": "postgres", + "database": "postgres", + "connTimeoutSecs": 10 + } +} diff --git a/pglt.toml b/pglt.toml deleted file mode 100644 index 5d0f672a8..000000000 --- a/pglt.toml +++ /dev/null @@ -1,21 +0,0 @@ -[vcs] -enabled = false -client_kind = "git" -use_ignore_file = false - -[files] -ignore = [] - -[linter] -enabled = true - -[linter.rules] -recommended = true - -[db] -host = "127.0.0.1" -port = 5432 -username = "postgres" -password = "postgres" -database = "postgres" -conn_timeout_secs = 10