@@ -1366,7 +1366,6 @@ pub struct AnnotateTopLevelDefinitions<'a> {
1366
1366
module : & ' a Module ,
1367
1367
params : & ' a CodeActionParams ,
1368
1368
edits : TextEdits < ' a > ,
1369
- printer : Printer < ' a > ,
1370
1369
is_hovering_definition : bool ,
1371
1370
}
1372
1371
@@ -1380,9 +1379,6 @@ impl<'a> AnnotateTopLevelDefinitions<'a> {
1380
1379
module,
1381
1380
params,
1382
1381
edits : TextEdits :: new ( line_numbers) ,
1383
- // We need to use the same printer for all the edits because otherwise
1384
- // we could get duplicate type variable names.
1385
- printer : Printer :: new_without_type_variables ( & module. ast . names ) ,
1386
1382
is_hovering_definition : false ,
1387
1383
}
1388
1384
}
@@ -1408,11 +1404,6 @@ impl<'a> AnnotateTopLevelDefinitions<'a> {
1408
1404
1409
1405
impl < ' ast > ast:: visit:: Visit < ' ast > for AnnotateTopLevelDefinitions < ' _ > {
1410
1406
fn visit_typed_module_constant ( & mut self , constant : & ' ast TypedModuleConstant ) {
1411
- // Since type variable names are local to definitions, any type variables
1412
- // in other parts of the module shouldn't affect what we print for the
1413
- // annotations of this constant.
1414
- self . printer . clear_type_variables ( ) ;
1415
-
1416
1407
let code_action_range = self . edits . src_span_to_lsp_range ( constant. location ) ;
1417
1408
1418
1409
if overlaps ( code_action_range, self . params . range ) {
@@ -1426,18 +1417,19 @@ impl<'ast> ast::visit::Visit<'ast> for AnnotateTopLevelDefinitions<'_> {
1426
1417
1427
1418
self . edits . insert (
1428
1419
constant. name_location . end ,
1429
- format ! ( ": {}" , self . printer. print_type( & constant. type_) ) ,
1420
+ format ! (
1421
+ ": {}" ,
1422
+ // Create new printer to ignore type variables from other definitions
1423
+ Printer :: new_without_type_variables( & self . module. ast. names)
1424
+ . print_type( & constant. type_)
1425
+ ) ,
1430
1426
) ;
1431
1427
}
1432
1428
1433
1429
fn visit_typed_function ( & mut self , fun : & ' ast ast:: TypedFunction ) {
1434
- // Since type variable names are local to definitions, any type variables
1435
- // in other parts of the module shouldn't affect what we print for the
1436
- // annotations of this functions. The only variables which cannot clash
1437
- // are ones defined in the signature of this function, which we register
1438
- // when we visit the parameters of this function inside `collect_type_variables`.
1439
- self . printer . clear_type_variables ( ) ;
1440
- collect_type_variables ( & mut self . printer , fun) ;
1430
+ // Create new printer to ignore type variables from other definitions
1431
+ let mut printer = Printer :: new_without_type_variables ( & self . module . ast . names ) ;
1432
+ collect_type_variables ( & mut printer, fun) ;
1441
1433
1442
1434
ast:: visit:: visit_typed_function ( self , fun) ;
1443
1435
@@ -1463,15 +1455,15 @@ impl<'ast> ast::visit::Visit<'ast> for AnnotateTopLevelDefinitions<'_> {
1463
1455
1464
1456
self . edits . insert (
1465
1457
argument. location . end ,
1466
- format ! ( ": {}" , self . printer. print_type( & argument. type_) ) ,
1458
+ format ! ( ": {}" , printer. print_type( & argument. type_) ) ,
1467
1459
) ;
1468
1460
}
1469
1461
1470
1462
// Annotate the return type if it isn't already annotated
1471
1463
if fun. return_annotation . is_none ( ) {
1472
1464
self . edits . insert (
1473
1465
fun. location . end ,
1474
- format ! ( " -> {}" , self . printer. print_type( & fun. return_type) ) ,
1466
+ format ! ( " -> {}" , printer. print_type( & fun. return_type) ) ,
1475
1467
) ;
1476
1468
}
1477
1469
}
0 commit comments