Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: replace go-lsp with lsp-protocol (#15608)
h3n4lbaa327b3e84f
diff --git a/backend/api/lsp/commands.go b/backend/api/lsp/commands.goindex 62f34c0d36..ff1dcb9a7a 100644--- a/backend/api/lsp/commands.go+++ b/backend/api/lsp/commands.go@@ -1,6 +1,8 @@package lsp-import "github.com/sourcegraph/go-lsp"+import (+ lsp "github.com/bytebase/lsp-protocol"+)type CommandName stringdiff --git a/backend/api/lsp/completion.go b/backend/api/lsp/completion.goindex e48273bf9a..a3ca74b93f 100644--- a/backend/api/lsp/completion.go+++ b/backend/api/lsp/completion.go@@ -5,8 +5,8 @@ import ("fmt""log/slog"+ lsp "github.com/bytebase/lsp-protocol""github.com/pkg/errors"- "github.com/sourcegraph/go-lsp""github.com/sourcegraph/jsonrpc2""github.com/bytebase/bytebase/backend/plugin/parser/base"@@ -68,7 +68,7 @@ func (h *Handler) handleTextDocumentCompletion(ctx context.Context, _ *jsonrpc2.DefaultSchema: h.getDefaultSchema(),Metadata: h.GetDatabaseMetadataFunc,ListDatabaseNames: h.ListDatabaseNamesFunc,- }, string(content), params.Position.Line+1, params.Position.Character)+ }, string(content), int(params.Position.Line)+1, int(params.Position.Character))if err != nil {// return errors will close the websocket connection, so we just log the error and return empty completion list.slog.Error("Failed to get completion candidates", "err", err)@@ -88,10 +88,12 @@ func (h *Handler) handleTextDocumentCompletion(ctx context.Context, _ *jsonrpc2.Detail: fmt.Sprintf("(%s)", string(candidate.Type)),Description: candidate.Definition,},- Kind: convertLSPCompletionItemKind(candidate.Type),- Documentation: candidate.Comment,- SortText: generateSortText(params, engine, candidate),- InsertText: candidate.Text,+ Kind: convertLSPCompletionItemKind(candidate.Type),+ Documentation: &lsp.Or_CompletionItem_documentation{+ Value: candidate.Comment,+ },+ SortText: generateSortText(params, engine, candidate),+ InsertText: candidate.Text,}items = append(items, completionItem)}@@ -129,19 +131,19 @@ func generateSortText(_ lsp.CompletionParams, _ storepb.Engine, candidate base.Cfunc convertLSPCompletionItemKind(tp base.CandidateType) lsp.CompletionItemKind {switch tp {case base.CandidateTypeSchema:- return lsp.CIKModule+ return lsp.ModuleCompletioncase base.CandidateTypeDatabase:- return lsp.CIKClass+ return lsp.ClassCompletioncase base.CandidateTypeTable, base.CandidateTypeForeignTable:- return lsp.CIKField+ return lsp.FieldCompletioncase base.CandidateTypeColumn:- return lsp.CIKInterface+ return lsp.InterfaceCompletioncase base.CandidateTypeFunction:- return lsp.CIKFunction+ return lsp.FunctionCompletioncase base.CandidateTypeView, base.CandidateTypeMaterializedView:- return lsp.CIKVariable+ return lsp.VariableCompletiondefault:- return lsp.CIKText+ return lsp.TextCompletion}}diff --git a/backend/api/lsp/custom.go b/backend/api/lsp/custom.goindex 9c31d4a4b1..50f21a8163 100644--- a/backend/api/lsp/custom.go+++ b/backend/api/lsp/custom.go@@ -1,6 +1,6 @@package lsp-import "github.com/sourcegraph/go-lsp"+import lsp "github.com/bytebase/lsp-protocol"type PingResult struct {Result string `json:"result"`diff --git a/backend/api/lsp/fs.go b/backend/api/lsp/fs.goindex f976c8b5d1..8a8eeb1bf2 100644--- a/backend/api/lsp/fs.go+++ b/backend/api/lsp/fs.go@@ -5,8 +5,8 @@ import ("strings""sync"+ lsp "github.com/bytebase/lsp-protocol""github.com/pkg/errors"- "github.com/sourcegraph/go-lsp")// MemFS is an in-memory file system.diff --git a/backend/api/lsp/fs_handler.go b/backend/api/lsp/fs_handler.goindex f6542e3d41..9170b96857 100644--- a/backend/api/lsp/fs_handler.go+++ b/backend/api/lsp/fs_handler.go@@ -7,8 +7,8 @@ import ("log/slog""os"+ lsp "github.com/bytebase/lsp-protocol""github.com/pkg/errors"- "github.com/sourcegraph/go-lsp""github.com/sourcegraph/jsonrpc2""github.com/bytebase/bytebase/backend/common/log"diff --git a/backend/api/lsp/handler.go b/backend/api/lsp/handler.goindex 3f9ddcaea7..6b58858efb 100644--- a/backend/api/lsp/handler.go+++ b/backend/api/lsp/handler.go@@ -7,8 +7,8 @@ import ("log/slog""sync"+ lsp "github.com/bytebase/lsp-protocol""github.com/pkg/errors"- "github.com/sourcegraph/go-lsp""github.com/sourcegraph/jsonrpc2""github.com/bytebase/bytebase/backend/common"@@ -223,12 +223,9 @@ func (h *Handler) handle(ctx context.Context, conn *jsonrpc2.Conn, req *jsonrpc2return nil, err}- kind := lsp.TDSKIncrementalreturn lsp.InitializeResult{Capabilities: lsp.ServerCapabilities{- TextDocumentSync: &lsp.TextDocumentSyncOptionsOrKind{- Kind: &kind,- },+ TextDocumentSync: lsp.Incremental,CompletionProvider: &lsp.CompletionOptions{TriggerCharacters: []string{".", " "},},diff --git a/backend/api/lsp/utils.go b/backend/api/lsp/utils.goindex e9b1530000..55b2a7a44a 100644--- a/backend/api/lsp/utils.go+++ b/backend/api/lsp/utils.go@@ -7,8 +7,8 @@ import ("unicode""unicode/utf8"+ lsp "github.com/bytebase/lsp-protocol""github.com/pkg/errors"- "github.com/sourcegraph/go-lsp")func trimFilePrefix(s string) string {@@ -43,7 +43,7 @@ func offsetForPosition(content []byte, p lsp.Position) (byteOffset int, whyInval}// Validate line number, notes that the Position in LSP is 0-based.- if p.Line >= lineNumber {+ if int(p.Line) >= lineNumber {return 0, errors.Errorf("line number %d out of range [0, %d)", p.Line, lineNumber)}@@ -51,7 +51,7 @@ func offsetForPosition(content []byte, p lsp.Position) (byteOffset int, whyInvaltrimmedContent := content[offset:]col8 := 0- for col16 := 0; col16 < p.Character; col16++ {+ for col16 := 0; col16 < int(p.Character); col16++ {// Unpack the first rune.r, sz := utf8.DecodeRune(trimmedContent)if sz == 0 {@@ -115,7 +115,7 @@ func getSQLStatementRangesUTF16Position(content []byte) []lsp.Range {continue}- begin := lsp.Position{Line: line, Character: character}+ begin := lsp.Position{Line: uint32(line), Character: uint32(character)}for _, r := range statement {if r == '\n' {line++@@ -147,7 +147,7 @@ func getSQLStatementRangesUTF16Position(content []byte) []lsp.Range {endCharacter++}}- end := lsp.Position{Line: endLine, Character: endCharacter}+ end := lsp.Position{Line: uint32(endLine), Character: uint32(endCharacter)}ranges = append(ranges, lsp.Range{Start: begin, End: end})}return rangesdiff --git a/backend/api/lsp/utils_test.go b/backend/api/lsp/utils_test.goindex 811fef13ba..4d137cf2af 100644--- a/backend/api/lsp/utils_test.go+++ b/backend/api/lsp/utils_test.go@@ -3,7 +3,7 @@ package lspimport ("testing"- "github.com/sourcegraph/go-lsp"+ lsp "github.com/bytebase/lsp-protocol""github.com/stretchr/testify/require")diff --git a/backend/plugin/parser/base/diagnose.go b/backend/plugin/parser/base/diagnose.goindex 5efb75c369..1e9cce51d5 100644--- a/backend/plugin/parser/base/diagnose.go+++ b/backend/plugin/parser/base/diagnose.go@@ -1,6 +1,6 @@package base-import "github.com/sourcegraph/go-lsp"+import lsp "github.com/bytebase/lsp-protocol"// DiagnosticContext is the context for diagnosing SQL statements.type DiagnoseContext struct {@@ -13,17 +13,17 @@ func ConvertSyntaxErrorToDiagnostic(err *SyntaxError) Diagnostic {Range: lsp.Range{Start: lsp.Position{// Convert to zero-based.- Line: err.Line - 1,- Character: err.Column,+ Line: uint32(err.Line) - 1,+ Character: uint32(err.Column),},End: lsp.Position{// Convert to zero-based.- Line: err.Line - 1,+ Line: uint32(err.Line) - 1,// The end position is exclusive.- Character: err.Column + 1,+ Character: uint32(err.Column) + 1,},},- Severity: lsp.Error,+ Severity: lsp.SeverityError,Source: "Syntax check",// Use RawMessage which created by antlr runtime, do not need our fine-tuned message// because we had indicated the error position in the message.diff --git a/go.mod b/go.modindex 0b065b4382..9678d6b76b 100644--- a/go.mod+++ b/go.mod@@ -27,6 +27,7 @@ require (github.com/blang/semver/v4 v4.0.0github.com/bytebase/cosmosdb-parser v0.0.0-20250317064006-c1dcb3ed4fa4github.com/bytebase/google-sql-parser v0.0.0-20250116032737-689a327f9465+ github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0github.com/bytebase/mysql-parser v0.0.0-20241224071214-cb9fd84811ddgithub.com/bytebase/plsql-parser v0.0.0-20250218041636-9fed633593d1github.com/bytebase/postgresql-parser v0.0.0-20250213053010-aeb8220eb3bb@@ -79,7 +80,6 @@ require (github.com/snowflakedb/gosnowflake v1.13.1github.com/soheilhy/cmux v0.1.5github.com/sourcegraph/conc v0.3.0- github.com/sourcegraph/go-lsp v0.0.0-20240223163137-f80c5dd31dfdgithub.com/sourcegraph/jsonrpc2 v0.2.0github.com/spf13/cobra v1.9.1github.com/stretchr/testify v1.10.0diff --git a/go.sum b/go.sumindex b47a61fcc4..1b25a0ba28 100644--- a/go.sum+++ b/go.sum@@ -831,8 +831,6 @@ github.com/bytebase/cosmosdb-parser v0.0.0-20250317064006-c1dcb3ed4fa4 h1:mw6ze5github.com/bytebase/cosmosdb-parser v0.0.0-20250317064006-c1dcb3ed4fa4/go.mod h1:sivaOoKlMrXkuude2VGsKv6p83CRRGgblNfeVKQka/Y=github.com/bytebase/gh-ost2 v1.1.7-0.20250310031106-33e16ca4b2e0 h1:wm4Set2lwArmC4f9hYdiunXtEYYzr6SyYRepTXNdkm4=github.com/bytebase/gh-ost2 v1.1.7-0.20250310031106-33e16ca4b2e0/go.mod h1:X0CGYwIZUnjfrv02/nBlftxqSBMm4mYJzFwiyn2D4d8=-github.com/bytebase/go-lsp v0.0.0-20240130071507-c04b5c75010c h1:W832GNANCst4C6TgYbQnKKxbuMZKQxTD4++b3HOuzBo=-github.com/bytebase/go-lsp v0.0.0-20240130071507-c04b5c75010c/go.mod h1:SULmZY7YNBsvNiQbrb/BEDdEJ84TGnfyUQxaHt8t8rY=github.com/bytebase/go-mssqldb v0.0.0-20240801091126-3ff3ca07d898 h1:0ggqA9XL4yvtePPvRDRYMed3jtdNk4s0o8AMW8uJPSA=github.com/bytebase/go-mssqldb v0.0.0-20240801091126-3ff3ca07d898/go.mod h1:2KhUz4GSLcdJGXSJMXAf2BjmakcgoOkNyPpHdGAxRpY=github.com/bytebase/go-obo v0.0.0-20231026081615-705a7fffbfd2 h1:nEHZi8S7PHT4GxP9GfJiuhO8KkYcHmePvy5BfiYxwNk=@@ -843,6 +841,8 @@ github.com/bytebase/google-sql-parser v0.0.0-20250116032737-689a327f9465 h1:Yk6Wgithub.com/bytebase/google-sql-parser v0.0.0-20250116032737-689a327f9465/go.mod h1:edPCw84OriRDnBl+JdtruQ1XoX6dbYR/AkhxyGFRHwg=github.com/bytebase/gosasl v0.0.0-20240422091407-6b7481e86f08 h1:S1GgjJLspz4E4z4CvomGvKgxyv0ATfZm27qHM418jWc=github.com/bytebase/gosasl v0.0.0-20240422091407-6b7481e86f08/go.mod h1:Qx8cW6jkI8riyzmklj80kAIkv+iezFUTBiGU0qHhHes=+github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0 h1:bJ8NSf2K+pccl5m/wuu97fiYjDwpJH6IzURAq/3XA2U=+github.com/bytebase/lsp-protocol v0.0.0-20250324071136-1586d0c10ff0/go.mod h1:BEWMfiZtqshdmulKJcIsWb45MUaEvDO4CROcgi8dfFg=github.com/bytebase/mysql-parser v0.0.0-20241224071214-cb9fd84811dd h1:nKWY30Pq9y/z0+MScRm90KU1U3i0U3j0KGBLN0JL/3M=github.com/bytebase/mysql-parser v0.0.0-20241224071214-cb9fd84811dd/go.mod h1:n22yoTeLcphIYQlV6nbufQbHMxNceOjeGDOrpaRIhiY=github.com/bytebase/partiql-parser v0.0.0-20240531101102-1962ff456f2c h1:TMANvCCN7gpqXHrzRWeWRkPTXmFvTSEyXTZ1Fz20EvM=