Skip to content
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ jobs:
with:
install-lib: false
- name: Build main binary
run: cargo build -p pgt_cli --release
run: cargo build -p pgls_cli --release
- name: Setup Bun
uses: oven-sh/setup-bun@v2
- name: Install JS dependencies
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres

- name: 🛠️ Run Build
run: cargo build -p pgt_cli --release --target ${{ matrix.config.target }}
run: cargo build -p pgls_cli --release --target ${{ matrix.config.target }}
env:
# Strip all debug symbols from the resulting binaries
RUSTFLAGS: "-C strip=symbols -C codegen-units=1"
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "crates/pgt_query/vendor/libpg_query"]
path = crates/pgt_query/vendor/libpg_query
path = crates/pgls_query/vendor/libpg_query
url = https://github.com/pganalyze/libpg_query.git
branch = 17-latest
52 changes: 26 additions & 26 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ just test
# or: cargo test run --no-fail-fast

# Test specific crate
just test-crate pgt_lsp
just test-crate pgls_lsp

# Run doc tests
just test-doc
Expand Down Expand Up @@ -64,41 +64,41 @@ just new-crate <name>
### CLI Usage
The main CLI binary is `postgrestools`:
```bash
cargo run -p pgt_cli -- check file.sql
cargo run -p pgls_cli -- check file.sql
# or after building:
./target/release/postgrestools check file.sql
```

## Architecture

### Crate Structure
The project uses a modular Rust workspace with crates prefixed with `pgt_`:
The project uses a modular Rust workspace with crates prefixed with `pgls_`:

**Core Infrastructure:**
- `pgt_workspace` - Main API and workspace management
- `pgt_lsp` - Language Server Protocol implementation
- `pgt_cli` - Command-line interface
- `pgt_fs` - Virtual file system abstraction
- `pgt_configuration` - Configuration management
- `pgls_workspace` - Main API and workspace management
- `pgls_lsp` - Language Server Protocol implementation
- `pgls_cli` - Command-line interface
- `pgls_fs` - Virtual file system abstraction
- `pgls_configuration` - Configuration management

**Parser and Language Processing:**
- `pgt_query` - Postgres query parsing (wraps libpg_query)
- `pgt_lexer` - SQL tokenizer with whitespace handling
- `pgt_statement_splitter` - Splits source into individual statements
- `pgt_treesitter` - Tree-sitter integration for additional parsing
- `pgls_query` - Postgres query parsing (wraps libpg_query)
- `pgls_lexer` - SQL tokenizer with whitespace handling
- `pgls_statement_splitter` - Splits source into individual statements
- `pgls_treesitter` - Tree-sitter integration for additional parsing

**Features:**
- `pgt_completions` - Autocompletion engine
- `pgt_hover` - Hover information provider
- `pgt_analyser` & `pgt_analyse` - Linting and analysis framework
- `pgt_typecheck` - Type checking via EXPLAIN
- `pgt_schema_cache` - In-memory database schema representation
- `pgls_completions` - Autocompletion engine
- `pgls_hover` - Hover information provider
- `pgls_analyser` & `pgls_analyse` - Linting and analysis framework
- `pgls_typecheck` - Type checking via EXPLAIN
- `pgls_schema_cache` - In-memory database schema representation

**Utilities:**
- `pgt_diagnostics` - Error and warning reporting
- `pgt_console` - Terminal output and formatting
- `pgt_text_edit` - Text manipulation utilities
- `pgt_suppressions` - Rule suppression handling
- `pgls_diagnostics` - Error and warning reporting
- `pgls_console` - Terminal output and formatting
- `pgls_text_edit` - Text manipulation utilities
- `pgls_suppressions` - Rule suppression handling

### TypeScript Packages
Located in `packages/` and `editors/`:
Expand All @@ -111,15 +111,15 @@ The server connects to a Postgres database to build an in-memory schema cache co

### Statement Processing Flow
1. Input source code is split into individual SQL statements
2. Each statement is parsed using libpg_query (via `pgt_query`)
2. Each statement is parsed using libpg_query (via `pgls_query`)
3. Statements are analyzed against the schema cache
4. Results are cached and updated incrementally on file changes

## Testing

### Test Data Location
- SQL test cases: `crates/pgt_statement_splitter/tests/data/`
- Analyzer test specs: `crates/pgt_analyser/tests/specs/`
- SQL test cases: `crates/pgls_statement_splitter/tests/data/`
- Analyzer test specs: `crates/pgls_analyser/tests/specs/`
- Example SQL files: `example/`, `test.sql`

### Snapshot Testing
Expand All @@ -145,10 +145,10 @@ cargo insta review
## Development Notes

### Code Generation
Many parser structures are generated from PostgreSQL's protobuf definitions using procedural macros in `pgt_query_macros`. Run `just gen-lint` after modifying analyzer rules or configurations.
Many parser structures are generated from PostgreSQL's protobuf definitions using procedural macros in `pgls_query_macros`. Run `just gen-lint` after modifying analyzer rules or configurations.

### Database Schema
The `pgt_schema_cache` crate contains SQL queries in `src/queries/` that introspect the database schema to build the in-memory cache.
The `pgls_schema_cache` crate contains SQL queries in `src/queries/` that introspect the database schema to build the in-memory cache.

### Multi-Platform Support
The project includes platform-specific allocators and build configurations for Windows, macOS, and Linux.
Expand Down
Loading