@@ -1210,8 +1210,10 @@ func (c *completer) selector(ctx context.Context, sel *ast.SelectorExpr) error {
1210
1210
1211
1211
// quickParse does a quick parse of a single file of package m,
1212
1212
// extracts exported package members and adds candidates to c.items.
1213
- var itemsMu sync.Mutex // guards c.items
1214
- var enough int32 // atomic bool
1213
+ // TODO(rfindley): synchronizing access to c here does not feel right.
1214
+ // Consider adding a concurrency-safe API for completer.
1215
+ var cMu sync.Mutex // guards c.items and c.matcher
1216
+ var enough int32 // atomic bool
1215
1217
quickParse := func (uri span.URI , m * source.Metadata ) error {
1216
1218
if atomic .LoadInt32 (& enough ) != 0 {
1217
1219
return nil
@@ -1231,13 +1233,22 @@ func (c *completer) selector(ctx context.Context, sel *ast.SelectorExpr) error {
1231
1233
return
1232
1234
}
1233
1235
1234
- if ! id .IsExported () ||
1235
- sel .Sel .Name != "_" && ! strings .HasPrefix (id .Name , sel .Sel .Name ) {
1236
- return // not a match
1236
+ if ! id .IsExported () {
1237
+ return
1238
+ }
1239
+
1240
+ cMu .Lock ()
1241
+ score := c .matcher .Score (id .Name )
1242
+ cMu .Unlock ()
1243
+
1244
+ if sel .Sel .Name != "_" && score == 0 {
1245
+ return // not a match; avoid constructing the completion item below
1237
1246
}
1238
1247
1239
1248
// The only detail is the kind and package: `var (from "example.com/foo")`
1240
1249
// TODO(adonovan): pretty-print FuncDecl.FuncType or TypeSpec.Type?
1250
+ // TODO(adonovan): should this score consider the actual c.matcher.Score
1251
+ // of the item? How does this compare with the deepState.enqueue path?
1241
1252
item := CompletionItem {
1242
1253
Label : id .Name ,
1243
1254
Detail : fmt .Sprintf ("%s (from %q)" , strings .ToLower (tok .String ()), m .PkgPath ),
@@ -1298,12 +1309,12 @@ func (c *completer) selector(ctx context.Context, sel *ast.SelectorExpr) error {
1298
1309
item .snippet = & sn
1299
1310
}
1300
1311
1301
- itemsMu .Lock ()
1312
+ cMu .Lock ()
1302
1313
c .items = append (c .items , item )
1303
1314
if len (c .items ) >= unimportedMemberTarget {
1304
1315
atomic .StoreInt32 (& enough , 1 )
1305
1316
}
1306
- itemsMu .Unlock ()
1317
+ cMu .Unlock ()
1307
1318
})
1308
1319
return nil
1309
1320
}
0 commit comments