Skip to content

feat: architecture and lsp features #128

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 48 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
ace84f1
feat: simple server
psteinroe Mar 14, 2024
b51b52f
feat: basic base db
psteinroe Mar 14, 2024
009c669
feat: untested doc sync with simple tree sitter parser
psteinroe Mar 14, 2024
9ff86ae
feat: impl changes in base db
psteinroe Mar 17, 2024
e96e936
chore: save stuff before altering everything
psteinroe Mar 26, 2024
e60c8e1
refactor: implement new change
psteinroe Mar 30, 2024
b1af92d
fix: bugs in doc change
psteinroe Mar 30, 2024
13d9144
fix: minor bug and bring back tests
psteinroe Apr 5, 2024
0c7d7a0
feat: ide create with poc for tree sitter
psteinroe Apr 5, 2024
6985e25
feat: add pg query parser
psteinroe Apr 6, 2024
5ef29ed
feat: progress on sql parser
psteinroe Apr 8, 2024
baf2b95
feat: migrate to new parser crate and cleanup statement change
psteinroe Apr 10, 2024
0e9d927
chore: progress
psteinroe Apr 12, 2024
d397763
fix: make it run again
psteinroe Apr 29, 2024
77e3507
fix: db connection and config load
psteinroe May 12, 2024
76a8ffa
fix: schema cache and listener
psteinroe May 13, 2024
501516f
feat: diagnostic infra and native errors
psteinroe May 20, 2024
1fb094f
feat: wip hover
psteinroe May 20, 2024
ec41f63
feat: hover crate
psteinroe May 21, 2024
8e02824
feat: add hover to ide
psteinroe May 29, 2024
4df116f
feat: lint
psteinroe Jun 3, 2024
a8232b3
feat: type checkerrrrr create
psteinroe Jun 5, 2024
8935eb6
feat: work on compute ergonomics
psteinroe Jun 20, 2024
404d720
fix: deletion within statement
psteinroe Jun 21, 2024
9bc53d5
fix: ergonomics
psteinroe Jun 23, 2024
7ab4895
feat: execute statement command
psteinroe Jun 23, 2024
5457575
feat: add fns to schema cache
psteinroe Jun 23, 2024
13c0708
feat: inlay hints and type resolver crate
psteinroe Jul 5, 2024
ad210c9
fix: tests
psteinroe Jul 5, 2024
aa230cd
feat: autocomplete
psteinroe Jul 11, 2024
92b209e
chore: cleanup
psteinroe Jul 12, 2024
573285f
refactor: all crates
psteinroe Jul 20, 2024
24c2180
refactor: move non-pg crates to lib dir
psteinroe Jul 21, 2024
703d385
fix: git module path
psteinroe Jul 21, 2024
4812459
fix: tests
psteinroe Jul 21, 2024
6f992cd
chore: add back tests for statement splitter
psteinroe Jul 21, 2024
a2a2c67
chore: add back tests for pg_syntax
psteinroe Jul 21, 2024
d48c468
chore: remoev pg regress tests for now
psteinroe Jul 21, 2024
6b42cf5
docs: add architecture
psteinroe Jul 31, 2024
a836f91
chore: docs for hover
psteinroe Jul 31, 2024
e004a56
chore: readme
psteinroe Aug 2, 2024
1ba05ed
chore: readme
psteinroe Aug 2, 2024
e089ae5
chore: merge mani
psteinroe Aug 2, 2024
f550edf
fix: lockfile
psteinroe Aug 2, 2024
d5e3e79
fix: feature
psteinroe Aug 2, 2024
2cb1019
fix: unused
psteinroe Aug 2, 2024
4c8b942
fix: unused
psteinroe Aug 2, 2024
063e2e1
fix: unused
psteinroe Aug 2, 2024
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
  •  
  •  
  •  
6 changes: 6 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ jobs:
ports:
- 5432:5432

env:
DB_CONNECTION_STRING: postgresql://postgres:postgres@localhost:5432/postgres

steps:
- name: 🏗 Setup repository
uses: actions/checkout@v3
Expand All @@ -38,6 +41,9 @@ jobs:
with:
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Run test migrations
run: psql -f test-db/seed.sql postgresql://postgres:postgres@localhost:5432/postgres

- name: 📦 Build
id: build
run: cargo build
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
path = libpg_query
url = https://github.com/pganalyze/libpg_query.git
[submodule "crates/tree_sitter_sql/tree-sitter-sql"]
path = crates/tree_sitter_sql/tree-sitter-sql
path = lib/tree_sitter_sql/tree-sitter-sql
url = https://github.com/DerekStride/tree-sitter-sql
branch = gh-pages
71 changes: 71 additions & 0 deletions ARCHITECTURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
## Architecture

This document describes the high-level architecture of postgres_lsp. If you want to familiarize yourself with the code base, you are just in the right place!

> Since the project still evolves rapidly, this document may not be up-to-date. If you find any inconsistency, please let us know by creating an issue.

### Bird's Eye View

On the highest level, the postgres language server is a thing which accepts input source code, cuts it into individual sql statements and parses and analyses each. In addition, it connects to a postgres database and stores an im-memory schema cache with all required type information such as tables, columns and functions. The result of the parsing is used alongside the schema cache to answer queries about a statement.

The client can submit a delta of input data (typically, a change to a single file), and the server will update the affected statements and their analysis accordingly. The underlying engine makes sure that we only re-parse and re-analyse what is necessary.

### Entry Points

The main entry point is as of now the `pg_lsp` crate, especially the `main.rs` function. It spawns the language server and starts listening for incoming messages. The server is implemented in the `server` module.

There might be an additional entry point for a CLI tool in the future.

### Code Map

This section talks briefly about various important directories and data structures.

#### `lib/`

Independent libraries that are used by the project but are not specific for postgres.

#### `crates/pg_lsp`

The main entry point of the language server. It contains the server implementation and the main loop.

#### `crates/pg_workspace`

> This crate will grow significantly in near future. The current implementation just contains the base data structures and stores the diagnostic results from various features.

The main API for consumers of the IDE. It stores the internal state of the workspace, such as the schema cache and the parsed statements and their analysis.

#### `crates/pg_lexer`

Simple lexer that tokenizes the input source code. Enhances the output of the `pg_query` tokenizer with the missing whitespace tokens.

#### `crates/pg_statement_splitter`

Implements the statement splitter, which cuts the input source code into individual statements.

#### `crates/pg_base_db`

Implements the base data structures and defines how documents and statements are stored and updated efficiently.

#### `crates/pg_schema_cache`

We store an in-memory representation of the database schema to efficiently resolve types.

#### `crates/pg_query_ext`

Simple wrapper crate for `pg_query` to expose types and a function to get the root node for an SQL statement. It also host any "extensions" to the `pg_query` crate that are not yet contributed upstream. Once all extensions are contributed upstream, this crate will be removed.

#### `crates/pg_query_proto_parser`

We use procedural macros a lot to generate repetitive code from the protobuf definition provided by `libg_query`. The `pg_query_proto_parser` crate is used to parse the proto file into a more usable data structure.

#### `crates/pg_syntax`

Implements the CST parser and AST enhancer. The CST parser is what is described in [this blog post](https://supabase.com/blog/postgres-language-server-implementing-parser). The AST enhancer takes in the CST and enriches the AST returned by `pg_query` with a range for each node.

#### `crates/pg_type_resolver`

Utility crate used by the feature crates listed below to resolve the source types to the actual types in the schema cache.

#### `crates/pg_commands`, `crates/pg_completions`, `crates/pg_hover`, `crates/pg_inlay_hints`, `crates/pg_lint`, `crates/pg_typecheck`

These crates implement the various features of the language server. They are all independent of each other and always operate on the schema cache and a single statement and its parse results. They are intentionally implemented in separate creates and without any language server flavour to make them reusable eg in a later cli.
Loading
Loading