aboutsummaryrefslogtreecommitdiff
path: root/code/native
diff options
context:
space:
mode:
Diffstat (limited to 'code/native')
-rw-r--r--code/native/Cargo.toml19
-rw-r--r--code/native/build.rs7
-rw-r--r--code/native/src/lib.rs88
3 files changed, 0 insertions, 114 deletions
diff --git a/code/native/Cargo.toml b/code/native/Cargo.toml
deleted file mode 100644
index 3a27051b2..000000000
--- a/code/native/Cargo.toml
+++ /dev/null
@@ -1,19 +0,0 @@
1[package]
2name = "backend"
3version = "0.1.0"
4authors = ["Aleksey Kladov <[email protected]>"]
5license = "MIT"
6build = "build.rs"
7exclude = ["artifacts.json", "index.node"]
8[workspace]
9
10[lib]
11name = "backend"
12crate-type = ["dylib"]
13
14[build-dependencies]
15neon-build = "0.2.0"
16
17[dependencies]
18neon = "0.2.0"
19libeditor = { path = "../../libeditor" }
diff --git a/code/native/build.rs b/code/native/build.rs
deleted file mode 100644
index 687a66194..000000000
--- a/code/native/build.rs
+++ /dev/null
@@ -1,7 +0,0 @@
1extern crate neon_build;
2
3fn main() {
4 neon_build::setup(); // must be called in build.rs
5
6 // add project-specific build logic here...
7}
diff --git a/code/native/src/lib.rs b/code/native/src/lib.rs
deleted file mode 100644
index cb304a141..000000000
--- a/code/native/src/lib.rs
+++ /dev/null
@@ -1,88 +0,0 @@
1#[macro_use]
2extern crate neon;
3extern crate libeditor;
4
5use neon::prelude::*;
6use libeditor::TextRange;
7
8pub struct Wrapper {
9 inner: libeditor::File,
10}
11
12declare_types! {
13 /// A class for generating greeting strings.
14 pub class RustFile for Wrapper {
15 init(mut cx) {
16 let text = cx.argument::<JsString>(0)?.value();
17 Ok(Wrapper {
18 inner: libeditor::File::new(&text)
19 })
20 }
21
22 method syntaxTree(mut cx) {
23 let tree = {
24 let this = cx.this();
25 let guard = cx.lock();
26 let wrapper = this.borrow(&guard);
27 wrapper.inner.syntax_tree()
28 };
29 Ok(cx.string(tree.as_str()).upcast())
30 }
31
32 method highlight(mut cx) {
33 let highlights = {
34 let this = cx.this();
35 let guard = cx.lock();
36 let wrapper = this.borrow(&guard);
37 wrapper.inner.highlight()
38 };
39 let res = cx.empty_array();
40 for (i, hl) in highlights.into_iter().enumerate() {
41 let start: u32 = hl.range.start().into();
42 let end: u32 = hl.range.end().into();
43 let start = cx.number(start);
44 let end = cx.number(end);
45 let tag = cx.string(hl.tag);
46 let hl = cx.empty_array();
47 hl.set(&mut cx, 0, start)?;
48 hl.set(&mut cx, 1, end)?;
49 hl.set(&mut cx, 2, tag)?;
50 res.set(&mut cx, i as u32, hl)?;
51 }
52
53 Ok(res.upcast())
54 }
55
56 method extendSelection(mut cx) {
57 let from_offset = cx.argument::<JsNumber>(0)?.value() as u32;
58 let to_offset = cx.argument::<JsNumber>(1)?.value() as u32;
59 let text_range = TextRange::from_to(from_offset.into(), to_offset.into());
60 let extended_range = {
61 let this = cx.this();
62 let guard = cx.lock();
63 let wrapper = this.borrow(&guard);
64 wrapper.inner.extend_selection(text_range)
65 };
66
67 match extended_range {
68 None => Ok(cx.null().upcast()),
69 Some(range) => {
70 let start: u32 = range.start().into();
71 let end: u32 = range.end().into();
72 let start = cx.number(start);
73 let end = cx.number(end);
74 let arr = cx.empty_array();
75 arr.set(&mut cx, 0, start)?;
76 arr.set(&mut cx, 1, end)?;
77 Ok(arr.upcast())
78 }
79 }
80
81 }
82 }
83
84}
85
86register_module!(mut cx, {
87 cx.export_class::<RustFile>("RustFile")
88});