Skip to content

Commit 64f21a7

Browse files
Ajit Pratap Singhclaude
authored andcommitted
feat: add VSCode extension for GoSQLX (#72)
Implement official VSCode extension with LSP client integration. Features: - Real-time SQL validation via GoSQLX LSP server - SQL syntax highlighting with comprehensive TextMate grammar - SQL formatting with customizable options (indent, keywords case) - Intelligent autocomplete for SQL keywords and functions - Hover documentation for SQL keywords - SQL analysis command for query complexity - Multi-dialect support (PostgreSQL, MySQL, SQL Server, Oracle, SQLite) Extension components: - package.json: Extension manifest with commands, settings, keybindings - src/extension.ts: LSP client, command handlers, status bar - syntaxes/sql.tmLanguage.json: TextMate grammar (keywords, functions, types) - language-configuration.json: Brackets, comments, indentation rules Commands: - GoSQLX: Validate SQL - GoSQLX: Format SQL - GoSQLX: Analyze SQL - GoSQLX: Restart Language Server Settings: - gosqlx.enable: Enable/disable language server - gosqlx.executablePath: Path to gosqlx binary - gosqlx.format.indentSize: Formatting indent size - gosqlx.format.uppercaseKeywords: Uppercase SQL keywords - gosqlx.dialect: SQL dialect selection Install with: code --install-extension gosqlx-0.1.0.vsix Closes #72 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b429e47 commit 64f21a7

13 files changed

Lines changed: 5544 additions & 0 deletions

vscode-extension/.eslintrc.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": {
5+
"ecmaVersion": 2022,
6+
"sourceType": "module"
7+
},
8+
"plugins": ["@typescript-eslint"],
9+
"extends": [
10+
"eslint:recommended",
11+
"plugin:@typescript-eslint/recommended"
12+
],
13+
"rules": {
14+
"@typescript-eslint/naming-convention": [
15+
"warn",
16+
{
17+
"selector": "import",
18+
"format": ["camelCase", "PascalCase"]
19+
}
20+
],
21+
"@typescript-eslint/semi": "warn",
22+
"curly": "warn",
23+
"eqeqeq": "warn",
24+
"no-throw-literal": "warn",
25+
"semi": "off"
26+
},
27+
"ignorePatterns": ["out", "dist", "**/*.d.ts"]
28+
}

vscode-extension/.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
out/
2+
dist/
3+
node_modules/
4+
.vscode-test/
5+
*.vsix
6+
.DS_Store

vscode-extension/.vscodeignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
.vscode/**
2+
.vscode-test/**
3+
src/**
4+
.gitignore
5+
.yarnrc
6+
vsc-extension-quickstart.md
7+
**/tsconfig.json
8+
**/.eslintrc.json
9+
**/*.map
10+
**/*.ts
11+
node_modules/**
12+
.github/**

vscode-extension/CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Change Log
2+
3+
All notable changes to the "GoSQLX" extension will be documented in this file.
4+
5+
## [0.1.0] - 2025-11-27
6+
7+
### Added
8+
- Initial release of GoSQLX VS Code extension
9+
- Real-time SQL validation via GoSQLX Language Server
10+
- SQL syntax highlighting with comprehensive TextMate grammar
11+
- SQL formatting with customizable options
12+
- Configurable indent size
13+
- Uppercase/lowercase keywords option
14+
- Intelligent autocomplete for SQL keywords and functions
15+
- Hover documentation for SQL keywords
16+
- SQL analysis command for query complexity analysis
17+
- Multi-dialect support (PostgreSQL, MySQL, SQL Server, Oracle, SQLite)
18+
- Extension settings panel
19+
- Command palette integration
20+
- Context menu integration
21+
- Status bar indicator
22+
- Output channel for debugging
23+
24+
### Technical
25+
- Language Server Protocol (LSP) client implementation
26+
- TextMate grammar with patterns for:
27+
- Comments (line and block)
28+
- Strings (single, double, dollar-quoted, backtick)
29+
- Numbers (integer, float, hex)
30+
- Operators (comparison, arithmetic, JSON)
31+
- Keywords (DML, DDL, joins, window functions, CTEs)
32+
- Functions (aggregate, window, string, datetime, math, JSON, array)
33+
- Data types (PostgreSQL comprehensive list)
34+
- Parameters (positional and named)

vscode-extension/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 GoSQLX
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

vscode-extension/README.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# GoSQLX - SQL Parser & Linter for VS Code
2+
3+
High-performance SQL parsing, validation, formatting, and analysis powered by [GoSQLX](https://github.com/ajitpratap0/GoSQLX).
4+
5+
## Features
6+
7+
### Real-time SQL Validation
8+
Get instant feedback on SQL syntax errors as you type. Errors are highlighted directly in the editor with detailed messages.
9+
10+
![Validation](images/validation.gif)
11+
12+
### SQL Formatting
13+
Format your SQL code with customizable indentation and keyword casing.
14+
15+
- **Keyboard shortcut**: `Ctrl+Shift+F` (Windows/Linux) or `Cmd+Shift+F` (Mac)
16+
- **Command palette**: "GoSQLX: Format SQL"
17+
- **Right-click menu**: Format SQL
18+
19+
### Intelligent Autocomplete
20+
Get context-aware suggestions for:
21+
- SQL keywords (100+ supported)
22+
- SQL functions with signatures
23+
- Common SQL snippets and patterns
24+
25+
### Hover Documentation
26+
Hover over SQL keywords to see documentation and usage examples.
27+
28+
### SQL Analysis
29+
Analyze query complexity, find potential issues, and get optimization suggestions.
30+
31+
## Supported SQL Dialects
32+
33+
- PostgreSQL
34+
- MySQL
35+
- SQL Server
36+
- Oracle
37+
- SQLite
38+
- Generic SQL
39+
40+
## Requirements
41+
42+
You need to have the `gosqlx` CLI tool installed:
43+
44+
```bash
45+
# Install via Go
46+
go install github.com/ajitpratap0/GoSQLX/cmd/gosqlx@latest
47+
48+
# Verify installation
49+
gosqlx --version
50+
```
51+
52+
Make sure `gosqlx` is in your system PATH.
53+
54+
## Extension Settings
55+
56+
This extension contributes the following settings:
57+
58+
| Setting | Default | Description |
59+
|---------|---------|-------------|
60+
| `gosqlx.enable` | `true` | Enable GoSQLX language server |
61+
| `gosqlx.executablePath` | `gosqlx` | Path to the gosqlx executable |
62+
| `gosqlx.trace.server` | `off` | Traces communication with the language server |
63+
| `gosqlx.format.indentSize` | `2` | Number of spaces for indentation |
64+
| `gosqlx.format.uppercaseKeywords` | `true` | Convert keywords to uppercase |
65+
| `gosqlx.validation.enable` | `true` | Enable real-time SQL validation |
66+
| `gosqlx.dialect` | `generic` | SQL dialect for validation |
67+
68+
## Commands
69+
70+
| Command | Description |
71+
|---------|-------------|
72+
| `GoSQLX: Validate SQL` | Validate the current SQL file |
73+
| `GoSQLX: Format SQL` | Format the current SQL file |
74+
| `GoSQLX: Analyze SQL` | Analyze query complexity and structure |
75+
| `GoSQLX: Restart Language Server` | Restart the GoSQLX language server |
76+
| `GoSQLX: Show Output Channel` | Show the GoSQLX output channel |
77+
78+
## Performance
79+
80+
GoSQLX delivers exceptional performance:
81+
82+
| Operation | Speed |
83+
|-----------|-------|
84+
| Validation | 1.38M+ ops/sec |
85+
| Formatting | 2,600+ files/sec |
86+
| Parsing | 1.5M+ ops/sec |
87+
88+
## Troubleshooting
89+
90+
### Language server not starting
91+
92+
1. Ensure `gosqlx` is installed and in your PATH:
93+
```bash
94+
which gosqlx
95+
gosqlx --version
96+
```
97+
98+
2. Check the GoSQLX output channel for errors:
99+
- Open Command Palette (`Ctrl+Shift+P`)
100+
- Run "GoSQLX: Show Output Channel"
101+
102+
3. Try specifying the full path in settings:
103+
```json
104+
{
105+
"gosqlx.executablePath": "/path/to/gosqlx"
106+
}
107+
```
108+
109+
### Validation not working
110+
111+
1. Ensure the file has a `.sql` extension
112+
2. Check that `gosqlx.validation.enable` is `true`
113+
3. Restart the language server
114+
115+
## Contributing
116+
117+
Contributions are welcome! Please see our [Contributing Guide](https://github.com/ajitpratap0/GoSQLX/blob/main/CONTRIBUTING.md).
118+
119+
## License
120+
121+
MIT License - see [LICENSE](https://github.com/ajitpratap0/GoSQLX/blob/main/LICENSE)
122+
123+
## Release Notes
124+
125+
### 0.1.0
126+
127+
Initial release:
128+
- Real-time SQL validation
129+
- SQL formatting with customizable options
130+
- Syntax highlighting for SQL
131+
- Intelligent autocomplete
132+
- Hover documentation
133+
- SQL analysis command
134+
- Multi-dialect support

vscode-extension/images/icon.svg

Lines changed: 26 additions & 0 deletions
Loading
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"comments": {
3+
"lineComment": "--",
4+
"blockComment": ["/*", "*/"]
5+
},
6+
"brackets": [
7+
["(", ")"],
8+
["[", "]"],
9+
["{", "}"]
10+
],
11+
"autoClosingPairs": [
12+
{ "open": "(", "close": ")" },
13+
{ "open": "[", "close": "]" },
14+
{ "open": "{", "close": "}" },
15+
{ "open": "'", "close": "'", "notIn": ["string", "comment"] },
16+
{ "open": "\"", "close": "\"", "notIn": ["string", "comment"] },
17+
{ "open": "`", "close": "`", "notIn": ["string", "comment"] },
18+
{ "open": "/*", "close": "*/", "notIn": ["string"] }
19+
],
20+
"surroundingPairs": [
21+
["(", ")"],
22+
["[", "]"],
23+
["{", "}"],
24+
["'", "'"],
25+
["\"", "\""],
26+
["`", "`"]
27+
],
28+
"folding": {
29+
"markers": {
30+
"start": "(?i)^\\s*(BEGIN|CASE|IF|LOOP|WHILE|FOR|CREATE|WITH)\\b",
31+
"end": "(?i)^\\s*(END|;)\\s*$"
32+
}
33+
},
34+
"wordPattern": "[\\w$#@]+",
35+
"indentationRules": {
36+
"increaseIndentPattern": "(?i)^\\s*(SELECT|FROM|WHERE|AND|OR|JOIN|LEFT|RIGHT|INNER|OUTER|CROSS|GROUP|ORDER|HAVING|UNION|INTERSECT|EXCEPT|CASE|WHEN|ELSE|BEGIN|IF|LOOP|WHILE|FOR|WITH)\\b",
37+
"decreaseIndentPattern": "(?i)^\\s*(END|;|\\)|\\])\\s*$"
38+
}
39+
}

0 commit comments

Comments
 (0)