Skip to content

chore: rust 2024 #224

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Mar 10, 2025
Merged
10 changes: 5 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ resolver = "2"
[workspace.package]
authors = ["Supabase Communnity"]
categories = ["development-tools", "postgres", "supabase"]
edition = "2021"
edition = "2024"
homepage = "https://supabase.com/"
keywords = ["linter", "typechecker", "postgres", "language-server"]
license = "MIT"
repository = "https://github.com/supabase-community/postgres_lsp"
rust-version = "1.82.0"
rust-version = "1.85.0"

[workspace.dependencies]
# supporting crates unrelated to postgres
Expand All @@ -31,7 +31,7 @@ quote = "1.0.33"
rayon = "1.10.0"
regex = "1.11.1"
rustc-hash = "2.0.0"
schemars = { version = "0.8.21", features = ["indexmap2", "smallvec"] }
schemars = { version = "0.8.22", features = ["indexmap2", "smallvec"] }
serde = "1.0.195"
serde_json = "1.0.114"
similar = "2.6.0"
Expand Down
6 changes: 3 additions & 3 deletions crates/pglt_analyse/src/categories.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use enumflags2::{bitflags, BitFlags};
use enumflags2::{BitFlags, bitflags};
use std::borrow::Cow;

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
Expand Down Expand Up @@ -288,8 +288,8 @@ impl schemars::JsonSchema for RuleCategories {
String::from("RuleCategories")
}

fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
<Vec<RuleCategory>>::json_schema(gen)
fn json_schema(r#gen: &mut schemars::r#gen::SchemaGenerator) -> schemars::schema::Schema {
<Vec<RuleCategory>>::json_schema(r#gen)
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_analyse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub use pglt_diagnostics::category_concat;

pub use crate::categories::{
ActionCategory, RefactorKind, RuleCategories, RuleCategoriesBuilder, RuleCategory,
SourceActionKind, SUPPRESSION_ACTION_CATEGORY,
SUPPRESSION_ACTION_CATEGORY, SourceActionKind,
};
pub use crate::filter::{AnalysisFilter, GroupKey, RuleFilter, RuleKey};
pub use crate::options::{AnalyserOptions, AnalyserRules};
Expand Down
4 changes: 2 additions & 2 deletions crates/pglt_analyse/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ macro_rules! declare_lint_rule {
( $( #[doc = $doc:literal] )+ $vis:vis $id:ident {
version: $version:literal,
name: $name:tt,
$( $key:ident: $value:expr, )*
$( $key:ident: $value:expr_2021, )*
} ) => {

pglt_analyse::declare_rule!(
Expand Down Expand Up @@ -53,7 +53,7 @@ macro_rules! declare_rule {
( $( #[doc = $doc:literal] )+ $vis:vis $id:ident {
version: $version:literal,
name: $name:tt,
$( $key:ident: $value:expr, )*
$( $key:ident: $value:expr_2021, )*
} ) => {
$( #[doc = $doc] )*
$vis enum $id {}
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_analyse/src/registry.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::{borrow, collections::BTreeSet};

use crate::{
AnalyserOptions,
context::RuleContext,
filter::{AnalysisFilter, GroupKey, RuleKey},
rule::{GroupCategory, Rule, RuleDiagnostic, RuleGroup},
AnalyserOptions,
};

pub trait RegistryVisitor {
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_analyse/src/rule.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pglt_console::fmt::Display;
use pglt_console::{markup, MarkupBuf};
use pglt_console::{MarkupBuf, markup};
use pglt_diagnostics::advice::CodeSuggestionAdvice;
use pglt_diagnostics::{
Advices, Category, Diagnostic, DiagnosticTags, Location, LogCategory, MessageAndDescription,
Expand Down
3 changes: 2 additions & 1 deletion crates/pglt_analyser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ mod tests {

use pglt_analyse::{AnalyserOptions, AnalysisFilter, RuleFilter};
use pglt_console::{
Markup,
fmt::{Formatter, Termcolor},
markup, Markup,
markup,
};
use pglt_diagnostics::PrintDiagnostic;
use termcolor::NoColor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pglt_analyse::{context::RuleContext, declare_lint_rule, Rule, RuleDiagnostic, RuleSource};
use pglt_analyse::{Rule, RuleDiagnostic, RuleSource, context::RuleContext, declare_lint_rule};
use pglt_console::markup;

declare_lint_rule! {
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_analyser/src/lint/safety/ban_drop_column.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pglt_analyse::{context::RuleContext, declare_lint_rule, Rule, RuleDiagnostic, RuleSource};
use pglt_analyse::{Rule, RuleDiagnostic, RuleSource, context::RuleContext, declare_lint_rule};
use pglt_console::markup;

declare_lint_rule! {
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_analyser/src/lint/safety/ban_drop_not_null.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pglt_analyse::{context::RuleContext, declare_lint_rule, Rule, RuleDiagnostic, RuleSource};
use pglt_analyse::{Rule, RuleDiagnostic, RuleSource, context::RuleContext, declare_lint_rule};
use pglt_console::markup;

declare_lint_rule! {
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_analyser/src/lint/safety/ban_drop_table.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pglt_analyse::{context::RuleContext, declare_lint_rule, Rule, RuleDiagnostic, RuleSource};
use pglt_analyse::{Rule, RuleDiagnostic, RuleSource, context::RuleContext, declare_lint_rule};
use pglt_console::markup;

declare_lint_rule! {
Expand Down
6 changes: 5 additions & 1 deletion crates/pglt_cli/src/changed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ pub(crate) fn get_changed_files(
(Some(since), Some(_)) => since,
(Some(since), None) => since,
(None, Some(branch)) => branch,
(None, None) => return Err(CliDiagnostic::incompatible_end_configuration("The `--changed` flag was set, but couldn't determine the base to compare against. Either set configuration.vcs.default_branch or use the --since argument.")),
(None, None) => {
return Err(CliDiagnostic::incompatible_end_configuration(
"The `--changed` flag was set, but couldn't determine the base to compare against. Either set configuration.vcs.default_branch or use the --since argument.",
));
}
};

let changed_files = fs.get_changed_files(base)?;
Expand Down
7 changes: 5 additions & 2 deletions crates/pglt_cli/src/cli_options.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::logging::LoggingKind;
use crate::LoggingLevel;
use crate::logging::LoggingKind;
use bpaf::Bpaf;
use pglt_configuration::ConfigurationPathHint;
use pglt_diagnostics::Severity;
Expand Down Expand Up @@ -208,7 +208,10 @@ impl FromStr for MaxDiagnostics {
if let Ok(value) = s.parse::<u32>() {
Ok(MaxDiagnostics::Limit(value))
} else {
Err(format!("Invalid value provided. Provide 'none' to lift the limit, or a number between 0 and {}.", u32::MAX))
Err(format!(
"Invalid value provided. Provide 'none' to lift the limit, or a number between 0 and {}.",
u32::MAX
))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/pglt_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use biome_deserialize::Merge;
use pglt_configuration::PartialConfiguration;
use pglt_console::Console;
use pglt_fs::FileSystem;
use pglt_workspace::{configuration::LoadedConfiguration, DynRef, Workspace, WorkspaceError};
use pglt_workspace::{DynRef, Workspace, WorkspaceError, configuration::LoadedConfiguration};
use std::ffi::OsString;

use super::{get_files_to_process_with_cli_options, CommandRunner};
use super::{CommandRunner, get_files_to_process_with_cli_options};

pub(crate) struct CheckCommandPayload {
pub(crate) configuration: Option<PartialConfiguration>,
Expand Down
45 changes: 24 additions & 21 deletions crates/pglt_cli/src/commands/daemon.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use crate::{
open_transport,
CliDiagnostic, CliSession, open_transport,
service::{self, ensure_daemon, open_socket, run_daemon},
CliDiagnostic, CliSession,
};
use pglt_console::{markup, ConsoleExt};
use pglt_console::{ConsoleExt, markup};
use pglt_lsp::ServerFactory;
use pglt_workspace::{workspace::WorkspaceClient, TransportError, WorkspaceError};
use pglt_workspace::{TransportError, WorkspaceError, workspace::WorkspaceClient};
use std::{env, fs, path::PathBuf};
use tokio::io;
use tokio::runtime::Runtime;
use tracing::subscriber::Interest;
use tracing::{debug_span, metadata::LevelFilter, Instrument, Metadata};
use tracing::{Instrument, Metadata, debug_span, metadata::LevelFilter};
use tracing_appender::rolling::Rotation;
use tracing_subscriber::{
Layer,
layer::{Context, Filter},
prelude::*,
registry, Layer,
registry,
};
use tracing_tree::HierarchicalLayer;

Expand Down Expand Up @@ -49,22 +49,25 @@ pub(crate) fn start(
pub(crate) fn stop(session: CliSession) -> Result<(), CliDiagnostic> {
let rt = Runtime::new()?;

if let Some(transport) = open_transport(rt)? {
let client = WorkspaceClient::new(transport)?;
match client.shutdown() {
// The `ChannelClosed` error is expected since the server can
// shutdown before sending a response
Ok(()) | Err(WorkspaceError::TransportError(TransportError::ChannelClosed)) => {}
Err(err) => return Err(CliDiagnostic::from(err)),
};
match open_transport(rt)? {
Some(transport) => {
let client = WorkspaceClient::new(transport)?;
match client.shutdown() {
// The `ChannelClosed` error is expected since the server can
// shutdown before sending a response
Ok(()) | Err(WorkspaceError::TransportError(TransportError::ChannelClosed)) => {}
Err(err) => return Err(CliDiagnostic::from(err)),
};

session.app.console.log(markup! {
"The server was successfully stopped"
});
} else {
session.app.console.log(markup! {
"The server was not running"
});
session.app.console.log(markup! {
"The server was successfully stopped"
});
}
_ => {
session.app.console.log(markup! {
"The server was not running"
});
}
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_cli/src/commands/init.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{CliDiagnostic, CliSession};
use pglt_configuration::PartialConfiguration;
use pglt_console::{markup, ConsoleExt};
use pglt_console::{ConsoleExt, markup};
use pglt_fs::ConfigName;
use pglt_workspace::configuration::create_config;

Expand Down
10 changes: 5 additions & 5 deletions crates/pglt_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use crate::changed::{get_changed_files, get_staged_files};
use crate::cli_options::{cli_options, CliOptions, CliReporter, ColorsArg};
use crate::cli_options::{CliOptions, CliReporter, ColorsArg, cli_options};
use crate::execute::Stdin;
use crate::logging::LoggingKind;
use crate::{
execute_mode, setup_cli_subscriber, CliDiagnostic, CliSession, Execution, LoggingLevel, VERSION,
CliDiagnostic, CliSession, Execution, LoggingLevel, VERSION, execute_mode, setup_cli_subscriber,
};
use bpaf::Bpaf;
use pglt_configuration::{partial_configuration, PartialConfiguration};
use pglt_configuration::{PartialConfiguration, partial_configuration};
use pglt_console::Console;
use pglt_fs::FileSystem;
use pglt_workspace::configuration::{load_configuration, LoadedConfiguration};
use pglt_workspace::configuration::{LoadedConfiguration, load_configuration};
use pglt_workspace::settings::PartialConfigurationExt;
use pglt_workspace::workspace::UpdateSettingsParams;
use pglt_workspace::{DynRef, Workspace, WorkspaceError};
Expand Down Expand Up @@ -183,7 +183,7 @@ impl PgltCommand {
| PgltCommand::Stop
| PgltCommand::Init
| PgltCommand::RunServer { .. }
| PgltCommand::Clean { .. }
| PgltCommand::Clean
| PgltCommand::PrintSocket => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/pglt_cli/src/commands/version.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use pglt_console::fmt::Formatter;
use pglt_console::{fmt, markup, ConsoleExt};
use pglt_console::{ConsoleExt, fmt, markup};
use pglt_workspace::workspace::ServerInfo;

use crate::{CliDiagnostic, CliSession, VERSION};
Expand Down
23 changes: 13 additions & 10 deletions crates/pglt_cli/src/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ mod std_in;
pub(crate) mod traverse;

use crate::cli_options::{CliOptions, CliReporter};
use crate::execute::traverse::{traverse, TraverseResult};
use crate::execute::traverse::{TraverseResult, traverse};
use crate::reporter::github::{GithubReporter, GithubReporterVisitor};
use crate::reporter::gitlab::{GitLabReporter, GitLabReporterVisitor};
use crate::reporter::junit::{JunitReporter, JunitReporterVisitor};
use crate::reporter::terminal::{ConsoleReporter, ConsoleReporterVisitor};
use crate::{CliDiagnostic, CliSession, DiagnosticsPayload, Reporter};
use pglt_diagnostics::{category, Category};
use pglt_diagnostics::{Category, category};
use pglt_fs::PgLTPath;
use std::borrow::Borrow;
use std::ffi::OsString;
Expand Down Expand Up @@ -103,7 +103,7 @@ pub enum TraversalMode {
impl Display for TraversalMode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
TraversalMode::Dummy { .. } => write!(f, "dummy"),
TraversalMode::Dummy => write!(f, "dummy"),
TraversalMode::Check { .. } => write!(f, "check"),
}
}
Expand Down Expand Up @@ -165,33 +165,33 @@ impl Execution {

pub(crate) fn as_diagnostic_category(&self) -> &'static Category {
match self.traversal_mode {
TraversalMode::Dummy { .. } => category!("dummy"),
TraversalMode::Dummy => category!("dummy"),
TraversalMode::Check { .. } => category!("check"),
}
}

pub(crate) const fn is_dummy(&self) -> bool {
matches!(self.traversal_mode, TraversalMode::Dummy { .. })
matches!(self.traversal_mode, TraversalMode::Dummy)
}

/// Whether the traversal mode requires write access to files
pub(crate) const fn requires_write_access(&self) -> bool {
match self.traversal_mode {
TraversalMode::Dummy { .. } => false,
TraversalMode::Dummy => false,
TraversalMode::Check { .. } => false,
}
}

pub(crate) fn as_stdin_file(&self) -> Option<&Stdin> {
match &self.traversal_mode {
TraversalMode::Dummy { .. } => None,
TraversalMode::Dummy => None,
TraversalMode::Check { stdin, .. } => stdin.as_ref(),
}
}

pub(crate) fn is_vcs_targeted(&self) -> bool {
match &self.traversal_mode {
TraversalMode::Dummy { .. } => false,
TraversalMode::Dummy => false,
TraversalMode::Check { vcs_targeted, .. } => {
vcs_targeted.staged || vcs_targeted.changed
}
Expand All @@ -205,7 +205,7 @@ impl Execution {
/// Returns [true] if the user used the `--write`/`--fix` option
pub(crate) fn is_write(&self) -> bool {
match self.traversal_mode {
TraversalMode::Dummy { .. } => false,
TraversalMode::Dummy => false,
TraversalMode::Check { .. } => false,
}
}
Expand All @@ -223,7 +223,10 @@ pub fn execute_mode(
execution.max_diagnostics = if cli_options.reporter.is_default() {
cli_options.max_diagnostics.into()
} else {
info!("Removing the limit of --max-diagnostics, because of a reporter different from the default one: {}", cli_options.reporter);
info!(
"Removing the limit of --max-diagnostics, because of a reporter different from the default one: {}",
cli_options.reporter
);
u32::MAX
};

Expand Down
Loading