From 966e9db2b83802dfb55d55bd3a26e69dced1bbd7 Mon Sep 17 00:00:00 2001
From: Aleksey Kladov <aleksey.kladov@gmail.com>
Date: Wed, 1 Aug 2018 10:40:07 +0300
Subject: Extract libeditor

---
 code/native/Cargo.toml |  2 +-
 code/native/src/lib.rs | 40 +++++++++-------------------------------
 2 files changed, 10 insertions(+), 32 deletions(-)

(limited to 'code/native')

diff --git a/code/native/Cargo.toml b/code/native/Cargo.toml
index 1648dfb33..3a27051b2 100644
--- a/code/native/Cargo.toml
+++ b/code/native/Cargo.toml
@@ -16,4 +16,4 @@ neon-build = "0.2.0"
 
 [dependencies]
 neon = "0.2.0"
-libsyntax2 = { path = "../../" }
+libeditor = { path = "../../libeditor" }
diff --git a/code/native/src/lib.rs b/code/native/src/lib.rs
index 068767fab..aae7ad2f3 100644
--- a/code/native/src/lib.rs
+++ b/code/native/src/lib.rs
@@ -1,42 +1,20 @@
 #[macro_use]
 extern crate neon;
-extern crate libsyntax2;
+extern crate libeditor;
 
-use libsyntax2::{
-    TextRange,
-    File,
-    utils::dump_tree,
-    SyntaxKind::*,
-    algo,
-};
 use neon::prelude::*;
 
 pub struct Wrapper {
-    inner: File,
+    inner: libeditor::File,
 }
 
-impl Wrapper {
-    fn highlight(&self) -> Vec<(TextRange, &'static str)> {
-        let mut res = Vec::new();
-        let syntax = self.inner.syntax();
-        for node in algo::walk::preorder(syntax.as_ref()) {
-            if node.kind() == ERROR {
-                res.push((node.range(), "error"))
-            }
-        }
-        res
-    }
-}
-
-
-
 declare_types! {
     /// A class for generating greeting strings.
     pub class RustFile for Wrapper {
         init(mut cx) {
             let text = cx.argument::<JsString>(0)?.value();
             Ok(Wrapper {
-                inner: File::parse(&text)
+                inner: libeditor::File::new(&text)
             })
         }
 
@@ -45,7 +23,7 @@ declare_types! {
             let tree = {
                 let guard = cx.lock();
                 let wrapper = this.borrow(&guard);
-                dump_tree(&wrapper.inner.syntax())
+                wrapper.inner.syntax_tree()
             };
             Ok(cx.string(tree.as_str()).upcast())
         }
@@ -55,15 +33,15 @@ declare_types! {
             let highlights = {
                 let guard = cx.lock();
                 let wrapper = this.borrow(&guard);
-                wrapper.highlight()
+                wrapper.inner.highlight()
             };
             let res = cx.empty_array();
-            for (i, (range, tag)) in highlights.into_iter().enumerate() {
-                let start: u32 = range.start().into();
-                let end: u32 = range.end().into();
+            for (i, hl) in highlights.into_iter().enumerate() {
+                let start: u32 = hl.range.start().into();
+                let end: u32 = hl.range.end().into();
                 let start = cx.number(start);
                 let end = cx.number(end);
-                let tag = cx.string(tag);
+                let tag = cx.string(hl.tag);
                 let hl = cx.empty_array();
                 hl.set(&mut cx, 0, start)?;
                 hl.set(&mut cx, 1, end)?;
-- 
cgit v1.2.3