Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve completion within objects and maps with incomplete configuration #345

Open
dbanck opened this issue Nov 17, 2023 · 0 comments
Open
Labels
bug Something isn't working

Comments

@dbanck
Copy link
Member

dbanck commented Nov 17, 2023

Context

While implementing template expressions in #322, we discovered some edge cases for template expressions inside objects and maps. In the past, we ran into similar problems with completion inside objects and maps with incomplete configuration.

Nested ObjectConsExpr

Completion currently fails for nested objects where the inner object is incomplete

attr = {
  foo = {
    bar
  }
}

Nested TemplateExpr

Completion currently fails for empty template expressions inside objects

default = {
  foo = "foo-${}"
}

Example test case for maps:

{
	"expression within map",
	map[string]*schema.AttributeSchema{
		"attr": {
			Constraint: schema.Map{
				Elem: schema.AnyExpression{OfType: cty.String},
			},
		},
	},
	reference.Targets{
		{
			Addr: lang.Address{
				lang.RootStep{Name: "var"},
				lang.AttrStep{Name: "bar"},
			},
			RangePtr: &hcl.Range{
				Filename: "variables.tf",
				Start:    hcl.Pos{Line: 2, Column: 1, Byte: 17},
				End:      hcl.Pos{Line: 2, Column: 3, Byte: 19},
			},
			Type: cty.String,
		},
	},
	`attr = {
foo = "foo-${}"
}
`,
	hcl.Pos{Line: 2, Column: 16, Byte: 24},
	lang.CompleteCandidates([]lang.Candidate{
		{
			Label:  "var.bar",
			Detail: "string",
			Kind:   lang.TraversalCandidateKind,
			TextEdit: lang.TextEdit{
				NewText: "var.bar",
				Snippet: "var.bar",
				Range: hcl.Range{
					Filename: "test.tf",
					Start:    hcl.Pos{Line: 2, Column: 16, Byte: 24},
					End:      hcl.Pos{Line: 2, Column: 16, Byte: 24},
				},
			},
		},
	}),
},

Proposal

We have filed two upstream issues in HCL that need to be addressed first and will likely fix the problem already:

We should add/update the tests for objects, maps, and template expression to make sure the feature works as expected.

@dbanck dbanck added the bug Something isn't working label Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant