Skip to content

Commit dd6e519

Browse files
authored
chore: remaining renamings (#582)
- PgTPath -> PgLSPath - PgTCommand -> PgLSCommand and a bunch of updates within comments
1 parent 1ff2ee1 commit dd6e519

File tree

38 files changed

+223
-175
lines changed

38 files changed

+223
-175
lines changed

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"postgrestools.bin": "./target/debug/postgrestools"
2+
"postgres-language-server.bin": "./target/debug/postgres-language-server"
33
}

AGENTS.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ just new-crate <name>
6262
```
6363

6464
### CLI Usage
65-
The main CLI binary is `postgrestools`:
65+
The main CLI binary is `postgres-language-server` (legacy name: `postgrestools`):
6666
```bash
6767
cargo run -p pgls_cli -- check file.sql
6868
# or after building:
69-
./target/release/postgrestools check file.sql
69+
./target/release/postgres-language-server check file.sql
7070
```
7171

7272
## Architecture
@@ -103,8 +103,8 @@ The project uses a modular Rust workspace with crates prefixed with `pgls_`:
103103
### TypeScript Packages
104104
Located in `packages/` and `editors/`:
105105
- VSCode extension in `editors/code/`
106-
- Backend JSON-RPC bridge in `packages/@postgrestools/backend-jsonrpc/`
107-
- Main TypeScript package in `packages/@postgrestools/postgrestools/`
106+
- Backend JSON-RPC bridge in `packages/@postgres-language-server/backend-jsonrpc/` (legacy: `packages/@postgrestools/backend-jsonrpc/`)
107+
- Main TypeScript package in `packages/@postgres-language-server/postgres-language-server/` (legacy: `packages/@postgrestools/postgrestools/`)
108108

109109
### Database Integration
110110
The server connects to a Postgres database to build an in-memory schema cache containing tables, columns, functions, and type information. This enables accurate autocompletion and type checking.
@@ -150,6 +150,21 @@ Many parser structures are generated from PostgreSQL's protobuf definitions usin
150150
### Database Schema
151151
The `pgls_schema_cache` crate contains SQL queries in `src/queries/` that introspect the database schema to build the in-memory cache.
152152

153-
### Multi-Platform Support
153+
### Code Refactoring Tools
154+
The project has `ast-grep` available for advanced code search and refactoring tasks. ast-grep is a structural search/replace tool that understands code syntax, making it useful for:
155+
- Renaming types, functions, or variables across the codebase
156+
- Finding and replacing code patterns
157+
- Performing structural code transformations
158+
159+
Example usage:
160+
```bash
161+
# Search for a pattern
162+
ast-grep --pattern 'struct $NAME { $$$FIELDS }'
163+
164+
# Replace a pattern across files
165+
ast-grep --pattern 'OldType' --rewrite 'NewType' --update-all
166+
```
167+
168+
### Multi-Platform Support
154169
The project includes platform-specific allocators and build configurations for Windows, macOS, and Linux.
155170
- Seeing the Treesitter tree for an SQL query can be helpful to debug and implement features. To do this, create a file with an SQL query, and run `just tree-print <file.sql>`.

crates/pgls_cli/src/commands/mod.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(crate) mod version;
1919
#[bpaf(options, version(VERSION))]
2020
#[allow(clippy::large_enum_variant)]
2121
/// Postgres Tools official CLI. Use it to check the health of your project or run it to check single files.
22-
pub enum PgtCommand {
22+
pub enum PgLSCommand {
2323
/// Shows the version information and quit.
2424
#[bpaf(command)]
2525
Version(#[bpaf(external(cli_options), hide_usage)] CliOptions),
@@ -218,19 +218,19 @@ pub enum PgtCommand {
218218
PrintSocket,
219219
}
220220

221-
impl PgtCommand {
221+
impl PgLSCommand {
222222
const fn cli_options(&self) -> Option<&CliOptions> {
223223
match self {
224-
PgtCommand::Version(cli_options)
225-
| PgtCommand::Check { cli_options, .. }
226-
| PgtCommand::Dblint { cli_options, .. } => Some(cli_options),
227-
PgtCommand::LspProxy { .. }
228-
| PgtCommand::Start { .. }
229-
| PgtCommand::Stop
230-
| PgtCommand::Init
231-
| PgtCommand::RunServer { .. }
232-
| PgtCommand::Clean
233-
| PgtCommand::PrintSocket => None,
224+
PgLSCommand::Version(cli_options)
225+
| PgLSCommand::Check { cli_options, .. }
226+
| PgLSCommand::Dblint { cli_options, .. } => Some(cli_options),
227+
PgLSCommand::LspProxy { .. }
228+
| PgLSCommand::Start { .. }
229+
| PgLSCommand::Stop
230+
| PgLSCommand::Init
231+
| PgLSCommand::RunServer { .. }
232+
| PgLSCommand::Clean
233+
| PgLSCommand::PrintSocket => None,
234234
}
235235
}
236236

@@ -315,6 +315,6 @@ mod tests {
315315
/// Tests that all CLI options adhere to the invariants expected by `bpaf`.
316316
#[test]
317317
fn check_options() {
318-
pgt_command().check_invariants(false);
318+
pg_l_s_command().check_invariants(false);
319319
}
320320
}

crates/pgls_cli/src/execute/process_file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::execute::config::ExecutionMode;
55
use crate::execute::walk::TraversalOptions;
66
use check::check_file;
77
use pgls_diagnostics::Error;
8-
use pgls_fs::PgTPath;
8+
use pgls_fs::PgLSPath;
99
use std::marker::PhantomData;
1010
use std::ops::Deref;
1111

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

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

Lines changed: 2 additions & 2 deletions
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 pgls_diagnostics::{Error, category};
4-
use pgls_fs::{File, OpenOptions, PgTPath};
4+
use pgls_fs::{File, OpenOptions, PgLSPath};
55
use pgls_workspace::workspace::{FileGuard, OpenFileParams};
66
use pgls_workspace::{Workspace, WorkspaceError};
77
use std::path::{Path, PathBuf};
@@ -24,7 +24,7 @@ impl<'ctx, 'app> WorkspaceFile<'ctx, 'app> {
2424
ctx: &SharedTraversalOptions<'ctx, 'app>,
2525
path: &Path,
2626
) -> Result<Self, Error> {
27-
let pgls_path = PgTPath::new(path);
27+
let pgls_path = PgLSPath::new(path);
2828
let open_options = OpenOptions::default()
2929
.read(true)
3030
.write(ctx.config.allows_writes());

crates/pgls_cli/src/execute/walk.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::reporter::{Report, TraversalData};
55
use crate::{CliDiagnostic, CliSession};
66
use crossbeam::channel::{Receiver, Sender, unbounded};
77
use pgls_diagnostics::{DiagnosticExt, Error, Resource};
8-
use pgls_fs::{FileSystem, PathInterner, PgTPath};
8+
use pgls_fs::{FileSystem, PathInterner, PgLSPath};
99
use pgls_fs::{TraversalContext, TraversalScope};
1010
use pgls_workspace::dome::Dome;
1111
use pgls_workspace::workspace::IsPathIgnoredParams;
@@ -133,7 +133,7 @@ fn traverse_inputs(
133133
fs: &dyn FileSystem,
134134
inputs: Vec<OsString>,
135135
ctx: &TraversalOptions,
136-
) -> (Duration, BTreeSet<PgTPath>) {
136+
) -> (Duration, BTreeSet<PgLSPath>) {
137137
let start = Instant::now();
138138
fs.traversal(Box::new(move |scope: &dyn TraversalScope| {
139139
for input in inputs {
@@ -299,11 +299,11 @@ pub(crate) struct TraversalOptions<'ctx, 'app> {
299299
pub(crate) remaining_diagnostics: &'ctx AtomicU32,
300300

301301
/// List of paths that should be processed
302-
pub(crate) evaluated_paths: RwLock<BTreeSet<PgTPath>>,
302+
pub(crate) evaluated_paths: RwLock<BTreeSet<PgLSPath>>,
303303
}
304304

305305
impl TraversalOptions<'_, '_> {
306-
pub(crate) fn increment_changed(&self, path: &PgTPath) {
306+
pub(crate) fn increment_changed(&self, path: &PgLSPath) {
307307
self.changed.fetch_add(1, Ordering::Relaxed);
308308
self.evaluated_paths
309309
.write()
@@ -329,15 +329,15 @@ impl TraversalContext for TraversalOptions<'_, '_> {
329329
&self.interner
330330
}
331331

332-
fn evaluated_paths(&self) -> BTreeSet<PgTPath> {
332+
fn evaluated_paths(&self) -> BTreeSet<PgLSPath> {
333333
self.evaluated_paths.read().unwrap().clone()
334334
}
335335

336336
fn push_diagnostic(&self, error: Error) {
337337
self.push_message(error);
338338
}
339339

340-
fn can_handle(&self, pgls_path: &PgTPath) -> bool {
340+
fn can_handle(&self, pgls_path: &PgLSPath) -> bool {
341341
let path = pgls_path.as_path();
342342

343343
let is_valid_file = self.fs.path_is_file(path)
@@ -372,22 +372,22 @@ impl TraversalContext for TraversalOptions<'_, '_> {
372372
true
373373
}
374374

375-
fn handle_path(&self, path: PgTPath) {
375+
fn handle_path(&self, path: PgLSPath) {
376376
handle_file(self, &path)
377377
}
378378

379-
fn store_path(&self, path: PgTPath) {
379+
fn store_path(&self, path: PgLSPath) {
380380
self.evaluated_paths
381381
.write()
382382
.unwrap()
383-
.insert(PgTPath::new(path.as_path()));
383+
.insert(PgLSPath::new(path.as_path()));
384384
}
385385
}
386386

387387
/// This function wraps the [process_file] function implementing the traversal
388388
/// in a [catch_unwind] block and emit diagnostics in case of error (either the
389389
/// traversal function returns Err or panics)
390-
fn handle_file(ctx: &TraversalOptions, path: &PgTPath) {
390+
fn handle_file(ctx: &TraversalOptions, path: &PgLSPath) {
391391
match catch_unwind(move || process_file(ctx, path)) {
392392
Ok(Ok(FileStatus::Changed)) => {
393393
ctx.increment_changed(path);

crates/pgls_cli/src/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ mod service;
2525
mod workspace;
2626

2727
use crate::cli_options::ColorsArg;
28-
pub use crate::commands::{PgtCommand, pgt_command};
28+
pub use crate::commands::{PgLSCommand, pg_l_s_command};
2929
pub use crate::logging::{LoggingLevel, setup_cli_subscriber};
3030
use crate::reporter::Report;
3131
pub use diagnostics::CliDiagnostic;
@@ -57,19 +57,19 @@ impl<'app> CliSession<'app> {
5757
}
5858

5959
/// Main function to run the CLI
60-
pub fn run(self, command: PgtCommand) -> Result<(), CliDiagnostic> {
60+
pub fn run(self, command: PgLSCommand) -> Result<(), CliDiagnostic> {
6161
let has_metrics = command.has_metrics();
6262
if has_metrics {
6363
crate::metrics::init_metrics();
6464
}
6565

6666
let result = match command {
67-
PgtCommand::Version(_) => commands::version::version(self),
68-
PgtCommand::Dblint {
67+
PgLSCommand::Version(_) => commands::version::version(self),
68+
PgLSCommand::Dblint {
6969
cli_options,
7070
configuration,
7171
} => commands::dblint::dblint(self, &cli_options, configuration),
72-
PgtCommand::Check {
72+
PgLSCommand::Check {
7373
cli_options,
7474
configuration,
7575
paths,
@@ -89,21 +89,21 @@ impl<'app> CliSession<'app> {
8989
since,
9090
},
9191
),
92-
PgtCommand::Clean => commands::clean::clean(self),
93-
PgtCommand::Start {
92+
PgLSCommand::Clean => commands::clean::clean(self),
93+
PgLSCommand::Start {
9494
config_path,
9595
log_path,
9696
log_prefix_name,
9797
} => commands::daemon::start(self, config_path, Some(log_path), Some(log_prefix_name)),
98-
PgtCommand::Stop => commands::daemon::stop(self),
99-
PgtCommand::Init => commands::init::init(self),
100-
PgtCommand::LspProxy {
98+
PgLSCommand::Stop => commands::daemon::stop(self),
99+
PgLSCommand::Init => commands::init::init(self),
100+
PgLSCommand::LspProxy {
101101
config_path,
102102
log_path,
103103
log_prefix_name,
104104
..
105105
} => commands::daemon::lsp_proxy(config_path, Some(log_path), Some(log_prefix_name)),
106-
PgtCommand::RunServer {
106+
PgLSCommand::RunServer {
107107
stop_on_disconnect,
108108
config_path,
109109
log_path,
@@ -118,7 +118,7 @@ impl<'app> CliSession<'app> {
118118
Some(log_level),
119119
Some(log_kind),
120120
),
121-
PgtCommand::PrintSocket => commands::daemon::print_socket(),
121+
PgLSCommand::PrintSocket => commands::daemon::print_socket(),
122122
};
123123

124124
if has_metrics {

crates/pgls_cli/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! This is the main binary
22
33
use pgls_cli::{
4-
CliDiagnostic, CliSession, PgtCommand, open_transport, pgt_command, setup_panic_handler,
4+
CliDiagnostic, CliSession, PgLSCommand, open_transport, pg_l_s_command, setup_panic_handler,
55
to_color_mode,
66
};
77
use pgls_console::{ConsoleExt, EnvConsole, markup};
@@ -31,7 +31,7 @@ fn main() -> ExitCode {
3131
set_bottom_frame(main as usize);
3232

3333
let mut console = EnvConsole::default();
34-
let command = pgt_command().fallback_to_usage().run();
34+
let command = pg_l_s_command().fallback_to_usage().run();
3535

3636
console.set_color(to_color_mode(command.get_color()));
3737

@@ -50,7 +50,7 @@ fn main() -> ExitCode {
5050
}
5151
}
5252

53-
fn run_workspace(console: &mut EnvConsole, command: PgtCommand) -> Result<(), CliDiagnostic> {
53+
fn run_workspace(console: &mut EnvConsole, command: PgLSCommand) -> Result<(), CliDiagnostic> {
5454
// If the `--use-server` CLI flag is set, try to open a connection to an
5555
// existing server socket
5656
let workspace = if command.should_use_server() {

crates/pgls_cli/src/reporter/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::cli_options::{CliOptions, CliReporter};
77
use crate::diagnostics::CliDiagnostic;
88
use pgls_console::Console;
99
use pgls_diagnostics::{Error, Severity};
10-
use pgls_fs::PgTPath;
10+
use pgls_fs::PgLSPath;
1111
use std::collections::BTreeSet;
1212
use std::path::PathBuf;
1313
use std::time::Duration;
@@ -54,7 +54,7 @@ impl From<CliReporter> for ReportMode {
5454

5555
#[derive(Debug)]
5656
pub struct TraversalData {
57-
pub evaluated_paths: BTreeSet<PgTPath>,
57+
pub evaluated_paths: BTreeSet<PgLSPath>,
5858
pub changed: usize,
5959
pub unchanged: usize,
6060
pub matches: usize,

crates/pgls_cli/src/reporter/terminal.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use pgls_console::fmt::Formatter;
44
use pgls_console::{Console, ConsoleExt, fmt, markup};
55
use pgls_diagnostics::advice::ListAdvice;
66
use pgls_diagnostics::{Diagnostic, Error, PrintDiagnostic};
7-
use pgls_fs::PgTPath;
7+
use pgls_fs::PgLSPath;
88
use std::borrow::Cow;
99
use std::collections::BTreeSet;
1010

@@ -51,7 +51,7 @@ fn log_diagnostics(console: &mut dyn Console, config: &ReportConfig, diagnostics
5151
}
5252
}
5353

54-
fn log_evaluated_paths(console: &mut dyn Console, evaluated_paths: &BTreeSet<PgTPath>) {
54+
fn log_evaluated_paths(console: &mut dyn Console, evaluated_paths: &BTreeSet<PgLSPath>) {
5555
let evaluated_paths_diagnostic = EvaluatedPathsDiagnostic {
5656
advice: ListAdvice {
5757
list: evaluated_paths

0 commit comments

Comments
 (0)