@@ -1170,6 +1170,11 @@ impl<'ast> ast::visit::Visit<'ast> for AddAnnotations<'_> {
1170
1170
}
1171
1171
1172
1172
fn visit_typed_module_constant ( & mut self , constant : & ' ast TypedModuleConstant ) {
1173
+ // Since type variable names are local to definitions, any type variables
1174
+ // in other parts of the module shouldn't affect what we print for the
1175
+ // annotations of this constant.
1176
+ self . printer . clear_type_variables ( ) ;
1177
+
1173
1178
let code_action_range = self . edits . src_span_to_lsp_range ( constant. location ) ;
1174
1179
1175
1180
// Only offer the code action if the cursor is over the statement
@@ -1189,6 +1194,14 @@ impl<'ast> ast::visit::Visit<'ast> for AddAnnotations<'_> {
1189
1194
}
1190
1195
1191
1196
fn visit_typed_function ( & mut self , fun : & ' ast ast:: TypedFunction ) {
1197
+ self . printer . clear_type_variables ( ) ;
1198
+
1199
+ // Since type variable names are local to definitions, any type variables
1200
+ // in other parts of the module shouldn't affect what we print for the
1201
+ // annotations of this functions. The only variables which cannot clash
1202
+ // are ones defined in the signature of this function, which we register
1203
+ // when we visit the parameters of this function below.
1204
+
1192
1205
ast:: visit:: visit_typed_function ( self , fun) ;
1193
1206
1194
1207
let code_action_range = self . edits . src_span_to_lsp_range (
@@ -1227,6 +1240,12 @@ impl<'ast> ast::visit::Visit<'ast> for AddAnnotations<'_> {
1227
1240
}
1228
1241
}
1229
1242
1243
+ fn visit_type_ast_var ( & mut self , _location : & ' ast SrcSpan , name : & ' ast EcoString ) {
1244
+ // Register this type variable so that we don't duplicate names when
1245
+ // adding annotations.
1246
+ self . printer . register_type_variable ( name. clone ( ) ) ;
1247
+ }
1248
+
1230
1249
fn visit_typed_expr_fn (
1231
1250
& mut self ,
1232
1251
location : & ' ast SrcSpan ,
@@ -1420,19 +1439,6 @@ impl<'ast> ast::visit::Visit<'ast> for QualifiedToUnqualifiedImportFirstPass<'as
1420
1439
) ;
1421
1440
}
1422
1441
1423
- fn visit_typed_function ( & mut self , fun : & ' ast ast:: TypedFunction ) {
1424
- for arg in & fun. arguments {
1425
- if let Some ( annotation) = & arg. annotation {
1426
- self . visit_type_ast ( annotation) ;
1427
- }
1428
- }
1429
-
1430
- if let Some ( return_annotation) = & fun. return_annotation {
1431
- self . visit_type_ast ( return_annotation) ;
1432
- }
1433
- ast:: visit:: visit_typed_function ( self , fun) ;
1434
- }
1435
-
1436
1442
fn visit_type_ast_constructor (
1437
1443
& mut self ,
1438
1444
location : & ' ast SrcSpan ,
@@ -1659,19 +1665,6 @@ impl<'ast> ast::visit::Visit<'ast> for QualifiedToUnqualifiedImportSecondPass<'a
1659
1665
) ;
1660
1666
}
1661
1667
1662
- fn visit_typed_function ( & mut self , fun : & ' ast ast:: TypedFunction ) {
1663
- for arg in & fun. arguments {
1664
- if let Some ( annotation) = & arg. annotation {
1665
- self . visit_type_ast ( annotation) ;
1666
- }
1667
- }
1668
-
1669
- if let Some ( return_annotation) = & fun. return_annotation {
1670
- self . visit_type_ast ( return_annotation) ;
1671
- }
1672
- ast:: visit:: visit_typed_function ( self , fun) ;
1673
- }
1674
-
1675
1668
fn visit_type_ast_constructor (
1676
1669
& mut self ,
1677
1670
location : & ' ast SrcSpan ,
@@ -1904,18 +1897,6 @@ impl<'ast> ast::visit::Visit<'ast> for UnqualifiedToQualifiedImportFirstPass<'as
1904
1897
) ;
1905
1898
}
1906
1899
1907
- fn visit_typed_function ( & mut self , fun : & ' ast ast:: TypedFunction ) {
1908
- for arg in & fun. arguments {
1909
- if let Some ( annotation) = & arg. annotation {
1910
- self . visit_type_ast ( annotation) ;
1911
- }
1912
- }
1913
-
1914
- if let Some ( return_annotation) = & fun. return_annotation {
1915
- self . visit_type_ast ( return_annotation) ;
1916
- }
1917
- ast:: visit:: visit_typed_function ( self , fun) ;
1918
- }
1919
1900
fn visit_type_ast_constructor (
1920
1901
& mut self ,
1921
1902
location : & ' ast SrcSpan ,
0 commit comments