@@ -701,6 +701,8 @@ async fn make_simple_http_response(
701701 // If this file is currently being edited, this is the body of an `Update`
702702 // message to send.
703703 Option < UpdateMessageContents > ,
704+ // The resulting file contents, if this is a CodeChat Editor file
705+ Option < String >
704706) {
705707 // Convert the provided URL back into a file name.
706708 let file_path = & http_request. file_path ;
@@ -710,6 +712,7 @@ async fn make_simple_http_response(
710712 Err ( err) => (
711713 SimpleHttpResponse :: Err ( SimpleHttpResponseError :: Io ( err) ) ,
712714 None ,
715+ None
713716 ) ,
714717 Ok ( mut fc) => {
715718 let file_contents = try_read_as_text ( & mut fc) . await ;
@@ -719,7 +722,7 @@ async fn make_simple_http_response(
719722 file_to_response (
720723 http_request,
721724 current_filepath,
722- file_contents. as_deref ( ) ,
725+ file_contents,
723726 use_pdf_js,
724727 )
725728 . await
@@ -755,7 +758,7 @@ async fn file_to_response(
755758 // `try_canonicalize`.
756759 current_filepath : & Path ,
757760 // Contents of this file, if it's text; None if it was binary data.
758- file_contents : Option < & str > ,
761+ file_contents : Option < String > ,
759762 // True to use the PDF.js viewer for this file.
760763 use_pdf_js : bool ,
761764) -> (
@@ -765,6 +768,8 @@ async fn file_to_response(
765768 // populate the Client with the parsed `file_contents`. In all other cases,
766769 // return None.
767770 Option < UpdateMessageContents > ,
771+ // The `file_contents` if this is a
772+ Option < String >
768773) {
769774 // Use a lossy conversion, since this is UI display, not filesystem access.
770775 let file_path = & http_request. file_path ;
@@ -774,6 +779,7 @@ async fn file_to_response(
774779 file_path. to_path_buf ( ) ,
775780 ) ) ,
776781 None ,
782+ None
777783 ) ;
778784 } ;
779785 let name = escape_html ( & file_name. to_string_lossy ( ) ) ;
@@ -791,6 +797,7 @@ async fn file_to_response(
791797 codechat_editor_js_name,
792798 ) ) ,
793799 None ,
800+ None
794801 ) ;
795802 } ;
796803 let codechat_editor_css_name = format ! ( "CodeChatEditor{js_test_suffix}.css" ) ;
@@ -800,17 +807,18 @@ async fn file_to_response(
800807 codechat_editor_css_name,
801808 ) ) ,
802809 None ,
810+ file_contents
803811 ) ;
804812 } ;
805813
806814 // Compare these files, since both have been canonicalized by
807815 // `try_canonical`.
808816 let is_current_file = file_path == current_filepath;
809817 let is_toc = http_request. flags == ProcessingTaskHttpRequestFlags :: Toc ;
810- let ( translation_results_string, path_to_toc) = if let Some ( file_contents_text) = file_contents
818+ let ( translation_results_string, path_to_toc) = if let Some ( ref file_contents_text) = file_contents
811819 {
812820 if is_current_file || is_toc {
813- source_to_codechat_for_web_string ( file_contents_text, file_path, is_toc)
821+ source_to_codechat_for_web_string ( & file_contents_text, file_path, is_toc)
814822 } else {
815823 // If this isn't the current file, then don't parse it.
816824 ( TranslationResultsString :: Unknown , None )
@@ -852,6 +860,7 @@ async fn file_to_response(
852860 file_name,
853861 ) ) ) ,
854862 None ,
863+ None
855864 ) ;
856865 } ;
857866 return (
@@ -871,13 +880,14 @@ async fn file_to_response(
871880 } ,
872881 ) ,
873882 None ,
883+ None
874884 ) ;
875885 }
876886
877887 let codechat_for_web = match translation_results_string {
878888 // The file type is binary. Ask the HTTP server to serve it raw.
879889 TranslationResultsString :: Binary => return
880- ( SimpleHttpResponse :: Bin ( file_path. to_path_buf ( ) ) , None )
890+ ( SimpleHttpResponse :: Bin ( file_path. to_path_buf ( ) ) , None , None )
881891 ,
882892 // The file type is unknown. Serve it raw.
883893 TranslationResultsString :: Unknown => {
@@ -887,11 +897,12 @@ async fn file_to_response(
887897 mime_guess:: from_path ( file_path) . first_or_text_plain ( ) ,
888898 ) ,
889899 None ,
900+ None
890901 ) ;
891902 }
892903 // Report a lexer error.
893904 TranslationResultsString :: Err ( err_string) => {
894- return ( SimpleHttpResponse :: Err ( SimpleHttpResponseError :: LexerError ( err_string) ) , None ) ;
905+ return ( SimpleHttpResponse :: Err ( SimpleHttpResponseError :: LexerError ( err_string) ) , None , None ) ;
895906 }
896907 // This is a CodeChat file. The following code wraps the CodeChat for
897908 // web results in a CodeChat Editor Client webpage.
@@ -919,6 +930,7 @@ async fn file_to_response(
919930 </html>"# ,
920931 ) ) ,
921932 None ,
933+ None
922934 ) ;
923935 }
924936 } ;
@@ -940,6 +952,7 @@ async fn file_to_response(
940952 file_path. to_path_buf ( ) ,
941953 ) ) ,
942954 None ,
955+ None
943956 ) ;
944957 } ;
945958 let dir = path_display ( raw_dir) ;
@@ -949,6 +962,7 @@ async fn file_to_response(
949962 file_path. to_path_buf ( ) ,
950963 ) ) ,
951964 None ,
965+ None
952966 ) ;
953967 } ;
954968 // Build and return the webpage.
@@ -996,6 +1010,7 @@ async fn file_to_response(
9961010 cursor_position : None ,
9971011 scroll_position : None ,
9981012 } ) ,
1013+ file_contents
9991014 )
10001015}
10011016
0 commit comments