\n\n"),
+ build_codemirror_doc_block(2, 2, "", "//", ""),
+ build_codemirror_doc_block(4, 4, "", "//", "")
+ ]
+ ))
+ );
// Test Unicode characters in code.
assert_eq!(
@@ -1388,15 +1446,70 @@ mod tests {
))
);
- // Test a fenced code block that's unterminated.
+ // Test a fenced code block that's unterminated. See [fence
+ // mending](#fence-mending).
+ assert_eq!(
+ source_to_codechat_for_web("/* ``` foo\n*/\n// Test", &"cpp".to_string(), false, false),
+ TranslationResults::CodeChat(build_codechat_for_web(
+ "c_cpp",
+ "\n\n\n",
+ vec![
+ build_codemirror_doc_block(
+ 0,
+ 1,
+ "",
+ "/*",
+ "\n\n\n"
+ ),
+ build_codemirror_doc_block(2, 2, "", "//", "Test
\n"), + ] + )) + ); + // Test the other code fence character (the tilde). + assert_eq!( + source_to_codechat_for_web( + "/* ~~~~~~~ foo\n*/\n// Test", + &"cpp".to_string(), + false, + false + ), + TranslationResults::CodeChat(build_codechat_for_web( + "c_cpp", + "\n\n\n", + vec![ + build_codemirror_doc_block( + 0, + 1, + "", + "/*", + "\n\n\n"
+ ),
+ build_codemirror_doc_block(2, 2, "", "//", "Test
\n"), + ] + )) + ); + // Test multiple unterminated fenced code blocks. + assert_eq!( + source_to_codechat_for_web("// ```\n // ~~~", &"cpp".to_string(), false, false), + TranslationResults::CodeChat(build_codechat_for_web( + "c_cpp", + "\n\n", + vec![ + build_codemirror_doc_block(0, 0, "", "//", "\n\n"),
+ build_codemirror_doc_block(1, 1, " ", "//", "\n"),
+ ]
+ ))
+ );
+
+ // Test an unterminated HTML block.
assert_eq!(
- source_to_codechat_for_web("/* ```\n*/\n//", &"cpp".to_string(), false, false),
+ source_to_codechat_for_web("// \n\n"),
- build_codemirror_doc_block(2, 2, "", "//", "\n\n"),
+ build_codemirror_doc_block(0, 0, "", "//", "Test
\n"), ] )) ); diff --git a/server/src/webserver/vscode.rs b/server/src/webserver/vscode.rs index e3a29d75..d8fa2c14 100644 --- a/server/src/webserver/vscode.rs +++ b/server/src/webserver/vscode.rs @@ -369,7 +369,10 @@ pub async fn vscode_ide_websocket( } }; - // Process the file contents. Since VSCode doesn't have a PDF viewer, determine if this is a PDF file. (TODO: look at the magic number also -- "%PDF"). + // Process the file contents. Since VSCode + // doesn't have a PDF viewer, determine if this + // is a PDF file. (TODO: look at the magic + // number also -- "%PDF"). let use_pdf_js = http_request.file_path.extension() == Some(OsStr::new("pdf")); let (simple_http_response, option_update) = match file_contents_option { Some(file_contents) => @@ -525,6 +528,9 @@ pub async fn vscode_ide_websocket( // Open a web browser when requested. EditorMessageContents::OpenUrl(url) => { + // This doesn't work in Codespaces. TODO: send + // this back to the VSCode window, then call + // `vscode.env.openExternal(vscode.Uri.parse(url))`. if let Err(err) = open::that_detached(&url) { let msg = format!("Unable to open web browser to URL {url}: {err}"); error!("{msg}"); @@ -592,7 +598,9 @@ pub async fn vscode_ide_websocket( match file_path.to_str() { None => Err("Unable to convert path to string.".to_string()), Some(file_path_string) => { - // Use a [binary file sniffer](#binary-file-sniffer) to determine if the file is text or binary. + // Use a [binary file + // sniffer](#binary-file-sniffer) to + // determine if the file is text or binary. let is_text = if let Ok(mut fc) = File::open(&file_path).await { try_read_as_text(&mut fc).await.is_some() } else {