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 @@ -1428,6 +1428,14 @@ impl<'ast> ast::visit::Visit<'ast> for AnnotateTopLevelDefinitions<'_> {
14281428 }
14291429
14301430 fn visit_typed_function ( & mut self , fun : & ' ast ast:: TypedFunction ) {
1431+ // Don't annotate already annotated arguments
1432+ let arguments_to_annotate = fun. arguments ( ) . iter ( ) . filter ( |argument| argument. annotation . is_none ( ) ) ;
1433+ let return_annotation_needed = fun. return_annotation . is_none ( ) ;
1434+
1435+ if arguments_to_annotate. is_empty ( ) && !return_annotation_needed {
1436+ return ;
1437+ }
1438+
14311439 // Create new printer to ignore type variables from other definitions
14321440 let mut printer = Printer :: new_without_type_variables ( & self . module . ast . names ) ;
14331441 collect_type_variables ( & mut printer, fun) ;
@@ -1446,20 +1454,15 @@ impl<'ast> ast::visit::Visit<'ast> for AnnotateTopLevelDefinitions<'_> {
14461454 }
14471455
14481456 // Annotate each argument separately
1449- for argument in fun. arguments . iter ( ) {
1450- // Don't annotate the argument if it's already annotated
1451- if argument. annotation . is_some ( ) {
1452- continue ;
1453- }
1454-
1457+ for argument in arguments_to_annotate {
14551458 self . edits . insert (
14561459 argument. location . end ,
14571460 format ! ( ": {}" , printer. print_type( & argument. type_) ) ,
14581461 ) ;
14591462 }
14601463
14611464 // Annotate the return type if it isn't already annotated
1462- if fun . return_annotation . is_none ( ) {
1465+ if return_annotation_needed {
14631466 self . edits . insert (
14641467 fun. location . end ,
14651468 format ! ( " -> {}" , printer. print_type( & fun. return_type) ) ,
You can’t perform that action at this time.
0 commit comments