diff --git a/decoder/hover.go b/decoder/hover.go index 6db364d9..eb7e7af4 100644 --- a/decoder/hover.go +++ b/decoder/hover.go @@ -262,7 +262,10 @@ func (d *PathDecoder) hoverDataForExpr(expr hcl.Expression, constraints ExprCons f, ok := d.pathCtx.Functions[e.Name] if ok { return &lang.HoverData{ - Content: lang.Markdown(fmt.Sprintf("```hcl\n%s(%s) %s\n```\n\n%s", e.Name, f.ParameterSignature(), f.ReturnTypes.FriendlyName(), f.Description)), + // We could use a code block here, but the highlighting of type names + // conflicts with the naming of function parameters + // e.g. a parameter named list + Content: lang.Markdown(fmt.Sprintf("`%s(%s) %s`\n\n%s", e.Name, f.ParameterSignature(), f.ReturnTypes.FriendlyName(), f.Description)), Range: expr.Range(), }, nil } diff --git a/decoder/signature.go b/decoder/signature.go index a1df59ef..ccb64cc5 100644 --- a/decoder/signature.go +++ b/decoder/signature.go @@ -51,17 +51,34 @@ func (d *PathDecoder) SignatureAtPos(filename string, pos hcl.Pos) (*lang.FuncSi return nil // Unknown function } - // TODO this should be based on `pos` and not the count of parameters - // a new entry is added to `Args` only after a user adds content, like "" - // not after a user types a `,` - // TODO this need to account for variadic arguments (VarParam) - activePar := max(len(fNode.Args)-1, 0) + activePar := 0 // default to first parameter + foundActivePar := false + // TODO check paren rage + for i, v := range fNode.Args { + if v.Range().ContainsPos(pos) { + activePar = i + foundActivePar = true + break + } + } + + if !foundActivePar { + // TODO how to account for spaces and commas? + // use f.Bytes + } paramsLen := len(f.Params) if f.VarParam != nil { paramsLen += 1 } + if activePar > paramsLen { + // there are multiple variadic parameters defined, so + // we want to highlight the variadic parameter in the + // function signature + activePar = paramsLen - 1 + } + parameters := make([]lang.FuncParameter, 0, paramsLen) for _, p := range f.Params { parameters = append(parameters, lang.FuncParameter{