File tree Expand file tree Collapse file tree 1 file changed +10
-7
lines changed
compiler-core/src/language_server Expand file tree Collapse file tree 1 file changed +10
-7
lines changed Original file line number Diff line number Diff line change @@ -1429,6 +1429,14 @@ impl<'ast> ast::visit::Visit<'ast> for AnnotateTopLevelDefinitions<'_> {
14291429 }
14301430
14311431 fn visit_typed_function ( & mut self , fun : & ' ast ast:: TypedFunction ) {
1432+ // Don't annotate already annotated arguments
1433+ let arguments_to_annotate = fun. arguments ( ) . iter ( ) . filter ( |argument| argument. annotation . is_none ( ) ) ;
1434+ let return_annotation_needed = fun. return_annotation . is_none ( ) ;
1435+
1436+ if arguments_to_annotate. is_empty ( ) && !return_annotation_needed {
1437+ return ;
1438+ }
1439+
14321440 // Create new printer to ignore type variables from other definitions
14331441 let mut printer = Printer :: new_without_type_variables ( & self . module . ast . names ) ;
14341442 collect_type_variables ( & mut printer, fun) ;
@@ -1447,20 +1455,15 @@ impl<'ast> ast::visit::Visit<'ast> for AnnotateTopLevelDefinitions<'_> {
14471455 }
14481456
14491457 // Annotate each argument separately
1450- for argument in fun. arguments . iter ( ) {
1451- // Don't annotate the argument if it's already annotated
1452- if argument. annotation . is_some ( ) {
1453- continue ;
1454- }
1455-
1458+ for argument in arguments_to_annotate {
14561459 self . edits . insert (
14571460 argument. location . end ,
14581461 format ! ( ": {}" , printer. print_type( & argument. type_) ) ,
14591462 ) ;
14601463 }
14611464
14621465 // Annotate the return type if it isn't already annotated
1463- if fun . return_annotation . is_none ( ) {
1466+ if return_annotation_needed {
14641467 self . edits . insert (
14651468 fun. location . end ,
14661469 format ! ( " -> {}" , printer. print_type( & fun. return_type) ) ,
You can’t perform that action at this time.
0 commit comments