@@ -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,19 +712,14 @@ 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 ;
716719 // <a id="binary-file-sniffer"></a>If this is a binary file (meaning
717720 // we can't read the contents as UTF-8), send the contents as none
718721 // to signal this isn't a text file.
719- file_to_response (
720- http_request,
721- current_filepath,
722- file_contents. as_deref ( ) ,
723- use_pdf_js,
724- )
725- . await
722+ file_to_response ( http_request, current_filepath, file_contents, use_pdf_js) . await
726723 }
727724 }
728725}
@@ -755,7 +752,7 @@ async fn file_to_response(
755752 // `try_canonicalize`.
756753 current_filepath : & Path ,
757754 // Contents of this file, if it's text; None if it was binary data.
758- file_contents : Option < & str > ,
755+ file_contents : Option < String > ,
759756 // True to use the PDF.js viewer for this file.
760757 use_pdf_js : bool ,
761758) -> (
@@ -765,6 +762,8 @@ async fn file_to_response(
765762 // populate the Client with the parsed `file_contents`. In all other cases,
766763 // return None.
767764 Option < UpdateMessageContents > ,
765+ // The `file_contents` if this is a
766+ Option < String > ,
768767) {
769768 // Use a lossy conversion, since this is UI display, not filesystem access.
770769 let file_path = & http_request. file_path ;
@@ -774,6 +773,7 @@ async fn file_to_response(
774773 file_path. to_path_buf ( ) ,
775774 ) ) ,
776775 None ,
776+ None ,
777777 ) ;
778778 } ;
779779 let name = escape_html ( & file_name. to_string_lossy ( ) ) ;
@@ -791,6 +791,7 @@ async fn file_to_response(
791791 codechat_editor_js_name,
792792 ) ) ,
793793 None ,
794+ None ,
794795 ) ;
795796 } ;
796797 let codechat_editor_css_name = format ! ( "CodeChatEditor{js_test_suffix}.css" ) ;
@@ -800,27 +801,28 @@ async fn file_to_response(
800801 codechat_editor_css_name,
801802 ) ) ,
802803 None ,
804+ file_contents,
803805 ) ;
804806 } ;
805807
806808 // Compare these files, since both have been canonicalized by
807809 // `try_canonical`.
808810 let is_current_file = file_path == current_filepath;
809811 let is_toc = http_request. flags == ProcessingTaskHttpRequestFlags :: Toc ;
810- let ( translation_results_string, path_to_toc) = if let Some ( file_contents_text) = file_contents
811- {
812- if is_current_file || is_toc {
813- source_to_codechat_for_web_string ( file_contents_text, file_path, is_toc)
812+ let ( translation_results_string, path_to_toc) =
813+ if let Some ( ref file_contents_text) = file_contents {
814+ if is_current_file || is_toc {
815+ source_to_codechat_for_web_string ( file_contents_text, file_path, is_toc)
816+ } else {
817+ // If this isn't the current file, then don't parse it.
818+ ( TranslationResultsString :: Unknown , None )
819+ }
814820 } else {
815- // If this isn't the current file, then don't parse it.
816- ( TranslationResultsString :: Unknown , None )
817- }
818- } else {
819- (
820- TranslationResultsString :: Binary ,
821- find_path_to_toc ( file_path) ,
822- )
823- } ;
821+ (
822+ TranslationResultsString :: Binary ,
823+ find_path_to_toc ( file_path) ,
824+ )
825+ } ;
824826 let is_project = path_to_toc. is_some ( ) ;
825827 // For project files, add in the sidebar. Convert this from a Windows path
826828 // to a Posix path if necessary.
@@ -852,6 +854,7 @@ async fn file_to_response(
852854 file_name,
853855 ) ) ) ,
854856 None ,
857+ None ,
855858 ) ;
856859 } ;
857860 return (
@@ -871,13 +874,14 @@ async fn file_to_response(
871874 } ,
872875 ) ,
873876 None ,
877+ None ,
874878 ) ;
875879 }
876880
877881 let codechat_for_web = match translation_results_string {
878882 // The file type is binary. Ask the HTTP server to serve it raw.
879883 TranslationResultsString :: Binary => return
880- ( SimpleHttpResponse :: Bin ( file_path. to_path_buf ( ) ) , None )
884+ ( SimpleHttpResponse :: Bin ( file_path. to_path_buf ( ) ) , None , None )
881885 ,
882886 // The file type is unknown. Serve it raw.
883887 TranslationResultsString :: Unknown => {
@@ -887,11 +891,12 @@ async fn file_to_response(
887891 mime_guess:: from_path ( file_path) . first_or_text_plain ( ) ,
888892 ) ,
889893 None ,
894+ None
890895 ) ;
891896 }
892897 // Report a lexer error.
893898 TranslationResultsString :: Err ( err_string) => {
894- return ( SimpleHttpResponse :: Err ( SimpleHttpResponseError :: LexerError ( err_string) ) , None ) ;
899+ return ( SimpleHttpResponse :: Err ( SimpleHttpResponseError :: LexerError ( err_string) ) , None , None ) ;
895900 }
896901 // This is a CodeChat file. The following code wraps the CodeChat for
897902 // web results in a CodeChat Editor Client webpage.
@@ -919,6 +924,7 @@ async fn file_to_response(
919924 </html>"# ,
920925 ) ) ,
921926 None ,
927+ None
922928 ) ;
923929 }
924930 } ;
@@ -940,6 +946,7 @@ async fn file_to_response(
940946 file_path. to_path_buf ( ) ,
941947 ) ) ,
942948 None ,
949+ None ,
943950 ) ;
944951 } ;
945952 let dir = path_display ( raw_dir) ;
@@ -949,6 +956,7 @@ async fn file_to_response(
949956 file_path. to_path_buf ( ) ,
950957 ) ) ,
951958 None ,
959+ None ,
952960 ) ;
953961 } ;
954962 // Build and return the webpage.
@@ -996,6 +1004,7 @@ async fn file_to_response(
9961004 cursor_position : None ,
9971005 scroll_position : None ,
9981006 } ) ,
1007+ file_contents,
9991008 )
10001009}
10011010
0 commit comments