feat: add LSP server, VSCode + DataGrip extensions, release infra, autofix
- pkg/lsp: JSON-RPC 2.0 LSP server (formatting, diagnostics, codeAction quick-fixes) - cmd/pgtidy: lsp and config subcommands - pkg/diagnostics: TextFix struct for byte-range autofixes - pkg/lint: MIG001/MIG003 autofixes, ApplyFixes helper, --fix flag on lint command - editors/vscode: TypeScript extension with LanguageClient, showVersion/showConfig/formatDocument commands, logo - editors/datagrip: Gradle JetBrains plugin via LSP4IJ, pluginIcon - .goreleaser.yaml, .github/workflows: CI + release pipeline - Makefile: snapshot, release, vscode-compile, vscode-package targets - go.mod + all imports: module path updated to git.warky.dev/wdevs/pgtidy - assets: logo files (256px, 128px, 1024px, ico)
This commit is contained in:
+28
-2
@@ -6,8 +6,8 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/hein/pgtidy/pkg/diagnostics"
|
||||
"github.com/hein/pgtidy/pkg/lint"
|
||||
"git.warky.dev/wdevs/pgtidy/pkg/diagnostics"
|
||||
"git.warky.dev/wdevs/pgtidy/pkg/lint"
|
||||
)
|
||||
|
||||
// cmdLint implements `pgtidy lint`. Reads one or more SQL files (or stdin) and
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
func cmdLint(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
|
||||
var (
|
||||
only []string // --only=ID,ID rule filter
|
||||
fix bool
|
||||
files []string
|
||||
)
|
||||
for _, a := range args {
|
||||
@@ -26,6 +27,8 @@ func cmdLint(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
|
||||
case a == "-h" || a == "--help":
|
||||
lintUsage(stdout)
|
||||
return 0
|
||||
case a == "--fix":
|
||||
fix = true
|
||||
case strings.HasPrefix(a, "--only="):
|
||||
ids := strings.Split(strings.TrimPrefix(a, "--only="), ",")
|
||||
for _, id := range ids {
|
||||
@@ -89,6 +92,13 @@ func cmdLint(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
|
||||
fmt.Fprintf(stderr, "pgtidy: %v\n", err)
|
||||
return 2
|
||||
}
|
||||
if fix {
|
||||
fixed := lint.ApplyFixes(string(src), diags)
|
||||
if fixed != string(src) {
|
||||
io.WriteString(stdout, fixed)
|
||||
return 0
|
||||
}
|
||||
}
|
||||
printDiags(diags)
|
||||
if len(diags) > 0 {
|
||||
found = true
|
||||
@@ -105,6 +115,21 @@ func cmdLint(args []string, stdin io.Reader, stdout, stderr io.Writer) int {
|
||||
fmt.Fprintf(stderr, "pgtidy: %v\n", err)
|
||||
return 2
|
||||
}
|
||||
if fix {
|
||||
fixed := lint.ApplyFixes(string(src), diags)
|
||||
if fixed != string(src) {
|
||||
if err := os.WriteFile(path, []byte(fixed), 0o644); err != nil {
|
||||
fmt.Fprintf(stderr, "pgtidy: writing %s: %v\n", path, err)
|
||||
return 2
|
||||
}
|
||||
// Re-check to report any remaining unfixed diagnostics.
|
||||
diags, err = check(fixed, path)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "pgtidy: %v\n", err)
|
||||
return 2
|
||||
}
|
||||
}
|
||||
}
|
||||
printDiags(diags)
|
||||
if len(diags) > 0 {
|
||||
found = true
|
||||
@@ -124,6 +149,7 @@ func lintUsage(w io.Writer) {
|
||||
Read SQL from files (or stdin) and report lint findings.
|
||||
|
||||
Flags:
|
||||
--fix Apply autofixes for fixable rules (MIG001, MIG003) and rewrite files
|
||||
--only=ID,... comma-separated rule IDs to enable (default: all rules)
|
||||
-h, --help show this help
|
||||
|
||||
|
||||
Reference in New Issue
Block a user