🐛 fix Neon Rust glue code
This commit is contained in:
parent
f00009fd98
commit
540bd13abc
2 changed files with 38 additions and 16 deletions
|
|
@ -10,7 +10,7 @@ import { registerAllCodeLensProviders } from "../lang-server/codeLens";
|
|||
import { getExtensionUri } from "../util/vscode";
|
||||
import { setupInlineTips } from "./inlineTips";
|
||||
import { startProxy } from "./proxy";
|
||||
const cpuCount = require("../sync.node");
|
||||
// const sync = require("../sync.node");
|
||||
|
||||
export let extensionContext: vscode.ExtensionContext | undefined = undefined;
|
||||
export let ideProtocolClient: IdeProtocolClient;
|
||||
|
|
@ -100,8 +100,6 @@ function showRefactorMigrationMessage() {
|
|||
}
|
||||
|
||||
export async function activateExtension(context: vscode.ExtensionContext) {
|
||||
console.log("owijfio: ", cpuCount.get());
|
||||
|
||||
// Add necessary files
|
||||
getTsConfigPath();
|
||||
|
||||
|
|
|
|||
|
|
@ -10,23 +10,46 @@ mod utils;
|
|||
|
||||
use neon::prelude::*;
|
||||
|
||||
// fn sync_results(mut cx: FunctionContext) -> JsResult<JsArray> {
|
||||
// let dir = cx.argument::<JsString>(0)?;
|
||||
// let branch = cx.argument::<JsString>(1)?;
|
||||
fn build_js_array<'a>(
|
||||
rs_array: Vec<(String, String)>,
|
||||
cx: &mut FunctionContext<'a>,
|
||||
) -> Handle<'a, JsArray> {
|
||||
let js_array = JsArray::new(cx, rs_array.len() as u32);
|
||||
for (i, (name, hash)) in rs_array.iter().enumerate() {
|
||||
let js_object = JsObject::new(cx);
|
||||
|
||||
// let results = sync::sync(Path::new(&dir), Some(&branch))
|
||||
let name = JsString::new(cx, &name);
|
||||
let _ = js_object.set(cx, "name", name);
|
||||
let hash = JsString::new(cx, &hash);
|
||||
let _ = js_object.set(cx, "hash", hash);
|
||||
|
||||
// let js_array = JsArray::new(&mut cx, 4);
|
||||
let _ = js_array.set(cx, i as u32, js_object);
|
||||
}
|
||||
|
||||
// for (i, result) in results.iter().enumerate() {
|
||||
// let js_object = JsObject::new(&mut cx);
|
||||
// js_object.set(&mut cx, "name", JsString::new(&mut cx, &result.0))?;
|
||||
// js_object.set(&mut cx, "status", JsString::new(&mut cx, &result.1))?;
|
||||
// js_array.set(&mut cx, i as u32, js_object)?;
|
||||
// }
|
||||
return js_array;
|
||||
}
|
||||
|
||||
// Ok(js_array)
|
||||
// }
|
||||
fn sync_results(mut cx: FunctionContext) -> JsResult<JsObject> {
|
||||
let dir = cx.argument::<JsString>(0)?.value(&mut cx);
|
||||
let branch = cx.argument::<JsString>(1)?.value(&mut cx);
|
||||
|
||||
let results = sync::sync(Path::new(&dir), Some(&branch)).unwrap();
|
||||
|
||||
let final_object = JsObject::new(&mut cx);
|
||||
let compute = build_js_array(results.0, &mut cx);
|
||||
final_object.set(&mut cx, "compute", compute)?;
|
||||
|
||||
let delete = build_js_array(results.1, &mut cx);
|
||||
final_object.set(&mut cx, "delete", delete)?;
|
||||
|
||||
let add_label = build_js_array(results.2, &mut cx);
|
||||
final_object.set(&mut cx, "add_label", add_label)?;
|
||||
|
||||
let remove_label = build_js_array(results.3, &mut cx);
|
||||
final_object.set(&mut cx, "remove_label", remove_label)?;
|
||||
|
||||
Ok(final_object)
|
||||
}
|
||||
|
||||
fn get_num_cpus(mut cx: FunctionContext) -> JsResult<JsNumber> {
|
||||
Ok(cx.number(2.0 as f64))
|
||||
|
|
@ -35,5 +58,6 @@ fn get_num_cpus(mut cx: FunctionContext) -> JsResult<JsNumber> {
|
|||
#[neon::main]
|
||||
fn main(mut cx: ModuleContext) -> NeonResult<()> {
|
||||
cx.export_function("get", get_num_cpus)?;
|
||||
cx.export_function("sync_results", sync_results)?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue