Skip to content

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

chore: no auto-complete for huge sql (#12003)

rebelice648f5b9c91ec
diff --git a/backend/api/lsp/completion.go b/backend/api/lsp/completion.go
index 0d88c75a62..ebb9ebf99c 100644
--- a/backend/api/lsp/completion.go
+++ b/backend/api/lsp/completion.go
@@ -15,6 +15,11 @@ import (
storepb "github.com/bytebase/bytebase/proto/generated-go/store"
)
+const (
+ // 1MB.
+ contentLengthLimit = 1024 * 1024
+)
+
func newEmptyCompletionList() *lsp.CompletionList {
return &lsp.CompletionList{
IsIncomplete: false,
@@ -33,6 +38,10 @@ func (h *Handler) handleTextDocumentCompletion(ctx context.Context, _ *jsonrpc2.
if err != nil {
return nil, err
}
+ if len(content) > contentLengthLimit {
+ // We don't want to parse a huge file.
+ return newEmptyCompletionList(), nil
+ }
_, valid, why := offsetForPosition(content, params.Position)
if !valid {
return nil, errors.Errorf("invalid position %d:%d (%s)", params.Position.Line, params.Position.Character, why)