Skip to content

Commit fa0c705

Browse files
fix: various fixes across the board (#255)
* remaining renamings * Update server.rs Co-authored-by: Julian Domke <[email protected]> * fix: use tokio if available and async-std as fallback * chore: add test that actually calls the binary --------- Co-authored-by: Julian Domke <[email protected]>
1 parent afb43bc commit fa0c705

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+584
-254
lines changed

Cargo.lock

+246-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+11-10
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,17 @@ serde = "1.0.195"
3939
serde_json = "1.0.114"
4040
similar = "2.6.0"
4141
smallvec = { version = "1.13.2", features = ["union", "const_new", "serde"] }
42-
sqlx = { version = "0.8.2", features = ["runtime-tokio", "postgres", "json"] }
43-
syn = "1.0.109"
44-
termcolor = "1.4.1"
45-
tokio = { version = "1.40.0", features = ["full"] }
46-
tower-lsp = "0.20.0"
47-
tracing = { version = "0.1.40", default-features = false, features = ["std"] }
48-
tracing-subscriber = "0.3.18"
49-
tree-sitter = "0.20.10"
50-
tree_sitter_sql = { path = "./lib/tree_sitter_sql", version = "0.0.0" }
51-
unicode-width = "0.1.12"
42+
# this will use tokio if available, otherwise async-std
43+
sqlx = { version = "0.8.2", features = ["runtime-tokio", "runtime-async-std", "postgres", "json"] }
44+
syn = "1.0.109"
45+
termcolor = "1.4.1"
46+
tokio = { version = "1.40.0", features = ["full"] }
47+
tower-lsp = "0.20.0"
48+
tracing = { version = "0.1.40", default-features = false, features = ["std"] }
49+
tracing-subscriber = "0.3.18"
50+
tree-sitter = "0.20.10"
51+
tree_sitter_sql = { path = "./lib/tree_sitter_sql", version = "0.0.0" }
52+
unicode-width = "0.1.12"
5253

5354
# postgres specific crates
5455
pgt_analyse = { path = "./crates/pgt_analyse", version = "0.0.0" }

crates/pgt_analyse/src/categories.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -70,34 +70,34 @@ impl ActionCategory {
7070
match self {
7171
ActionCategory::QuickFix(tag) => {
7272
if tag.is_empty() {
73-
Cow::Borrowed("quickfix.pglt")
73+
Cow::Borrowed("quickfix.pgt")
7474
} else {
75-
Cow::Owned(format!("quickfix.pglt.{tag}"))
75+
Cow::Owned(format!("quickfix.pgt.{tag}"))
7676
}
7777
}
7878

79-
ActionCategory::Refactor(RefactorKind::None) => Cow::Borrowed("refactor.pglt"),
79+
ActionCategory::Refactor(RefactorKind::None) => Cow::Borrowed("refactor.pgt"),
8080
ActionCategory::Refactor(RefactorKind::Extract) => {
81-
Cow::Borrowed("refactor.extract.pglt")
81+
Cow::Borrowed("refactor.extract.pgt")
8282
}
83-
ActionCategory::Refactor(RefactorKind::Inline) => Cow::Borrowed("refactor.inline.pglt"),
83+
ActionCategory::Refactor(RefactorKind::Inline) => Cow::Borrowed("refactor.inline.pgt"),
8484
ActionCategory::Refactor(RefactorKind::Rewrite) => {
85-
Cow::Borrowed("refactor.rewrite.pglt")
85+
Cow::Borrowed("refactor.rewrite.pgt")
8686
}
8787
ActionCategory::Refactor(RefactorKind::Other(tag)) => {
88-
Cow::Owned(format!("refactor.{tag}.pglt"))
88+
Cow::Owned(format!("refactor.{tag}.pgt"))
8989
}
9090

91-
ActionCategory::Source(SourceActionKind::None) => Cow::Borrowed("source.pglt"),
92-
ActionCategory::Source(SourceActionKind::FixAll) => Cow::Borrowed("source.fixAll.pglt"),
91+
ActionCategory::Source(SourceActionKind::None) => Cow::Borrowed("source.pgt"),
92+
ActionCategory::Source(SourceActionKind::FixAll) => Cow::Borrowed("source.fixAll.pgt"),
9393
ActionCategory::Source(SourceActionKind::OrganizeImports) => {
94-
Cow::Borrowed("source.organizeImports.pglt")
94+
Cow::Borrowed("source.organizeImports.pgt")
9595
}
9696
ActionCategory::Source(SourceActionKind::Other(tag)) => {
97-
Cow::Owned(format!("source.{tag}.pglt"))
97+
Cow::Owned(format!("source.{tag}.pgt"))
9898
}
9999

100-
ActionCategory::Other(tag) => Cow::Owned(format!("{tag}.pglt")),
100+
ActionCategory::Other(tag) => Cow::Owned(format!("{tag}.pgt")),
101101
}
102102
}
103103
}

crates/pgt_cli/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ mimalloc = "0.1.43"
5151
tikv-jemallocator = "0.6.0"
5252

5353
[dev-dependencies]
54+
assert_cmd = "2.0.16"
55+
predicates = "3.1.3"
5456

5557
[lib]
5658
doctest = false

crates/pgt_cli/src/cli_options.rs

+2-2
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 PgLT to exit with an error code if some diagnostics emit warnings.
51+
/// Tell Postgres Tools 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 PgLT 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 Postgres Tools to print only diagnostics that contain only errors.
9090
pub diagnostic_level: Severity,
9191
}
9292

crates/pgt_cli/src/commands/daemon.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ pub(crate) fn read_most_recent_log_file(
206206
/// The events received by the subscriber are filtered at the `info` level,
207207
/// then printed using the [HierarchicalLayer] layer, and the resulting text
208208
/// is written to log files rotated on a hourly basis (in
209-
/// `pglt-logs/server.log.yyyy-MM-dd-HH` files inside the system temporary
209+
/// `pgt-logs/server.log.yyyy-MM-dd-HH` files inside the system temporary
210210
/// directory)
211211
fn setup_tracing_subscriber(log_path: Option<PathBuf>, log_file_name_prefix: Option<String>) {
212-
let pgt_log_path = log_path.unwrap_or(pgt_fs::ensure_cache_dir().join("pglt-logs"));
212+
let pgt_log_path = log_path.unwrap_or(pgt_fs::ensure_cache_dir().join("pgt-logs"));
213213
let appender_builder = tracing_appender::rolling::RollingFileAppender::builder();
214214
let file_appender = appender_builder
215215
.filename_prefix(log_file_name_prefix.unwrap_or(String::from("server.log")))
@@ -235,16 +235,16 @@ fn setup_tracing_subscriber(log_path: Option<PathBuf>, log_file_name_prefix: Opt
235235
pub fn default_pgt_log_path() -> PathBuf {
236236
match env::var_os("PGT_LOG_PATH") {
237237
Some(directory) => PathBuf::from(directory),
238-
None => pgt_fs::ensure_cache_dir().join("pglt-logs"),
238+
None => pgt_fs::ensure_cache_dir().join("pgt-logs"),
239239
}
240240
}
241241

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

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

254254
impl LoggingFilter {
255255
fn is_enabled(&self, meta: &Metadata<'_>) -> bool {
256-
let filter = if meta.target().starts_with("pglt") {
256+
let filter = if meta.target().starts_with("pgt") {
257257
SELF_FILTER
258258
} else {
259259
LevelFilter::INFO

crates/pgt_cli/src/commands/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub(crate) mod version;
2424

2525
#[derive(Debug, Clone, Bpaf)]
2626
#[bpaf(options, version(VERSION))]
27-
/// PgLT official CLI. Use it to check the health of your project or run it to check single files.
27+
/// Postgres Tools official CLI. Use it to check the health of your project or run it to check single files.
2828
pub enum PgtCommand {
2929
/// Shows the version information and quit.
3030
#[bpaf(command)]
@@ -87,7 +87,7 @@ pub enum PgtCommand {
8787
long("log-path"),
8888
argument("PATH"),
8989
hide_usage,
90-
fallback(pgt_fs::ensure_cache_dir().join("pglt-logs")),
90+
fallback(pgt_fs::ensure_cache_dir().join("pgt-logs")),
9191
)]
9292
log_path: PathBuf,
9393
/// Allows to set a custom file path to the configuration file,
@@ -123,7 +123,7 @@ pub enum PgtCommand {
123123
long("log-path"),
124124
argument("PATH"),
125125
hide_usage,
126-
fallback(pgt_fs::ensure_cache_dir().join("pglt-logs")),
126+
fallback(pgt_fs::ensure_cache_dir().join("pgt-logs")),
127127
)]
128128
log_path: PathBuf,
129129
/// Allows to set a custom file path to the configuration file,
@@ -157,7 +157,7 @@ pub enum PgtCommand {
157157
long("log-path"),
158158
argument("PATH"),
159159
hide_usage,
160-
fallback(pgt_fs::ensure_cache_dir().join("pglt-logs")),
160+
fallback(pgt_fs::ensure_cache_dir().join("pgt-logs")),
161161
)]
162162
log_path: PathBuf,
163163

@@ -197,7 +197,7 @@ impl PgtCommand {
197197
}
198198
// We want force colors in CI, to give e better UX experience
199199
// Unless users explicitly set the colors flag
200-
// if matches!(self, PgLTCommand::Ci { .. }) && cli_options.colors.is_none() {
200+
// if matches!(self, Postgres ToolsCommand::Ci { .. }) && cli_options.colors.is_none() {
201201
// return Some(&ColorsArg::Force);
202202
// }
203203
// Normal behaviors

crates/pgt_cli/src/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ fn command_name() -> String {
1212
current_exe()
1313
.ok()
1414
.and_then(|path| Some(path.file_name()?.to_str()?.to_string()))
15-
.unwrap_or_else(|| String::from("pglt"))
15+
.unwrap_or_else(|| String::from("postgrestools"))
1616
}
1717

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

crates/pgt_cli/src/execute/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::reporter::junit::{JunitReporter, JunitReporterVisitor};
1111
use crate::reporter::terminal::{ConsoleReporter, ConsoleReporterVisitor};
1212
use crate::{CliDiagnostic, CliSession, DiagnosticsPayload, Reporter};
1313
use pgt_diagnostics::{Category, category};
14-
use pgt_fs::PgLTPath;
14+
use pgt_fs::PgTPath;
1515
use std::borrow::Borrow;
1616
use std::ffi::OsString;
1717
use std::fmt::{Display, Formatter};
@@ -232,7 +232,7 @@ pub fn execute_mode(
232232

233233
// don't do any traversal if there's some content coming from stdin
234234
if let Some(stdin) = execution.as_stdin_file() {
235-
let pgt_path = PgLTPath::new(stdin.as_path());
235+
let pgt_path = PgTPath::new(stdin.as_path());
236236
std_in::run(
237237
session,
238238
&execution,

crates/pgt_cli/src/execute/process_file.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::execute::TraversalMode;
55
use crate::execute::traverse::TraversalOptions;
66
use check::check_file;
77
use pgt_diagnostics::Error;
8-
use pgt_fs::PgLTPath;
8+
use pgt_fs::PgTPath;
99
use std::marker::PhantomData;
1010
use std::ops::Deref;
1111

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

crates/pgt_cli/src/execute/process_file/workspace_file.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::execute::diagnostics::{ResultExt, ResultIoExt};
22
use crate::execute::process_file::SharedTraversalOptions;
33
use pgt_diagnostics::{Error, category};
4-
use pgt_fs::{File, OpenOptions, PgLTPath};
4+
use pgt_fs::{File, OpenOptions, PgTPath};
55
use pgt_workspace::workspace::{ChangeParams, FileGuard, OpenFileParams};
66
use pgt_workspace::{Workspace, WorkspaceError};
77
use std::ffi::OsStr;
@@ -21,7 +21,7 @@ impl<'ctx, 'app> WorkspaceFile<'ctx, 'app> {
2121
ctx: &SharedTraversalOptions<'ctx, 'app>,
2222
path: &Path,
2323
) -> Result<Self, Error> {
24-
let pgt_path = PgLTPath::new(path);
24+
let pgt_path = PgTPath::new(path);
2525
let open_options = OpenOptions::default()
2626
.read(true)
2727
.write(ctx.execution.requires_write_access());

crates/pgt_cli/src/execute/std_in.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
use crate::execute::Execution;
44
use crate::{CliDiagnostic, CliSession};
55
use pgt_console::{ConsoleExt, markup};
6-
use pgt_fs::PgLTPath;
6+
use pgt_fs::PgTPath;
77

88
pub(crate) fn run<'a>(
99
session: CliSession,
1010
mode: &'a Execution,
11-
pgt_path: PgLTPath,
11+
pgt_path: PgTPath,
1212
content: &'a str,
1313
verbose: bool,
1414
) -> Result<(), CliDiagnostic> {

crates/pgt_cli/src/execute/traverse.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::{CliDiagnostic, CliSession};
77
use crossbeam::channel::{Receiver, Sender, unbounded};
88
use pgt_diagnostics::DiagnosticTags;
99
use pgt_diagnostics::{DiagnosticExt, Error, Resource, Severity};
10-
use pgt_fs::{FileSystem, PathInterner, PgLTPath};
10+
use pgt_fs::{FileSystem, PathInterner, PgTPath};
1111
use pgt_fs::{TraversalContext, TraversalScope};
1212
use pgt_workspace::dome::Dome;
1313
use pgt_workspace::workspace::IsPathIgnoredParams;
@@ -31,7 +31,7 @@ use std::{
3131

3232
pub(crate) struct TraverseResult {
3333
pub(crate) summary: TraversalSummary,
34-
pub(crate) evaluated_paths: BTreeSet<PgLTPath>,
34+
pub(crate) evaluated_paths: BTreeSet<PgTPath>,
3535
pub(crate) diagnostics: Vec<Error>,
3636
}
3737

@@ -86,7 +86,7 @@ pub(crate) fn traverse(
8686

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

@@ -148,7 +148,7 @@ fn init_thread_pool() {
148148
static INIT_ONCE: Once = Once::new();
149149
INIT_ONCE.call_once(|| {
150150
rayon::ThreadPoolBuilder::new()
151-
.thread_name(|index| format!("pglt::worker_{index}"))
151+
.thread_name(|index| format!("pgt::worker_{index}"))
152152
.build_global()
153153
.expect("failed to initialize the global thread pool");
154154
});
@@ -160,7 +160,7 @@ fn traverse_inputs(
160160
fs: &dyn FileSystem,
161161
inputs: Vec<OsString>,
162162
ctx: &TraversalOptions,
163-
) -> (Duration, BTreeSet<PgLTPath>) {
163+
) -> (Duration, BTreeSet<PgTPath>) {
164164
let start = Instant::now();
165165
fs.traversal(Box::new(move |scope: &dyn TraversalScope| {
166166
for input in inputs {
@@ -412,11 +412,11 @@ pub(crate) struct TraversalOptions<'ctx, 'app> {
412412
pub(crate) remaining_diagnostics: &'ctx AtomicU32,
413413

414414
/// List of paths that should be processed
415-
pub(crate) evaluated_paths: RwLock<BTreeSet<PgLTPath>>,
415+
pub(crate) evaluated_paths: RwLock<BTreeSet<PgTPath>>,
416416
}
417417

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

439-
pub(crate) fn protected_file(&self, pgt_path: &PgLTPath) {
439+
pub(crate) fn protected_file(&self, pgt_path: &PgTPath) {
440440
self.push_diagnostic(WorkspaceError::protected_file(pgt_path.display().to_string()).into())
441441
}
442442
}
@@ -446,15 +446,15 @@ impl TraversalContext for TraversalOptions<'_, '_> {
446446
&self.interner
447447
}
448448

449-
fn evaluated_paths(&self) -> BTreeSet<PgLTPath> {
449+
fn evaluated_paths(&self) -> BTreeSet<PgTPath> {
450450
self.evaluated_paths.read().unwrap().clone()
451451
}
452452

453453
fn push_diagnostic(&self, error: Error) {
454454
self.push_message(error);
455455
}
456456

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

460460
let is_valid_file = self.fs.path_is_file(path)
@@ -492,22 +492,22 @@ impl TraversalContext for TraversalOptions<'_, '_> {
492492
}
493493
}
494494

495-
fn handle_path(&self, path: PgLTPath) {
495+
fn handle_path(&self, path: PgTPath) {
496496
handle_file(self, &path)
497497
}
498498

499-
fn store_path(&self, path: PgLTPath) {
499+
fn store_path(&self, path: PgTPath) {
500500
self.evaluated_paths
501501
.write()
502502
.unwrap()
503-
.insert(PgLTPath::new(path.as_path()));
503+
.insert(PgTPath::new(path.as_path()));
504504
}
505505
}
506506

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

0 commit comments

Comments
 (0)