Skip to content

Wrong NameRange for namespaced function call expressions #650

@dbanck

Description

@dbanck

#639 introduced namespaced functions. While exploring what's required to support this in terraform-ls, I discovered that the NameRange for function call expressions with the new syntax seems to be off.

Test Code

package main

import (
	"log"

	"github.com/hashicorp/hcl/v2"
	"github.com/hashicorp/hcl/v2/hclsyntax"
)

func main() {
	cfg := `attr = test::noop("noop")`
	f, _ := hclsyntax.ParseConfig([]byte(cfg), "", hcl.InitialPos)
	attrs, _ := f.Body.JustAttributes()
	expr := attrs["attr"].Expr.(*hclsyntax.FunctionCallExpr)
	log.Printf("Name Range: %#v", expr.NameRange)
}

Output

Name Range: hcl.Range{Filename:"", Start:hcl.Pos{Line:1, Column:8, Byte:7}, End:hcl.Pos{Line:1, Column:12, Byte:11}}

Thus, the name range contains only the first part of a namespaced function call, rather than the entire expression up to the opening parenthesis.

attr = test::noop("noop")
       ^^^^ NameRange

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions