Skip to content

Commit

Permalink
WIP: bridge uuid from JavaScrip to Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
ktiays committed Mar 22, 2023
1 parent 41af928 commit 089a42d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 98 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"cSpell.words": [
"aicursor"
],
"cmake.configureOnOpen": false
"cmake.configureOnOpen": false,
"editor.formatOnSave": true
}
4 changes: 1 addition & 3 deletions crates/cursor-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,11 @@ pub async fn generate_code(input: &GenerateInput) -> Result<(), JsValue> {
let mut previous_message: String = "".to_owned();
let mut last_token = "".to_owned();

let x = uuid::Uuid::new_v4().to_string();
node_bridge::bindings::console::log_str(&format!("{}", x));
while !finished {
if interrupted {
// Generate an UUID as conversation ID.
if conversation_id.is_none() {
conversation_id = Some(uuid::Uuid::new_v4().to_string());
conversation_id = Some(node_bridge::bindings::uuid::uuid_v4());
}
let timestamp = chrono::Utc::now().timestamp_millis();
let bot_message = BotMessage::new(
Expand Down
1 change: 1 addition & 0 deletions crates/node-bridge/src/bindings/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod buffer;
pub mod console;
pub mod https;
pub mod uuid;

pub use buffer::Buffer;
7 changes: 7 additions & 0 deletions crates/node-bridge/src/bindings/uuid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use wasm_bindgen::prelude::*;

#[wasm_bindgen(module = "uuid")]
extern "C" {
#[wasm_bindgen(js_name = "v4")]
pub fn uuid_v4() -> String;
}
95 changes: 2 additions & 93 deletions package-lock.json

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

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"scripts": {
"vscode:prepublish": "npm run package",
"compile": "webpack",
"compile:rust": "cd crates/cursor-core && wasm-pack build --target nodejs && cp pkg/cursor_core_bg.wasm ../../dist/cursor_core_bg.wasm",
"compile:rust": "cd crates/cursor-core && wasm-pack build --target nodejs --weak-refs --dev && cp pkg/cursor_core_bg.wasm ../../dist/cursor_core_bg.wasm",
"build:dev": "npm run compile:rust && npm run compile",
"watch": "webpack --watch",
"package": "webpack --mode production --devtool hidden-source-map",
Expand All @@ -55,5 +55,8 @@
"typescript": "^4.9.5",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
},
"dependencies": {
"uuid": "^9.0.0"
}
}

0 comments on commit 089a42d

Please sign in to comment.