Skip to content

No semantic tokens returned for a function call #431

@rcjsuen

Description

@rcjsuen

This HCL file seems pretty straightforward to me but I don't have any semantic tokens for functions. Is this intentional?

group {
  name = lower("")
}
[{hcl-blockType [] example.tf:1,1-6} {hcl-attrName [] example.tf:2,3-7}]
package main

import (
	"context"
	"fmt"

	"github.com/hashicorp/hcl-lang/decoder"
	"github.com/hashicorp/hcl-lang/lang"
	"github.com/hashicorp/hcl-lang/schema"
	"github.com/hashicorp/hcl/v2"
	"github.com/hashicorp/hcl/v2/hclsyntax"
	"github.com/zclconf/go-cty/cty"
)

type PathReader struct {
	Files map[string]*hcl.File
}

func (pr *PathReader) PathContext(path lang.Path) (*decoder.PathContext, error) {
	schema := &schema.BodySchema{
		Blocks: map[string]*schema.BlockSchema{
			"group": {
				Labels: []*schema.LabelSchema{
					{
						Name: "groupName",
					},
				},
				Body: &schema.BodySchema{
					Attributes: map[string]*schema.AttributeSchema{
						"name": {
							IsOptional: true,
							Constraint: schema.AnyExpression{OfType: cty.String},
						},
					},
				},
			},
		},
	}

	return &decoder.PathContext{Schema: schema, Files: pr.Files}, nil
}

func (pr *PathReader) Paths(ctx context.Context) []lang.Path {
	return []lang.Path{}
}

func main() {
	f, pDiags := hclsyntax.ParseConfig([]byte("group {\n  name = lower(\"\")\n}"), "example.tf", hcl.InitialPos)
	if len(pDiags) > 0 {
		panic(pDiags)
	}

	decoder := decoder.NewDecoder(&PathReader{Files: map[string]*hcl.File{"example.tf": f}})
	pathDecoder, err := decoder.Path(lang.Path{Path: ".", LanguageID: "terraform"})
	if err != nil {
		panic(err)
	}

	tokens, err := pathDecoder.SemanticTokensInFile(context.Background(), "example.tf")
	if err != nil {
		panic(err)
	}
	fmt.Println(tokens)
}

Metadata

Metadata

Assignees

No one assigned

    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