Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore(LSP): log database error for LSP (#9223)

rebelice4c93b9ad959f
diff --git a/backend/api/lsp/completion.go b/backend/api/lsp/completion.go
index 1137fe29f1..95dbbd88f1 100644
--- a/backend/api/lsp/completion.go
+++ b/backend/api/lsp/completion.go
@@ -3,6 +3,7 @@ package lsp
import (
"context"
"fmt"
+ "log/slog"
"github.com/pkg/errors"
"github.com/sourcegraph/go-lsp"
@@ -14,6 +15,13 @@ import (
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
+func newEmptyCompletionList() *lsp.CompletionList {
+ return &lsp.CompletionList{
+ IsIncomplete: false,
+ Items: []lsp.CompletionItem{},
+ }
+}
+
func (h *Handler) handleTextDocumentCompletion(ctx context.Context, _ *jsonrpc2.Conn, _ *jsonrpc2.Request, params lsp.CompletionParams) (*lsp.CompletionList, error) {
if !IsURI(params.TextDocument.URI) {
return nil, &jsonrpc2.Error{
@@ -33,11 +41,15 @@ func (h *Handler) handleTextDocumentCompletion(ctx context.Context, _ *jsonrpc2.
defaultDatabase := h.getDefaultDatabase()
engine := h.getEngineType(ctx)
if engine == storepb.Engine_ENGINE_UNSPECIFIED {
- return nil, errors.Errorf("engine is not specified")
+ // return errors will close the websocket connection, so we just log the error and return empty completion list.
+ slog.Error("Engine is not specified")
+ return newEmptyCompletionList(), nil
}
candidates, err := base.Completion(ctx, engine, string(content), params.Position.Line+1, params.Position.Character, defaultDatabase, h.GetDatabaseMetadataFunc)
if err != nil {
- return nil, errors.Wrap(err, "failed to get completion candidates")
+ // 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)
+ return newEmptyCompletionList(), nil
}
var items []lsp.CompletionItem