aboutsummaryrefslogtreecommitdiff
path: root/code/native/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-10 20:33:29 +0100
committerAleksey Kladov <[email protected]>2018-08-10 20:33:29 +0100
commit7c67612b8a894187fa3b64725531a5459f9211bf (patch)
tree9e2a536efa0c880d921fd8d4d74423afc9451fd4 /code/native/src
parent26262aaf05983c5b7f41cc438e287523268fe1eb (diff)
organizize
Diffstat (limited to 'code/native/src')
-rw-r--r--code/native/src/lib.rs88
1 files changed, 0 insertions, 88 deletions
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});