Skip to content

Commit 7c1eec9

Browse files
committed
chore: docs
1 parent 614562c commit 7c1eec9

5 files changed

Lines changed: 100 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ The following features are implemented:
2626
- Syntax Error Highlighting
2727
- Type-checking (via `EXPLAIN` error insights)
2828
- Linter, inspired by [Squawk](https://squawkhq.com)
29+
- Formatting
2930

3031
Our current focus is on refining and enhancing these core features while building a robust and easily accessible infrastructure. For future plans and opportunities to contribute, please check out the issues and discussions. Any contributions are welcome!
3132

docs/configuration.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ A configuration file is usually placed in your project’s root folder. It is or
2222
},
2323
"plpgsqlCheck": {
2424
"enabled": true
25+
},
26+
"format": {
27+
"enabled": true,
28+
"keywordCase": "lower"
2529
}
2630
}
2731
```

docs/features/formatting.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# Formatting
2+
3+
> **Preview Feature**: The formatter is currently in preview. We'd love feedback from early adopters! Please report any issues or unexpected output at [GitHub Issues](https://github.com/supabase-community/postgres-language-server/issues).
4+
5+
The language server provides SQL formatting that produces consistent, readable code. Built on Postgres' own parser, the formatter ensures 100% syntax compatibility with your SQL.
6+
7+
## Configuration
8+
9+
Configure formatting behavior in your `postgres-language-server.jsonc`:
10+
11+
```json
12+
{
13+
"format": {
14+
"enabled": true,
15+
"lineWidth": 100,
16+
"indentSize": 2,
17+
"indentStyle": "spaces",
18+
"keywordCase": "lower",
19+
"constantCase": "lower",
20+
"typeCase": "lower"
21+
}
22+
}
23+
```
24+
25+
### Options
26+
27+
| Option | Default | Description |
28+
|--------|---------|-------------|
29+
| `enabled` | `true` | Enable or disable the formatter |
30+
| `lineWidth` | `100` | Maximum line width before breaking |
31+
| `indentSize` | `2` | Number of spaces (or tab width) for indentation |
32+
| `indentStyle` | `"spaces"` | Use `"spaces"` or `"tabs"` for indentation |
33+
| `keywordCase` | `"lower"` | Casing for SQL keywords: `"upper"` or `"lower"` |
34+
| `constantCase` | `"lower"` | Casing for constants (NULL, TRUE, FALSE): `"upper"` or `"lower"` |
35+
| `typeCase` | `"lower"` | Casing for data types (text, int, varchar): `"upper"` or `"lower"` |
36+
37+
### Example Output
38+
39+
With default settings (lowercase):
40+
41+
```sql
42+
create table users (
43+
id serial primary key,
44+
name text not null,
45+
active boolean default true
46+
);
47+
48+
select * from users where active = true;
49+
```
50+
51+
With uppercase keywords and constants:
52+
53+
```sql
54+
CREATE TABLE users (
55+
id serial PRIMARY KEY,
56+
name text NOT NULL,
57+
active boolean DEFAULT TRUE
58+
);
59+
60+
SELECT * FROM users WHERE active = TRUE;
61+
```
62+
63+
## CLI Usage
64+
65+
Format files using the CLI:
66+
67+
```bash
68+
# Format and show diff
69+
postgres-language-server format file.sql
70+
71+
# Format and write changes
72+
postgres-language-server format file.sql --write
73+
74+
# Format entire directory
75+
postgres-language-server format migrations/ --write
76+
```
77+
78+
## Editor Integration
79+
80+
The formatter integrates with your editor via the Language Server Protocol. Use your editor's format document command (typically bound to a keyboard shortcut) to format SQL files.
81+
82+
## Ignoring Files
83+
84+
Use the `ignore` and `include` options to control which files are formatted:
85+
86+
```json
87+
{
88+
"format": {
89+
"ignore": ["**/generated/**", "**/vendor/**"],
90+
"include": ["**/*.sql"]
91+
}
92+
}
93+
```

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ The following features are available today:
1717
- [Syntax Diagnostics](features/syntax_diagnostics.md)
1818
- [Linting](features/linting.md)
1919
- [Type Checking](features/type_checking.md)
20+
- [Formatting](features/formatting.md) (Preview)
2021
- [PL/pgSQL Support](features/plpgsql.md)
2122
- [Autocompletion & Hover](features/editor_features.md)
2223

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ nav:
2121
- Linting: features/linting.md
2222
- Database Linting: features/database_linting.md
2323
- Type Checking: features/type_checking.md
24+
- Formatting: features/formatting.md
2425
- PL/pgSQL Support: features/plpgsql.md
2526
- Autocompletion & Hover: features/editor_features.md
2627
- Guides:

0 commit comments

Comments
 (0)