Skip to content

Commit 013fdd7

Browse files
committed
Fix: correct is_toc to is_current.
1 parent d6b6f93 commit 013fdd7

File tree

11 files changed

+70
-63
lines changed

11 files changed

+70
-63
lines changed

extensions/VSCode/src/extension.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -529,23 +529,23 @@ export const activate = (context: vscode.ExtensionContext) => {
529529
}
530530

531531
case "LoadFile": {
532-
const [load_file, is_toc] = value as [
532+
const [load_file, is_current] = value as [
533533
string,
534534
boolean,
535535
];
536536
// Look through all open documents to see if we have
537537
// the requested file.
538538
const doc = get_document(load_file);
539-
// If the request is for the TOC as a TOC (not as an editable file), don't create a new version; the value we send won't be used and doesn't matter.
540-
if (!is_toc) {
539+
// If we have this file and the request is for the current file to edit/view in the Client, assign a version.
540+
if (doc !== undefined && is_current) {
541541
version = rand();
542542
}
543543
const load_file_result: null | [string, number] =
544544
doc === undefined
545545
? null
546546
: [doc.getText(), version];
547547
console_log(
548-
`CodeChat Editor extension: Result(LoadFile(${format_struct(load_file_result)}))`,
548+
`CodeChat Editor extension: Result(LoadFile(id = ${id}, ${format_struct(load_file_result)}))`,
549549
);
550550
await codeChatEditorServer.sendResultLoadfile(
551551
id,
@@ -596,7 +596,7 @@ const format_struct = (complex_data_structure: any): string =>
596596
DEBUG_ENABLED
597597
? JSON.stringify(
598598
// If the struct is `undefined`, print an empty string.
599-
complex_data_structure ?? "",
599+
complex_data_structure ?? "null/undefined",
600600
).substring(0, MAX_MESSAGE_LENGTH)
601601
: "";
602602

server/src/ide/vscode/tests.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -353,11 +353,11 @@ async fn test_vscode_ide_websocket3() {
353353
//
354354
// Message ids: IDE - 0, Server - 1->2, Client - 0.
355355
let em = read_message(&mut ws_ide).await;
356-
let (msg, is_toc) = cast!(em.message, EditorMessageContents::LoadFile, a, b);
356+
let (msg, is_current) = cast!(em.message, EditorMessageContents::LoadFile, a, b);
357357
// Compare these as strings -- we want to ensure the path separator is
358358
// correct for the current platform.
359359
assert_eq!(file_path.to_string_lossy(), msg.to_string_lossy());
360-
assert_eq!(is_toc, false);
360+
assert_eq!(is_current, false);
361361
assert_eq!(em.id, INITIAL_MESSAGE_ID + MESSAGE_ID_INCREMENT);
362362

363363
// Reply to the `LoadFile` message -- the file isn't present.
@@ -511,12 +511,12 @@ async fn test_vscode_ide_websocket8() {
511511
//
512512
// Message ids: IDE - 1, Server - 1->2, Client - 0.
513513
let em = read_message(&mut ws_ide).await;
514-
let (msg, is_toc) = cast!(em.message, EditorMessageContents::LoadFile, a, b);
514+
let (msg, is_current) = cast!(em.message, EditorMessageContents::LoadFile, a, b);
515515
assert_eq!(
516516
path::absolute(Path::new(&msg)).unwrap(),
517517
path::absolute(&file_path).unwrap()
518518
);
519-
assert_eq!(is_toc, false);
519+
assert_eq!(is_current, true);
520520
assert_eq!(em.id, INITIAL_MESSAGE_ID + MESSAGE_ID_INCREMENT);
521521

522522
// Reply to the `LoadFile` message with the file's contents.
@@ -945,9 +945,9 @@ async fn test_vscode_ide_websocket4() {
945945
//
946946
// Message ids: IDE - 0, Server - 1->2, Client - 1.
947947
let em = read_message(&mut ws_ide).await;
948-
let (msg, is_toc) = cast!(em.message, EditorMessageContents::LoadFile, a, b);
948+
let (msg, is_current) = cast!(em.message, EditorMessageContents::LoadFile, a, b);
949949
assert_eq!(fs::canonicalize(&msg).unwrap(), file_path_temp);
950-
assert_eq!(is_toc, false);
950+
assert_eq!(is_current, true);
951951
assert_eq!(em.id, INITIAL_MESSAGE_ID + MESSAGE_ID_INCREMENT);
952952

953953
// Reply to the `LoadFile` message: the IDE doesn't have the file.
@@ -1033,12 +1033,12 @@ async fn test_vscode_ide_websocket4() {
10331033
//
10341034
// Message ids: IDE - 0, Server - 3->4, Client - 0.
10351035
let em = read_message(&mut ws_ide).await;
1036-
let (msg, is_toc) = cast!(em.message, EditorMessageContents::LoadFile, a, b);
1036+
let (msg, is_current) = cast!(em.message, EditorMessageContents::LoadFile, a, b);
10371037
assert_eq!(
10381038
fs::canonicalize(&msg).unwrap(),
10391039
fs::canonicalize(test_dir.join("toc.md")).unwrap()
10401040
);
1041-
assert_eq!(is_toc, false);
1041+
assert_eq!(is_current, false);
10421042
assert_eq!(em.id, INITIAL_MESSAGE_ID + 3.0 * MESSAGE_ID_INCREMENT);
10431043

10441044
// Reply to the `LoadFile` message: the IDE doesn't have the file.
@@ -1214,9 +1214,9 @@ async fn test_vscode_ide_websocket4a() {
12141214
//
12151215
// Message ids: IDE - 0, Server - 1->2, Client - 1.
12161216
let em = read_message(&mut ws_ide).await;
1217-
let (msg, is_toc) = cast!(em.message, EditorMessageContents::LoadFile, a, b);
1217+
let (msg, is_current) = cast!(em.message, EditorMessageContents::LoadFile, a, b);
12181218
assert_eq!(fs::canonicalize(&msg).unwrap(), file_path_temp);
1219-
assert_eq!(is_toc, false);
1219+
assert_eq!(is_current, true);
12201220
assert_eq!(em.id, INITIAL_MESSAGE_ID + MESSAGE_ID_INCREMENT);
12211221

12221222
// Reply to the `LoadFile` message: the IDE doesn't have the file.
@@ -1329,9 +1329,9 @@ async fn test_vscode_ide_websocket4b() {
13291329
//
13301330
// Message ids: IDE - 0, Server - 1->2, Client - 1.
13311331
let em = read_message(&mut ws_ide).await;
1332-
let (msg, is_toc) = cast!(em.message, EditorMessageContents::LoadFile, a, b);
1332+
let (msg, is_current) = cast!(em.message, EditorMessageContents::LoadFile, a, b);
13331333
assert_eq!(fs::canonicalize(&msg).unwrap(), file_path_temp);
1334-
assert_eq!(is_toc, false);
1334+
assert_eq!(is_current, true);
13351335
assert_eq!(em.id, INITIAL_MESSAGE_ID + MESSAGE_ID_INCREMENT);
13361336

13371337
// Reply to the `LoadFile` message: the IDE doesn't have the file.

server/src/lexer/pest/c.pest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,4 @@ vis_newline = { NEWLINE }
170170
not_newline_eoi = _{ !(NEWLINE ~ EOI) }
171171
star_dedent = _{ PEEK ~ " * " }
172172

173-
/// CodeChat Editor lexer: c_cpp.
173+
/// CodeChat Editor lexer: cpp.

server/src/lexer/pest/python.pest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,4 @@ short_string = _{
7676
// --------
7777
dedenter = { unused }
7878

79-
/// CodeChat Editor lexer: c_cpp.
79+
/// CodeChat Editor lexer: cpp.

server/src/lexer/pest/shared.pest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,4 @@ not_newline = _{ !NEWLINE ~ ANY }
8383
// Indicates this token isn't used by the parser.
8484
unused = { "unused" }
8585

86-
/// CodeChat Editor lexer: c_cpp.
86+
/// CodeChat Editor lexer: cpp.

server/src/lexer/tests.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ fn test_js() {
464464
#[test]
465465
fn test_cpp() {
466466
let llc = compile_lexers(get_language_lexer_vec());
467-
let cpp = llc.map_mode_to_lexer.get(&stringit("c_cpp")).unwrap();
467+
let cpp = llc.map_mode_to_lexer.get(&stringit("cpp")).unwrap();
468468

469469
// Try out a C++ heredoc.
470470
assert_eq!(
@@ -479,7 +479,7 @@ fn test_cpp() {
479479
#[test]
480480
fn test_c() {
481481
let llc = compile_lexers(get_language_lexer_vec());
482-
let c = llc.map_mode_to_lexer.get(&stringit("c_cpp")).unwrap();
482+
let c = llc.map_mode_to_lexer.get(&stringit("cpp")).unwrap();
483483

484484
// Test logical lines.
485485
let s = indoc!(
@@ -731,10 +731,7 @@ fn test_compiler() {
731731

732732
let c_ext_lexer_arr = llc.map_ext_to_lexer_vec.get(&stringit("c")).unwrap();
733733
assert_eq!(c_ext_lexer_arr.len(), 1);
734-
assert_eq!(
735-
c_ext_lexer_arr[0].language_lexer.lexer_name.as_str(),
736-
"c_cpp"
737-
);
734+
assert_eq!(c_ext_lexer_arr[0].language_lexer.lexer_name.as_str(), "cpp");
738735
assert_eq!(
739736
llc.map_mode_to_lexer
740737
.get(&stringit("verilog"))

server/src/processing/tests.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ fn test_codemirror_to_code_doc_blocks_cpp() {
245245
// Pass an inline comment.
246246
assert_eq!(
247247
run_test(
248-
"c_cpp",
248+
"cpp",
249249
"\n",
250250
vec![build_codemirror_doc_block(0, 1, "", "//", "Test")]
251251
),
@@ -255,7 +255,7 @@ fn test_codemirror_to_code_doc_blocks_cpp() {
255255
// Pass a block comment.
256256
assert_eq!(
257257
run_test(
258-
"c_cpp",
258+
"cpp",
259259
"\n",
260260
vec![build_codemirror_doc_block(0, 1, "", "/*", "Test")]
261261
),
@@ -265,7 +265,7 @@ fn test_codemirror_to_code_doc_blocks_cpp() {
265265
// Two back-to-back doc blocks.
266266
assert_eq!(
267267
run_test(
268-
"c_cpp",
268+
"cpp",
269269
"\n\n",
270270
vec![
271271
build_codemirror_doc_block(0, 1, "", "//", "Test 1"),
@@ -622,7 +622,7 @@ fn test_source_to_codechat_for_web_1() {
622622
assert_eq!(
623623
source_to_codechat_for_web("//\n\n//\n\n//", &"cpp".to_string(), 0.0, false, false),
624624
Ok(TranslationResults::CodeChat(build_codechat_for_web(
625-
"c_cpp",
625+
"cpp",
626626
"\n\n\n\n",
627627
vec![
628628
build_codemirror_doc_block(0, 1, "", "//", ""),
@@ -634,7 +634,7 @@ fn test_source_to_codechat_for_web_1() {
634634
assert_eq!(
635635
source_to_codechat_for_web("// ~~~\n\n//\n\n//", &"cpp".to_string(), 0.0, false, false),
636636
Ok(TranslationResults::CodeChat(build_codechat_for_web(
637-
"c_cpp",
637+
"cpp",
638638
"\n\n\n\n",
639639
vec![
640640
build_codemirror_doc_block(0, 1, "", "//", "<pre><code>\n</code></pre>\n"),
@@ -648,7 +648,7 @@ fn test_source_to_codechat_for_web_1() {
648648
assert_eq!(
649649
source_to_codechat_for_web("; // σ\n//", &"cpp".to_string(), 0.0, false, false),
650650
Ok(TranslationResults::CodeChat(build_codechat_for_web(
651-
"c_cpp",
651+
"cpp",
652652
"; // σ\n",
653653
vec![build_codemirror_doc_block(7, 8, "", "//", ""),]
654654
)))
@@ -658,7 +658,7 @@ fn test_source_to_codechat_for_web_1() {
658658
assert_eq!(
659659
source_to_codechat_for_web("\"σ\";\n//", &"cpp".to_string(), 0.0, false, false),
660660
Ok(TranslationResults::CodeChat(build_codechat_for_web(
661-
"c_cpp",
661+
"cpp",
662662
"\"σ\";\n",
663663
vec![build_codemirror_doc_block(5, 6, "", "//", ""),]
664664
)))
@@ -675,7 +675,7 @@ fn test_source_to_codechat_for_web_1() {
675675
false
676676
),
677677
Ok(TranslationResults::CodeChat(build_codechat_for_web(
678-
"c_cpp",
678+
"cpp",
679679
"\n\n\n",
680680
vec![
681681
build_codemirror_doc_block(
@@ -699,7 +699,7 @@ fn test_source_to_codechat_for_web_1() {
699699
false
700700
),
701701
Ok(TranslationResults::CodeChat(build_codechat_for_web(
702-
"c_cpp",
702+
"cpp",
703703
"\n\n\n",
704704
vec![
705705
build_codemirror_doc_block(
@@ -717,7 +717,7 @@ fn test_source_to_codechat_for_web_1() {
717717
assert_eq!(
718718
source_to_codechat_for_web("// ```\n // ~~~", &"cpp".to_string(), 0.0, false, false),
719719
Ok(TranslationResults::CodeChat(build_codechat_for_web(
720-
"c_cpp",
720+
"cpp",
721721
"\n\n",
722722
vec![
723723
build_codemirror_doc_block(0, 1, "", "//", "<pre><code>\n</code></pre>\n"),
@@ -730,7 +730,7 @@ fn test_source_to_codechat_for_web_1() {
730730
assert_eq!(
731731
source_to_codechat_for_web("// <foo>\n // Test", &"cpp".to_string(), 0.0, false, false),
732732
Ok(TranslationResults::CodeChat(build_codechat_for_web(
733-
"c_cpp",
733+
"cpp",
734734
"\n\n",
735735
vec![
736736
build_codemirror_doc_block(0, 1, "", "//", "<foo>\n"),
@@ -750,7 +750,7 @@ fn test_source_to_codechat_for_web_1() {
750750
false
751751
),
752752
Ok(TranslationResults::CodeChat(build_codechat_for_web(
753-
"c_cpp",
753+
"cpp",
754754
"\n\n",
755755
vec![
756756
build_codemirror_doc_block(0, 1, "", "//", "<pre>\n"),

server/src/translation.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,9 @@ pub async fn translation_task(
545545
id: tt.id,
546546
message: EditorMessageContents::LoadFile
547547
(http_request.file_path.clone(),
548-
http_request.flags == ProcessingTaskHttpRequestFlags::Toc
548+
// Assign a version to this `LoadFile` request only if it's the current file and loaded as the file to edit, not as the sidebar TOC. We can us a simple comparison, since both file names have already been canonicalized.
549+
http_request.file_path == tt.current_file &&
550+
http_request.flags == ProcessingTaskHttpRequestFlags::None
549551
)
550552
}));
551553
// Store the ID and request, which are needed to send a
@@ -749,7 +751,9 @@ impl TranslationTask {
749751
let ((simple_http_response, option_update), file_contents) = match file_contents_option {
750752
Some((file_contents, new_version)) => {
751753
// Only pay attention to the version if this is an editable Client file.
752-
if http_request.flags == ProcessingTaskHttpRequestFlags::None {
754+
if http_request.file_path == self.current_file
755+
&& http_request.flags == ProcessingTaskHttpRequestFlags::None
756+
{
753757
self.version = new_version;
754758
}
755759
// The IDE just sent the full contents; we're sending full

server/src/webserver.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,14 @@ pub enum EditorMessageContents {
214214
OpenUrl(String),
215215

216216
// #### These messages may only be sent by the Server.
217-
/// Ask the IDE if the provided file is loaded. If so, the IDE should
218-
/// respond by sending a `LoadFile` with the requested file. If not, the
219-
/// returned `Result` should indicate the error "not loaded". The boolean
220-
/// indicates if the request is for the non-editable sidebar TOC file, or
221-
/// for an editable Client file (which still may be the TOC, if that's being
222-
/// edited). Valid destinations: IDE.
223-
LoadFile(PathBuf, bool),
217+
/// Ask the IDE if the provided file is already loaded. The IDE should always respond to this with a `ResultOkTypes::LoadFile` message. If the file was loaded, the IDE responds with `Some((` contents of file, version of file `))`; if the was isn't loaded, it responds with `None`. The boolean value accompanying this message
218+
/// Valid destinations: IDE.
219+
LoadFile(
220+
// Path to the file to load.
221+
PathBuf,
222+
// `is_current` - true if this is the current file being edited/viewed by the Client.
223+
bool,
224+
),
224225
/// This may only be used to respond to an `Opened` message; it contains the
225226
/// HTML for the CodeChat Editor Client to display in its built-in browser.
226227
/// Valid destinations: IDE.
@@ -251,9 +252,14 @@ pub enum ResultOkTypes {
251252
Void,
252253
/// The `LoadFile` message provides file contents and a revision number, if
253254
/// available. This message may only be sent from the IDE to the Server.
254-
/// If this is sent in response to a `LoadFile` where the toc boolean is false,
255-
/// this value will be ignored.
256-
LoadFile(Option<(String, f64)>),
255+
LoadFile(
256+
Option<(
257+
// The text of the file.
258+
String,
259+
// The version of the file; ignored if the corresponding `LoadFile` request's `is_current` value was false.
260+
f64,
261+
)>,
262+
),
257263
}
258264

259265
#[derive(Debug, Serialize, Deserialize, TS, PartialEq, thiserror::Error)]

0 commit comments

Comments
 (0)