@@ -10,7 +10,7 @@ func formatFieldAndType(t ast.Expr, id *ast.Ident) string {
1010 return id .String () + " " + typeStr
1111}
1212
13- func formatFuncParams (params * ast.FieldList ) (string , int ) {
13+ func formatFieldsList (params * ast.FieldList , joinChar string ) (string , int ) {
1414 if params == nil {
1515 return "" , 0
1616 }
@@ -30,7 +30,7 @@ func formatFuncParams(params *ast.FieldList) (string, int) {
3030 }
3131 }
3232
33- return strings .Join (fieldTypePair , ", " ), paramsLen
33+ return strings .Join (fieldTypePair , joinChar ), paramsLen
3434}
3535
3636func valSpecToItem (isConst bool , v * ast.ValueSpec , withPrivate bool ) []* CompletionItem {
@@ -61,26 +61,30 @@ func valSpecToItem(isConst bool, v *ast.ValueSpec, withPrivate bool) []*Completi
6161 return items
6262}
6363
64- func funcToItem (fn * ast.FuncDecl ) * CompletionItem {
65- ci := & CompletionItem {
66- Label : fn .Name .String (),
67- Kind : Function ,
68- Documentation : fn .Doc .Text (),
69- }
70-
71- params , _ := formatFuncParams (fn .Type .Params )
72- ci .Detail = "func(" + params + ")"
73- ci .InsertText = ci .Label + "(" + params + ")"
74-
75- returns , retCount := formatFuncParams (fn .Type .Results )
64+ func funcToString (fn * ast.FuncType ) string {
65+ params , _ := formatFieldsList (fn .Params , ", " )
66+ str := "func(" + params + ")"
67+ returns , retCount := formatFieldsList (fn .Results , ", " )
7668 switch retCount {
7769 case 0 :
7870 break
7971 case 1 :
80- ci . Detail += " " + returns
72+ str += " " + returns
8173 default :
82- ci .Detail += " (" + returns + ")"
74+ str += " (" + returns + ")"
75+ }
76+
77+ return str
78+ }
79+
80+ func funcToItem (fn * ast.FuncDecl ) * CompletionItem {
81+ ci := & CompletionItem {
82+ Label : fn .Name .String (),
83+ Kind : Function ,
84+ Documentation : fn .Doc .Text (),
8385 }
8486
87+ ci .Detail = funcToString (fn .Type )
88+ ci .InsertText = ci .Label + "()"
8589 return ci
8690}
0 commit comments