Skip to content

Commit 379ade4

Browse files
chore(docs): initial commit (#204)
* chore(docs): initial commit * feat(docs): poc for codegen * docs: troubleshooting * feat(docs): finish codegen * fix: docs * fix: diagnostics in docs * fix: docs * fix: docs * fix: lint * feat: integrate docs codegen into ci * Update docs/codegen/src/utils.rs Co-authored-by: Julian Domke <[email protected]> * chore: merge main * chore: lint fix * chore: lint fix --------- Co-authored-by: Julian Domke <[email protected]>
1 parent 6933732 commit 379ade4

35 files changed

+1486
-38
lines changed

.github/workflows/pull_request.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ jobs:
181181
run: cargo run -p xtask_codegen -- analyser
182182
- name: Run the configuration codegen
183183
run: cargo run -p xtask_codegen -- configuration
184+
- name: Run the docs codegen
185+
run: cargo run -p docs_codegen
184186
- name: Check for git diff
185187
run: |
186188
if [[ $(git status --porcelain) ]]; then

Cargo.lock

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace]
2-
members = ["crates/*", "lib/*", "xtask/codegen", "xtask/rules_check"]
2+
members = ["crates/*", "lib/*", "xtask/codegen", "xtask/rules_check", "docs/codegen"]
33
resolver = "2"
44

55
[workspace.package]
@@ -28,6 +28,7 @@ pg_query = "6.0.0"
2828
proc-macro2 = "1.0.66"
2929
quote = "1.0.33"
3030
rayon = "1.10.0"
31+
regex = "1.11.1"
3132
rustc-hash = "2.0.0"
3233
schemars = { version = "0.8.21", features = ["indexmap2", "smallvec"] }
3334
serde = "1.0.195"
@@ -80,6 +81,8 @@ pglt_workspace = { path = "./crates/pglt_workspace", version = "0.0
8081

8182
pglt_test_macros = { path = "./crates/pglt_test_macros" }
8283
pglt_test_utils = { path = "./crates/pglt_test_utils" }
83-
# parser = { path = "./crates/parser", version = "0.0.0" }
84-
# sql_parser = { path = "./crates/sql_parser", version = "0.0.0" }
85-
# sql_parser_codegen = { path = "./crates/sql_parser_codegen", version = "0.0.0" }
84+
85+
docs_codegen = { path = "./docs/codegen", version = "0.0.0" }
86+
87+
[profile.dev.package]
88+
insta.opt-level = 3

crates/pglt_analyser/tests/rules_tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ fn rule_test(full_path: &'static str, _: &str, _: &str) {
2323
};
2424

2525
let query =
26-
read_to_string(full_path).expect(format!("Failed to read file: {} ", full_path).as_str());
26+
read_to_string(full_path).unwrap_or_else(|_| panic!("Failed to read file: {} ", full_path));
2727

2828
let ast = pglt_query_ext::parse(&query).expect("failed to parse SQL");
2929
let options = AnalyserOptions::default();
@@ -51,7 +51,6 @@ fn rule_test(full_path: &'static str, _: &str, _: &str) {
5151
fn parse_test_path(path: &Path) -> (String, String, String) {
5252
let mut comps: Vec<&str> = path
5353
.components()
54-
.into_iter()
5554
.map(|c| c.as_os_str().to_str().unwrap())
5655
.collect();
5756

crates/pglt_cli/src/cli_options.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pub struct CliOptions {
4848
#[bpaf(long("no-errors-on-unmatched"), switch)]
4949
pub no_errors_on_unmatched: bool,
5050

51-
/// Tell PGLSP to exit with an error code if some diagnostics emit warnings.
51+
/// Tell PgLT to exit with an error code if some diagnostics emit warnings.
5252
#[bpaf(long("error-on-warnings"), switch)]
5353
pub error_on_warnings: bool,
5454

@@ -86,7 +86,7 @@ pub struct CliOptions {
8686
fallback(Severity::default()),
8787
display_fallback
8888
)]
89-
/// The level of diagnostics to show. In order, from the lowest to the most important: info, warn, error. Passing `--diagnostic-level=error` will cause PGLSP to print only diagnostics that contain only errors.
89+
/// The level of diagnostics to show. In order, from the lowest to the most important: info, warn, error. Passing `--diagnostic-level=error` will cause PgLT to print only diagnostics that contain only errors.
9090
pub diagnostic_level: Severity,
9191
}
9292

crates/pglt_cli/src/commands/daemon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ fn setup_tracing_subscriber(log_path: Option<PathBuf>, log_file_name_prefix: Opt
230230
}
231231

232232
pub fn default_pglt_log_path() -> PathBuf {
233-
match env::var_os("PGLSP_LOG_PATH") {
233+
match env::var_os("PGLT_LOG_PATH") {
234234
Some(directory) => PathBuf::from(directory),
235235
None => pglt_fs::ensure_cache_dir().join("pglt-logs"),
236236
}

crates/pglt_cli/src/commands/mod.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ pub enum PgltCommand {
7272
Start {
7373
/// Allows to change the prefix applied to the file name of the logs.
7474
#[bpaf(
75-
env("PGLSP_LOG_PREFIX_NAME"),
75+
env("PGLT_LOG_PREFIX_NAME"),
7676
long("log-prefix-name"),
7777
argument("STRING"),
7878
hide_usage,
@@ -83,7 +83,7 @@ pub enum PgltCommand {
8383

8484
/// Allows to change the folder where logs are stored.
8585
#[bpaf(
86-
env("PGLSP_LOG_PATH"),
86+
env("PGLT_LOG_PATH"),
8787
long("log-path"),
8888
argument("PATH"),
8989
hide_usage,
@@ -92,7 +92,7 @@ pub enum PgltCommand {
9292
log_path: PathBuf,
9393
/// Allows to set a custom file path to the configuration file,
9494
/// or a custom directory path to find `pglt.toml`
95-
#[bpaf(env("PGLSP_LOG_PREFIX_NAME"), long("config-path"), argument("PATH"))]
95+
#[bpaf(env("PGLT_LOG_PREFIX_NAME"), long("config-path"), argument("PATH"))]
9696
config_path: Option<PathBuf>,
9797
},
9898

@@ -109,7 +109,7 @@ pub enum PgltCommand {
109109
LspProxy {
110110
/// Allows to change the prefix applied to the file name of the logs.
111111
#[bpaf(
112-
env("PGLSP_LOG_PREFIX_NAME"),
112+
env("PGLT_LOG_PREFIX_NAME"),
113113
long("log-prefix-name"),
114114
argument("STRING"),
115115
hide_usage,
@@ -119,7 +119,7 @@ pub enum PgltCommand {
119119
log_prefix_name: String,
120120
/// Allows to change the folder where logs are stored.
121121
#[bpaf(
122-
env("PGLSP_LOG_PATH"),
122+
env("PGLT_LOG_PATH"),
123123
long("log-path"),
124124
argument("PATH"),
125125
hide_usage,
@@ -128,7 +128,7 @@ pub enum PgltCommand {
128128
log_path: PathBuf,
129129
/// Allows to set a custom file path to the configuration file,
130130
/// or a custom directory path to find `pglt.toml`
131-
#[bpaf(env("PGLSP_CONFIG_PATH"), long("config-path"), argument("PATH"))]
131+
#[bpaf(env("PGLT_CONFIG_PATH"), long("config-path"), argument("PATH"))]
132132
config_path: Option<PathBuf>,
133133
/// Bogus argument to make the command work with vscode-languageclient
134134
#[bpaf(long("stdio"), hide, hide_usage, switch)]
@@ -143,7 +143,7 @@ pub enum PgltCommand {
143143
RunServer {
144144
/// Allows to change the prefix applied to the file name of the logs.
145145
#[bpaf(
146-
env("PGLSP_LOG_PREFIX_NAME"),
146+
env("PGLT_LOG_PREFIX_NAME"),
147147
long("log-prefix-name"),
148148
argument("STRING"),
149149
hide_usage,
@@ -153,7 +153,7 @@ pub enum PgltCommand {
153153
log_prefix_name: String,
154154
/// Allows to change the folder where logs are stored.
155155
#[bpaf(
156-
env("PGLSP_LOG_PATH"),
156+
env("PGLT_LOG_PATH"),
157157
long("log-path"),
158158
argument("PATH"),
159159
hide_usage,
@@ -165,7 +165,7 @@ pub enum PgltCommand {
165165
stop_on_disconnect: bool,
166166
/// Allows to set a custom file path to the configuration file,
167167
/// or a custom directory path to find `pglt.toml`
168-
#[bpaf(env("PGLSP_CONFIG_PATH"), long("config-path"), argument("PATH"))]
168+
#[bpaf(env("PGLT_CONFIG_PATH"), long("config-path"), argument("PATH"))]
169169
config_path: Option<PathBuf>,
170170
},
171171
#[bpaf(command("__print_socket"), hide)]

crates/pglt_cli/src/diagnostics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn command_name() -> String {
1515
.unwrap_or_else(|| String::from("pglt"))
1616
}
1717

18-
/// A diagnostic that is emitted when running PGLSP via CLI.
18+
/// A diagnostic that is emitted when running PgLT via CLI.
1919
///
2020
/// When displaying the diagnostic,
2121
#[derive(Debug, Diagnostic)]

crates/pglt_cli/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub use panic::setup_panic_handler;
3232
pub use reporter::{DiagnosticsPayload, Reporter, ReporterVisitor, TraversalSummary};
3333
pub use service::{open_transport, SocketTransport};
3434

35-
pub(crate) const VERSION: &str = match option_env!("PGLSP_VERSION") {
35+
pub(crate) const VERSION: &str = match option_env!("PGLT_VERSION") {
3636
Some(version) => version,
3737
None => env!("CARGO_PKG_VERSION"),
3838
};

crates/pglt_configuration/src/analyser/linter/rules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl std::str::FromStr for RuleGroup {
4646
#[cfg_attr(feature = "schema", derive(JsonSchema))]
4747
#[serde(rename_all = "camelCase", deny_unknown_fields)]
4848
pub struct Rules {
49-
#[doc = r" It enables the lint rules recommended by PGLSP. `true` by default."]
49+
#[doc = r" It enables the lint rules recommended by PgLT. `true` by default."]
5050
#[serde(skip_serializing_if = "Option::is_none")]
5151
pub recommended: Option<bool>,
5252
#[doc = r" It enables ALL rules. The rules that belong to `nursery` won't be enabled."]

crates/pglt_configuration/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use migrations::{
3434
use serde::{Deserialize, Serialize};
3535
use vcs::VcsClientKind;
3636

37-
pub const VERSION: &str = match option_env!("PGLSP_VERSION") {
37+
pub const VERSION: &str = match option_env!("PGLT_VERSION") {
3838
Some(version) => version,
3939
None => "0.0.0",
4040
};

crates/pglt_flags/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,33 +8,33 @@ use std::sync::{LazyLock, OnceLock};
88

99
/// Returns `true` if this is an unstable build of PgLT
1010
pub fn is_unstable() -> bool {
11-
PGLSP_VERSION.deref().is_none()
11+
PGLT_VERSION.deref().is_none()
1212
}
1313

1414
/// The internal version of PgLT. This is usually supplied during the CI build
15-
pub static PGLSP_VERSION: LazyLock<Option<&str>> = LazyLock::new(|| option_env!("PGLSP_VERSION"));
15+
pub static PGLT_VERSION: LazyLock<Option<&str>> = LazyLock::new(|| option_env!("PGLT_VERSION"));
1616

1717
pub struct PgLTEnv {
1818
pub pglt_log_path: PgLTEnvVariable,
1919
pub pglt_log_prefix: PgLTEnvVariable,
2020
pub pglt_config_path: PgLTEnvVariable,
2121
}
2222

23-
pub static PGLSP_ENV: OnceLock<PgLTEnv> = OnceLock::new();
23+
pub static PGLT_ENV: OnceLock<PgLTEnv> = OnceLock::new();
2424

2525
impl PgLTEnv {
2626
fn new() -> Self {
2727
Self {
2828
pglt_log_path: PgLTEnvVariable::new(
29-
"PGLSP_LOG_PATH",
29+
"PGLT_LOG_PATH",
3030
"The directory where the Daemon logs will be saved.",
3131
),
3232
pglt_log_prefix: PgLTEnvVariable::new(
33-
"PGLSP_LOG_PREFIX_NAME",
33+
"PGLT_LOG_PREFIX_NAME",
3434
"A prefix that's added to the name of the log. Default: `server.log.`",
3535
),
3636
pglt_config_path: PgLTEnvVariable::new(
37-
"PGLSP_CONFIG_PATH",
37+
"PGLT_CONFIG_PATH",
3838
"A path to the configuration file",
3939
),
4040
}
@@ -71,7 +71,7 @@ impl PgLTEnvVariable {
7171
}
7272

7373
pub fn pglt_env() -> &'static PgLTEnv {
74-
PGLSP_ENV.get_or_init(PgLTEnv::new)
74+
PGLT_ENV.get_or_init(PgLTEnv::new)
7575
}
7676

7777
impl Display for PgLTEnv {

crates/pglt_fs/src/fs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ mod os;
1818
pub struct ConfigName;
1919

2020
impl ConfigName {
21-
const PGLSP_TOML: [&'static str; 1] = ["pglt.toml"];
21+
const PGLT_TOML: [&'static str; 1] = ["pglt.toml"];
2222

2323
pub const fn pglt_toml() -> &'static str {
24-
Self::PGLSP_TOML[0]
24+
Self::PGLT_TOML[0]
2525
}
2626

2727
pub const fn file_names() -> [&'static str; 1] {
28-
Self::PGLSP_TOML
28+
Self::PGLT_TOML
2929
}
3030
}
3131

crates/pglt_fs/src/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl From<FileKind> for FileKinds {
9191
)]
9292
pub struct PgLTPath {
9393
path: PathBuf,
94-
/// Determines the kind of the file inside PGLSP. Some files are considered as configuration files, others as manifest files, and others as files to handle
94+
/// 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
9595
kind: FileKinds,
9696
/// Whether this path (usually a file) was fixed as a result of a format/lint/check command with the `--write` filag.
9797
was_written: bool,
@@ -164,7 +164,7 @@ impl PgLTPath {
164164
/// Returns the contents of a file, if it exists
165165
///
166166
/// ## Error
167-
/// If PGLSP doesn't have permissions to read the file
167+
/// If PgLT doesn't have permissions to read the file
168168
pub fn get_buffer_from_file(&mut self) -> String {
169169
// we assume we have permissions
170170
read_to_string(&self.path).expect("cannot read the file to format")

crates/pglt_workspace/src/workspace/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ impl WorkspaceServer {
111111
/// Check whether a file is ignored in the top-level config `files.ignore`/`files.include`
112112
fn is_ignored(&self, path: &Path) -> bool {
113113
let file_name = path.file_name().and_then(|s| s.to_str());
114-
// Never ignore PGLSP's config file regardless `include`/`ignore`
114+
// Never ignore PgLT's config file regardless `include`/`ignore`
115115
(file_name != Some(ConfigName::pglt_toml())) &&
116116
// Apply top-level `include`/`ignore
117117
(self.is_ignored_by_top_level_config(path) || self.is_ignored_by_migration_config(path))
@@ -130,7 +130,7 @@ impl WorkspaceServer {
130130
// `matched_path_or_any_parents` panics if `source` is not under the gitignore root.
131131
// This checks excludes absolute paths that are not a prefix of the base root.
132132
if !path.has_root() || path.starts_with(ignore.path()) {
133-
// Because PGLSP passes a list of paths,
133+
// Because PgLT passes a list of paths,
134134
// we use `matched_path_or_any_parents` instead of `matched`.
135135
ignore
136136
.matched_path_or_any_parents(path, path.is_dir())

0 commit comments

Comments
 (0)