@@ -1281,14 +1281,23 @@ func (c *gopCompleter) selector(ctx context.Context, sel *ast.SelectorExpr) erro
12811281 paramList ("(" , ")" , fn .Type .Params )
12821282
12831283 item .snippet = & sn
1284+ } else if tok == token .FUNC {
1285+ // ast.OverloadFuncDecl
1286+ item .isOverload = true
1287+ item .Detail = "Go+ overload func\n \n " + item .Detail
12841288 }
12851289
12861290 cMu .Lock ()
12871291 c .items = append (c .items , item )
12881292 // goxls func alias
12891293 if tok == token .FUNC {
12901294 if alias , ok := hasAliasName (id .Name ); ok {
1291- noSnip := len (fn .Type .Params .List ) == 0
1295+ var noSnip bool
1296+ if fn != nil {
1297+ noSnip = len (fn .Type .Params .List ) == 0
1298+ } else {
1299+ noSnip = true
1300+ }
12921301 c .items = append (c .items , cloneAliasItem (item , id .Name , alias , 0.0001 , noSnip ))
12931302 }
12941303 }
@@ -1333,45 +1342,7 @@ func (c *gopCompleter) selector(ctx context.Context, sel *ast.SelectorExpr) erro
13331342 if err := g .Wait (); err != nil {
13341343 return err
13351344 }
1336- // check gop packages index overload
1337- for pkg , items := range recheck .items {
1338- if recheck .pkgs [pkg ] {
1339- names := make (map [string ]bool )
1340- sort .Slice (items , func (i , j int ) bool {
1341- return items [i ].Label < items [j ].Label
1342- })
1343- for _ , item := range items {
1344- id := item .Label [:len (item .Label )- 3 ]
1345- if ! names [id ] {
1346- names [id ] = true
1347- item .isOverload = true
1348- c .items = append (c .items , cloneAliasItem (item .CompletionItem , item .Label , id , 0 , false ))
1349- if alias , ok := hasAliasName (id ); ok {
1350- c .items = append (c .items , cloneAliasItem (item .CompletionItem , item .Label , alias , 0.0001 , item .noSnip ))
1351- }
1352- }
1353- }
1354- } else {
1355- for _ , item := range items {
1356- c .items = append (c .items , item .CompletionItem )
1357- if alias , ok := hasAliasName (item .Label ); ok {
1358- c .items = append (c .items , cloneAliasItem (item .CompletionItem , item .Label , alias , 0.0001 , item .noSnip ))
1359- }
1360- }
1361- }
1362- }
1363- // check gop packages gopo overload
1364- for pkg , items := range recheck .gopo {
1365- if recheck .pkgs [pkg ] {
1366- for _ , item := range items {
1367- c .items = append (c .items , item )
1368- if alias , ok := hasAliasName (item .Label ); ok {
1369- c .items = append (c .items , cloneAliasItem (item , item .Label , alias , 0.0001 , true ))
1370- }
1371- }
1372- }
1373- }
1374-
1345+ recheck .checkOverload (c )
13751346 // In addition, we search in the module cache using goimports.
13761347 ctx , cancel := context .WithCancel (ctx )
13771348 var mu sync.Mutex
@@ -1413,12 +1384,6 @@ type recheckItem struct {
14131384 noSnip bool
14141385}
14151386
1416- type unimportChecked struct {
1417- pkgs map [source.PackagePath ]bool // gop package
1418- items map [source.PackagePath ][]recheckItem // index overload funcs
1419- gopo map [source.PackagePath ][]CompletionItem // gopo overload funcs
1420- }
1421-
14221387func (c * gopCompleter ) packageMembers (pkg * types.Package , score float64 , imp * importInfo , cb func (candidate )) {
14231388 scope := pkg .Scope ()
14241389 for _ , name := range scope .Names () {
@@ -2498,6 +2463,58 @@ func gopForEachPackageMember(content []byte, f func(tok token.Token, id *ast.Ide
24982463 if decl .Recv == nil {
24992464 f (token .FUNC , decl .Name , decl )
25002465 }
2466+ case * ast.OverloadFuncDecl :
2467+ if decl .Recv == nil {
2468+ f (token .FUNC , decl .Name , nil )
2469+ }
2470+ }
2471+ }
2472+ }
2473+
2474+ type unimportChecked struct {
2475+ pkgs map [source.PackagePath ]bool // gop package
2476+ items map [source.PackagePath ][]recheckItem // index overload funcs
2477+ gopo map [source.PackagePath ][]CompletionItem // gopo overload funcs
2478+ }
2479+
2480+ func (recheck * unimportChecked ) checkOverload (c * gopCompleter ) {
2481+ // check gop package index overload
2482+ for pkg , items := range recheck .items {
2483+ if recheck .pkgs [pkg ] {
2484+ names := make (map [string ]bool )
2485+ sort .Slice (items , func (i , j int ) bool {
2486+ return items [i ].Label < items [j ].Label
2487+ })
2488+ for _ , item := range items {
2489+ id := item .Label [:len (item .Label )- 3 ]
2490+ if ! names [id ] {
2491+ names [id ] = true
2492+ item .isOverload = true
2493+ item .Detail = "Go+ overload func\n \n " + item .Detail
2494+ c .items = append (c .items , cloneAliasItem (item .CompletionItem , item .Label , id , 0 , false ))
2495+ if alias , ok := hasAliasName (id ); ok {
2496+ c .items = append (c .items , cloneAliasItem (item .CompletionItem , item .Label , alias , 0.0001 , item .noSnip ))
2497+ }
2498+ }
2499+ }
2500+ } else {
2501+ for _ , item := range items {
2502+ c .items = append (c .items , item .CompletionItem )
2503+ if alias , ok := hasAliasName (item .Label ); ok {
2504+ c .items = append (c .items , cloneAliasItem (item .CompletionItem , item .Label , alias , 0.0001 , item .noSnip ))
2505+ }
2506+ }
2507+ }
2508+ }
2509+ // check gop package gopo overload
2510+ for pkg , items := range recheck .gopo {
2511+ if recheck .pkgs [pkg ] {
2512+ for _ , item := range items {
2513+ c .items = append (c .items , item )
2514+ if alias , ok := hasAliasName (item .Label ); ok {
2515+ c .items = append (c .items , cloneAliasItem (item , item .Label , alias , 0.0001 , true ))
2516+ }
2517+ }
25012518 }
25022519 }
25032520}
0 commit comments