Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions builder/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

240 changes: 140 additions & 100 deletions client/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codechat-editor-client",
"version": "0.1.6",
"version": "0.1.7",
"description": "The CodeChat Editor Client, part of a web-based literate programming editor (the CodeChat Editor).",
"homepage": "https://github.com/bjones1/CodeChat_Editor",
"type": "module",
Expand Down
3 changes: 2 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ CodeChat Editor. If not, see
# Changelog

- [Github master](https://github.com/bjones1/CodeChat_Editor):
- No changes.
- Fixed hyperlink navigation.
- Fixed case-insensitive filename handling bugs.
- v0.1.6, 2024-Dec-29:
- Improvements to the build tool.
- Corrections to the C parser.
Expand Down
240 changes: 140 additions & 100 deletions extensions/VSCode/package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion extensions/VSCode/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codechat-editor-client",
"version": "0.1.6",
"version": "0.1.7",
"publisher": "CodeChat",
"engines": {
"vscode": "^1.61.0"
Expand Down
58 changes: 41 additions & 17 deletions extensions/VSCode/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
// ### Node.js packages
import assert from "assert";
import child_process from "node:child_process";
import process from "node:process";

// ### Third-party packages
import escape from "escape-html";
Expand All @@ -45,6 +46,9 @@ const MAX_MESSAGE_LENGTH = 200;
// The timeout for a websocket `Response`.
const RESPONSE_TIMEOUT = 15000;

// True on Windows, false on OS X / Linux.
const is_windows = process.platform === "win32";

// These globals are truly global: only one is needed for this entire plugin.
let websocket: WebSocket | undefined;
// Where the webclient resides: `html` for a webview panel embedded in VSCode;
Expand Down Expand Up @@ -395,7 +399,9 @@ export const activate = (context: vscode.ExtensionContext) => {
case "Update": {
const current_update =
value as UpdateMessageContents;
const doc = get_document(current_update.file_path);
const doc = get_document(
current_update.file_path
);
if (doc === undefined) {
send_result(id, {
Err: "No open document for this file.",
Expand Down Expand Up @@ -457,7 +463,7 @@ export const activate = (context: vscode.ExtensionContext) => {
// Report if this was an error.
const result_contents = value as MessageResult;
if ("Err" in result_contents) {
const msg = `Error in message ${id}: ${result_contents.Err}.`;
const msg = `Error in message ${id}: ${result_contents.Err}`;
console.log(msg);
// Warning: Calling `show_error` shuts down
// the client. Do this deliberately, since
Expand All @@ -473,7 +479,8 @@ export const activate = (context: vscode.ExtensionContext) => {
// Look through all open documents to see if we
// have the requested file.
const doc = get_document(load_file);
const load_file_result = doc === undefined ? null : doc.getText();
const load_file_result =
doc === undefined ? null : doc.getText();
send_result(id, {
Ok: {
LoadFile: load_file_result,
Expand Down Expand Up @@ -511,15 +518,15 @@ export const activate = (context: vscode.ExtensionContext) => {
}
)
);
}
};

// On deactivation, close everything down.
export const deactivate = async () => {
console.log("CodeChat extension: deactivating.");
await stop_client();
webview_panel?.dispose();
console.log("CodeChat extension: deactivated.");
}
};

// ## Supporting functions
//
Expand Down Expand Up @@ -606,18 +613,16 @@ const start_render = () => {
}
}, 300);
}
}
};

const current_file = () => {
// Only send a new current file is there's a change.
const ate = vscode.window.activeTextEditor;
if (can_render() && ate !== current_editor) {
current_editor = ate;
send_message(
{
CurrentFile: ate!.document.fileName,
},
);
send_message({
CurrentFile: ate!.document.fileName,
});
}
};

Expand Down Expand Up @@ -648,7 +653,7 @@ const stop_client = async () => {
);
}
current_editor = undefined;
}
};

// Provide an error message in the panel if possible.
const show_error = (message: string) => {
Expand All @@ -667,7 +672,7 @@ const show_error = (message: string) => {
message + "\nSee https://github.com/bjones1/CodeChat_Editor."
);
}
}
};

// Only render if the window and editor are active, we have a valid render
// client, and the webview is visible.
Expand All @@ -676,14 +681,33 @@ const can_render = () => {
vscode.window.activeTextEditor !== undefined &&
websocket !== undefined &&
(codechat_client_location === CodeChatEditorClientLocation.browser ||
(webview_panel !== undefined))
webview_panel !== undefined)
);
}
};

const get_document = (file_path: string) => {
// Look through all open documents to see if we have the requested file.
for (const doc of vscode.workspace.textDocuments) {
if (doc.fileName === file_path) {
// Make the possibly incorrect assumption that only Windows filesystems
// are case-insensitive; I don't know how to easily determine the
// case-sensitivity of the current filesystem without extra probing code
// (write a file in mixed case, try to open it in another mixed case.)
// Per
// [How to Work with Different Filesystems](https://nodejs.org/en/learn/manipulating-files/working-with-different-filesystems#filesystem-behavior),
// "Be wary of inferring filesystem behavior from `process.platform`.
// For example, do not assume that because your program is running on
// Darwin that you are therefore working on a case-insensitive
// filesystem (HFS+), as the user may be using a case-sensitive
// filesystem (HFSX)."
//
// The same article
// [recommends](https://nodejs.org/en/learn/manipulating-files/working-with-different-filesystems#be-prepared-for-slight-differences-in-comparison-functions)
// using `toUpperCase` for case-insensitive filename comparisons.
if (
(!is_windows && doc.fileName === file_path) ||
(is_windows &&
doc.fileName.toUpperCase() === file_path.toUpperCase())
) {
return doc;
}
}
Expand Down Expand Up @@ -755,4 +779,4 @@ const run_server = (args: string[]) => {
stderr += chunk.toString();
});
});
}
};
Loading
Loading