Skip to content

fix: various fixes across the board #255

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 4 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
268 changes: 246 additions & 22 deletions Cargo.lock

Large diffs are not rendered by default.

21 changes: 11 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,17 @@ serde = "1.0.195"
serde_json = "1.0.114"
similar = "2.6.0"
smallvec = { version = "1.13.2", features = ["union", "const_new", "serde"] }
sqlx = { version = "0.8.2", features = ["runtime-tokio", "postgres", "json"] }
syn = "1.0.109"
termcolor = "1.4.1"
tokio = { version = "1.40.0", features = ["full"] }
tower-lsp = "0.20.0"
tracing = { version = "0.1.40", default-features = false, features = ["std"] }
tracing-subscriber = "0.3.18"
tree-sitter = "0.20.10"
tree_sitter_sql = { path = "./lib/tree_sitter_sql", version = "0.0.0" }
unicode-width = "0.1.12"
# this will use tokio if available, otherwise async-std
sqlx = { version = "0.8.2", features = ["runtime-tokio", "runtime-async-std", "postgres", "json"] }
syn = "1.0.109"
termcolor = "1.4.1"
tokio = { version = "1.40.0", features = ["full"] }
tower-lsp = "0.20.0"
tracing = { version = "0.1.40", default-features = false, features = ["std"] }
tracing-subscriber = "0.3.18"
tree-sitter = "0.20.10"
tree_sitter_sql = { path = "./lib/tree_sitter_sql", version = "0.0.0" }
unicode-width = "0.1.12"

# postgres specific crates
pgt_analyse = { path = "./crates/pgt_analyse", version = "0.0.0" }
Expand Down
24 changes: 12 additions & 12 deletions crates/pgt_analyse/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,34 +70,34 @@ impl ActionCategory {
match self {
ActionCategory::QuickFix(tag) => {
if tag.is_empty() {
Cow::Borrowed("quickfix.pglt")
Cow::Borrowed("quickfix.pgt")
} else {
Cow::Owned(format!("quickfix.pglt.{tag}"))
Cow::Owned(format!("quickfix.pgt.{tag}"))
}
}

ActionCategory::Refactor(RefactorKind::None) => Cow::Borrowed("refactor.pglt"),
ActionCategory::Refactor(RefactorKind::None) => Cow::Borrowed("refactor.pgt"),
ActionCategory::Refactor(RefactorKind::Extract) => {
Cow::Borrowed("refactor.extract.pglt")
Cow::Borrowed("refactor.extract.pgt")
}
ActionCategory::Refactor(RefactorKind::Inline) => Cow::Borrowed("refactor.inline.pglt"),
ActionCategory::Refactor(RefactorKind::Inline) => Cow::Borrowed("refactor.inline.pgt"),
ActionCategory::Refactor(RefactorKind::Rewrite) => {
Cow::Borrowed("refactor.rewrite.pglt")
Cow::Borrowed("refactor.rewrite.pgt")
}
ActionCategory::Refactor(RefactorKind::Other(tag)) => {
Cow::Owned(format!("refactor.{tag}.pglt"))
Cow::Owned(format!("refactor.{tag}.pgt"))
}

ActionCategory::Source(SourceActionKind::None) => Cow::Borrowed("source.pglt"),
ActionCategory::Source(SourceActionKind::FixAll) => Cow::Borrowed("source.fixAll.pglt"),
ActionCategory::Source(SourceActionKind::None) => Cow::Borrowed("source.pgt"),
ActionCategory::Source(SourceActionKind::FixAll) => Cow::Borrowed("source.fixAll.pgt"),
ActionCategory::Source(SourceActionKind::OrganizeImports) => {
Cow::Borrowed("source.organizeImports.pglt")
Cow::Borrowed("source.organizeImports.pgt")
}
ActionCategory::Source(SourceActionKind::Other(tag)) => {
Cow::Owned(format!("source.{tag}.pglt"))
Cow::Owned(format!("source.{tag}.pgt"))
}

ActionCategory::Other(tag) => Cow::Owned(format!("{tag}.pglt")),
ActionCategory::Other(tag) => Cow::Owned(format!("{tag}.pgt")),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/pgt_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ mimalloc = "0.1.43"
tikv-jemallocator = "0.6.0"

[dev-dependencies]
assert_cmd = "2.0.16"
predicates = "3.1.3"

[lib]
doctest = false
Expand Down
4 changes: 2 additions & 2 deletions crates/pgt_cli/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct CliOptions {
#[bpaf(long("no-errors-on-unmatched"), switch)]
pub no_errors_on_unmatched: bool,

/// Tell PgLT to exit with an error code if some diagnostics emit warnings.
/// Tell Postgres Tools to exit with an error code if some diagnostics emit warnings.
#[bpaf(long("error-on-warnings"), switch)]
pub error_on_warnings: bool,

Expand Down Expand Up @@ -86,7 +86,7 @@ pub struct CliOptions {
fallback(Severity::default()),
display_fallback
)]
/// 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.
/// The level of diagnostics to show. In order, from the lowest to the most important: info, warn, error. Passing `--diagnostic-level=error` will cause Postgres Tools to print only diagnostics that contain only errors.
pub diagnostic_level: Severity,
}

Expand Down
12 changes: 6 additions & 6 deletions crates/pgt_cli/src/commands/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,10 @@ pub(crate) fn read_most_recent_log_file(
/// The events received by the subscriber are filtered at the `info` level,
/// then printed using the [HierarchicalLayer] layer, and the resulting text
/// is written to log files rotated on a hourly basis (in
/// `pglt-logs/server.log.yyyy-MM-dd-HH` files inside the system temporary
/// `pgt-logs/server.log.yyyy-MM-dd-HH` files inside the system temporary
/// directory)
fn setup_tracing_subscriber(log_path: Option<PathBuf>, log_file_name_prefix: Option<String>) {
let pgt_log_path = log_path.unwrap_or(pgt_fs::ensure_cache_dir().join("pglt-logs"));
let pgt_log_path = log_path.unwrap_or(pgt_fs::ensure_cache_dir().join("pgt-logs"));
let appender_builder = tracing_appender::rolling::RollingFileAppender::builder();
let file_appender = appender_builder
.filename_prefix(log_file_name_prefix.unwrap_or(String::from("server.log")))
Expand All @@ -235,16 +235,16 @@ fn setup_tracing_subscriber(log_path: Option<PathBuf>, log_file_name_prefix: Opt
pub fn default_pgt_log_path() -> PathBuf {
match env::var_os("PGT_LOG_PATH") {
Some(directory) => PathBuf::from(directory),
None => pgt_fs::ensure_cache_dir().join("pglt-logs"),
None => pgt_fs::ensure_cache_dir().join("pgt-logs"),
}
}

/// Tracing filter enabling:
/// - All spans and events at level info or higher
/// - All spans and events at level debug in crates whose name starts with `pglt`
/// - All spans and events at level debug in crates whose name starts with `pgt`
struct LoggingFilter;

/// Tracing filter used for spans emitted by `pglt*` crates
/// Tracing filter used for spans emitted by `pgt*` crates
const SELF_FILTER: LevelFilter = if cfg!(debug_assertions) {
LevelFilter::TRACE
} else {
Expand All @@ -253,7 +253,7 @@ const SELF_FILTER: LevelFilter = if cfg!(debug_assertions) {

impl LoggingFilter {
fn is_enabled(&self, meta: &Metadata<'_>) -> bool {
let filter = if meta.target().starts_with("pglt") {
let filter = if meta.target().starts_with("pgt") {
SELF_FILTER
} else {
LevelFilter::INFO
Expand Down
10 changes: 5 additions & 5 deletions crates/pgt_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(crate) mod version;

#[derive(Debug, Clone, Bpaf)]
#[bpaf(options, version(VERSION))]
/// PgLT official CLI. Use it to check the health of your project or run it to check single files.
/// Postgres Tools official CLI. Use it to check the health of your project or run it to check single files.
pub enum PgtCommand {
/// Shows the version information and quit.
#[bpaf(command)]
Expand Down Expand Up @@ -87,7 +87,7 @@ pub enum PgtCommand {
long("log-path"),
argument("PATH"),
hide_usage,
fallback(pgt_fs::ensure_cache_dir().join("pglt-logs")),
fallback(pgt_fs::ensure_cache_dir().join("pgt-logs")),
)]
log_path: PathBuf,
/// Allows to set a custom file path to the configuration file,
Expand Down Expand Up @@ -123,7 +123,7 @@ pub enum PgtCommand {
long("log-path"),
argument("PATH"),
hide_usage,
fallback(pgt_fs::ensure_cache_dir().join("pglt-logs")),
fallback(pgt_fs::ensure_cache_dir().join("pgt-logs")),
)]
log_path: PathBuf,
/// Allows to set a custom file path to the configuration file,
Expand Down Expand Up @@ -157,7 +157,7 @@ pub enum PgtCommand {
long("log-path"),
argument("PATH"),
hide_usage,
fallback(pgt_fs::ensure_cache_dir().join("pglt-logs")),
fallback(pgt_fs::ensure_cache_dir().join("pgt-logs")),
)]
log_path: PathBuf,

Expand Down Expand Up @@ -197,7 +197,7 @@ impl PgtCommand {
}
// We want force colors in CI, to give e better UX experience
// Unless users explicitly set the colors flag
// if matches!(self, PgLTCommand::Ci { .. }) && cli_options.colors.is_none() {
// if matches!(self, Postgres ToolsCommand::Ci { .. }) && cli_options.colors.is_none() {
// return Some(&ColorsArg::Force);
// }
// Normal behaviors
Expand Down
4 changes: 2 additions & 2 deletions crates/pgt_cli/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ fn command_name() -> String {
current_exe()
.ok()
.and_then(|path| Some(path.file_name()?.to_str()?.to_string()))
.unwrap_or_else(|| String::from("pglt"))
.unwrap_or_else(|| String::from("postgrestools"))
}

/// A diagnostic that is emitted when running PgLT via CLI.
/// A diagnostic that is emitted when running Postgres Tools via CLI.
///
/// When displaying the diagnostic,
#[derive(Debug, Diagnostic)]
Expand Down
4 changes: 2 additions & 2 deletions crates/pgt_cli/src/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::reporter::junit::{JunitReporter, JunitReporterVisitor};
use crate::reporter::terminal::{ConsoleReporter, ConsoleReporterVisitor};
use crate::{CliDiagnostic, CliSession, DiagnosticsPayload, Reporter};
use pgt_diagnostics::{Category, category};
use pgt_fs::PgLTPath;
use pgt_fs::PgTPath;
use std::borrow::Borrow;
use std::ffi::OsString;
use std::fmt::{Display, Formatter};
Expand Down Expand Up @@ -232,7 +232,7 @@ pub fn execute_mode(

// don't do any traversal if there's some content coming from stdin
if let Some(stdin) = execution.as_stdin_file() {
let pgt_path = PgLTPath::new(stdin.as_path());
let pgt_path = PgTPath::new(stdin.as_path());
std_in::run(
session,
&execution,
Expand Down
4 changes: 2 additions & 2 deletions crates/pgt_cli/src/execute/process_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::execute::TraversalMode;
use crate::execute::traverse::TraversalOptions;
use check::check_file;
use pgt_diagnostics::Error;
use pgt_fs::PgLTPath;
use pgt_fs::PgTPath;
use std::marker::PhantomData;
use std::ops::Deref;

Expand Down Expand Up @@ -111,7 +111,7 @@ impl<'ctx, 'app> Deref for SharedTraversalOptions<'ctx, 'app> {
/// diagnostics were emitted, or compare the formatted code with the original
/// content of the file and emit a diff or write the new content to the disk if
/// write mode is enabled
pub(crate) fn process_file(ctx: &TraversalOptions, pgt_path: &PgLTPath) -> FileResult {
pub(crate) fn process_file(ctx: &TraversalOptions, pgt_path: &PgTPath) -> FileResult {
tracing::trace_span!("process_file", path = ?pgt_path).in_scope(move || {
let shared_context = &SharedTraversalOptions::new(ctx);

Expand Down
4 changes: 2 additions & 2 deletions crates/pgt_cli/src/execute/process_file/workspace_file.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::execute::diagnostics::{ResultExt, ResultIoExt};
use crate::execute::process_file::SharedTraversalOptions;
use pgt_diagnostics::{Error, category};
use pgt_fs::{File, OpenOptions, PgLTPath};
use pgt_fs::{File, OpenOptions, PgTPath};
use pgt_workspace::workspace::{ChangeParams, FileGuard, OpenFileParams};
use pgt_workspace::{Workspace, WorkspaceError};
use std::ffi::OsStr;
Expand All @@ -21,7 +21,7 @@ impl<'ctx, 'app> WorkspaceFile<'ctx, 'app> {
ctx: &SharedTraversalOptions<'ctx, 'app>,
path: &Path,
) -> Result<Self, Error> {
let pgt_path = PgLTPath::new(path);
let pgt_path = PgTPath::new(path);
let open_options = OpenOptions::default()
.read(true)
.write(ctx.execution.requires_write_access());
Expand Down
4 changes: 2 additions & 2 deletions crates/pgt_cli/src/execute/std_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
use crate::execute::Execution;
use crate::{CliDiagnostic, CliSession};
use pgt_console::{ConsoleExt, markup};
use pgt_fs::PgLTPath;
use pgt_fs::PgTPath;

pub(crate) fn run<'a>(
session: CliSession,
mode: &'a Execution,
pgt_path: PgLTPath,
pgt_path: PgTPath,
content: &'a str,
verbose: bool,
) -> Result<(), CliDiagnostic> {
Expand Down
28 changes: 14 additions & 14 deletions crates/pgt_cli/src/execute/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{CliDiagnostic, CliSession};
use crossbeam::channel::{Receiver, Sender, unbounded};
use pgt_diagnostics::DiagnosticTags;
use pgt_diagnostics::{DiagnosticExt, Error, Resource, Severity};
use pgt_fs::{FileSystem, PathInterner, PgLTPath};
use pgt_fs::{FileSystem, PathInterner, PgTPath};
use pgt_fs::{TraversalContext, TraversalScope};
use pgt_workspace::dome::Dome;
use pgt_workspace::workspace::IsPathIgnoredParams;
Expand All @@ -31,7 +31,7 @@ use std::{

pub(crate) struct TraverseResult {
pub(crate) summary: TraversalSummary,
pub(crate) evaluated_paths: BTreeSet<PgLTPath>,
pub(crate) evaluated_paths: BTreeSet<PgTPath>,
pub(crate) diagnostics: Vec<Error>,
}

Expand Down Expand Up @@ -86,7 +86,7 @@ pub(crate) fn traverse(

let (duration, evaluated_paths, diagnostics) = thread::scope(|s| {
let handler = thread::Builder::new()
.name(String::from("pglt::console"))
.name(String::from("pgt::console"))
.spawn_scoped(s, || printer.run(receiver, recv_files))
.expect("failed to spawn console thread");

Expand Down Expand Up @@ -148,7 +148,7 @@ fn init_thread_pool() {
static INIT_ONCE: Once = Once::new();
INIT_ONCE.call_once(|| {
rayon::ThreadPoolBuilder::new()
.thread_name(|index| format!("pglt::worker_{index}"))
.thread_name(|index| format!("pgt::worker_{index}"))
.build_global()
.expect("failed to initialize the global thread pool");
});
Expand All @@ -160,7 +160,7 @@ fn traverse_inputs(
fs: &dyn FileSystem,
inputs: Vec<OsString>,
ctx: &TraversalOptions,
) -> (Duration, BTreeSet<PgLTPath>) {
) -> (Duration, BTreeSet<PgTPath>) {
let start = Instant::now();
fs.traversal(Box::new(move |scope: &dyn TraversalScope| {
for input in inputs {
Expand Down Expand Up @@ -412,11 +412,11 @@ pub(crate) struct TraversalOptions<'ctx, 'app> {
pub(crate) remaining_diagnostics: &'ctx AtomicU32,

/// List of paths that should be processed
pub(crate) evaluated_paths: RwLock<BTreeSet<PgLTPath>>,
pub(crate) evaluated_paths: RwLock<BTreeSet<PgTPath>>,
}

impl TraversalOptions<'_, '_> {
pub(crate) fn increment_changed(&self, path: &PgLTPath) {
pub(crate) fn increment_changed(&self, path: &PgTPath) {
self.changed.fetch_add(1, Ordering::Relaxed);
self.evaluated_paths
.write()
Expand All @@ -436,7 +436,7 @@ impl TraversalOptions<'_, '_> {
self.messages.send(msg.into()).ok();
}

pub(crate) fn protected_file(&self, pgt_path: &PgLTPath) {
pub(crate) fn protected_file(&self, pgt_path: &PgTPath) {
self.push_diagnostic(WorkspaceError::protected_file(pgt_path.display().to_string()).into())
}
}
Expand All @@ -446,15 +446,15 @@ impl TraversalContext for TraversalOptions<'_, '_> {
&self.interner
}

fn evaluated_paths(&self) -> BTreeSet<PgLTPath> {
fn evaluated_paths(&self) -> BTreeSet<PgTPath> {
self.evaluated_paths.read().unwrap().clone()
}

fn push_diagnostic(&self, error: Error) {
self.push_message(error);
}

fn can_handle(&self, pgt_path: &PgLTPath) -> bool {
fn can_handle(&self, pgt_path: &PgTPath) -> bool {
let path = pgt_path.as_path();

let is_valid_file = self.fs.path_is_file(path)
Expand Down Expand Up @@ -492,22 +492,22 @@ impl TraversalContext for TraversalOptions<'_, '_> {
}
}

fn handle_path(&self, path: PgLTPath) {
fn handle_path(&self, path: PgTPath) {
handle_file(self, &path)
}

fn store_path(&self, path: PgLTPath) {
fn store_path(&self, path: PgTPath) {
self.evaluated_paths
.write()
.unwrap()
.insert(PgLTPath::new(path.as_path()));
.insert(PgTPath::new(path.as_path()));
}
}

/// This function wraps the [process_file] function implementing the traversal
/// in a [catch_unwind] block and emit diagnostics in case of error (either the
/// traversal function returns Err or panics)
fn handle_file(ctx: &TraversalOptions, path: &PgLTPath) {
fn handle_file(ctx: &TraversalOptions, path: &PgTPath) {
match catch_unwind(move || process_file(ctx, path)) {
Ok(Ok(FileStatus::Changed)) => {
ctx.increment_changed(path);
Expand Down
Loading