From 02495a122dc44c1f8ec7bc8fd55cb59b60b9ac40 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Tue, 14 Mar 2023 18:23:37 +0000 Subject: [PATCH] schema: Only prefill required fields if enabled --- schema/constraint_object.go | 4 +++ schema/constraint_test.go | 59 +++++++++++++++++++++++++++++++++++-- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/schema/constraint_object.go b/schema/constraint_object.go index 29b596bb..8c47ecb8 100644 --- a/schema/constraint_object.go +++ b/schema/constraint_object.go @@ -74,6 +74,10 @@ func (o Object) EmptyCompletionData(ctx context.Context, placeholder int, nestin TriggerSuggest: triggerSuggest, } + if !prefillRequiredFields(ctx) { + return emptyObjectData + } + attrData, ok := o.attributesCompletionData(ctx, placeholder, nestingLevel) if !ok { return emptyObjectData diff --git a/schema/constraint_test.go b/schema/constraint_test.go index a94f87d6..cb7c6da5 100644 --- a/schema/constraint_test.go +++ b/schema/constraint_test.go @@ -325,13 +325,15 @@ tomap({ func TestConstraint_EmptyCompletionData(t *testing.T) { testCases := []struct { - cons Constraint - expectedCompData CompletionData + cons Constraint + prefillRequiredFields bool + expectedCompData CompletionData }{ { LiteralType{ Type: cty.String, }, + false, CompletionData{ NewText: `"value"`, Snippet: `"${1:value}"`, @@ -344,6 +346,7 @@ func TestConstraint_EmptyCompletionData(t *testing.T) { Type: cty.String, }, }, + false, CompletionData{ NewText: `[ "value" ]`, Snippet: `[ "${1:value}" ]`, @@ -354,6 +357,7 @@ func TestConstraint_EmptyCompletionData(t *testing.T) { LiteralType{ Type: cty.List(cty.String), }, + false, CompletionData{ NewText: `[ "value" ]`, Snippet: `[ "${1:value}" ]`, @@ -366,6 +370,7 @@ func TestConstraint_EmptyCompletionData(t *testing.T) { Type: cty.String, }, }, + false, CompletionData{ NewText: `[ "value" ]`, Snippet: `[ "${1:value}" ]`, @@ -376,6 +381,7 @@ func TestConstraint_EmptyCompletionData(t *testing.T) { LiteralType{ Type: cty.Set(cty.String), }, + false, CompletionData{ NewText: `[ "value" ]`, Snippet: `[ "${1:value}" ]`, @@ -390,6 +396,7 @@ func TestConstraint_EmptyCompletionData(t *testing.T) { "baz": cty.List(cty.String), }), }, + true, CompletionData{ NewText: `{ bar = 0 @@ -415,6 +422,7 @@ func TestConstraint_EmptyCompletionData(t *testing.T) { }), }), }, + true, CompletionData{ NewText: `{ bar = 0 @@ -439,6 +447,7 @@ func TestConstraint_EmptyCompletionData(t *testing.T) { LiteralValue{ Value: cty.StringVal("foobar"), }, + false, CompletionData{ NewText: `"foobar"`, Snippet: `"foobar"`, @@ -449,6 +458,7 @@ func TestConstraint_EmptyCompletionData(t *testing.T) { LiteralValue{ Value: cty.StringVal("foo\nbar"), }, + false, CompletionData{ NewText: `<<