Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
CppCXY committed Nov 22, 2024
1 parent 2c3cea5 commit c368dbf
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 30 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/resources/log
/log
/bin
/server
8 changes: 4 additions & 4 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ lazy_static = "1.4.0"
encoding_rs = "0.8"
tokio = { version = "1.40.0", features = ["full"] }
notify = { version = "6.1.1", features = ["serde"] }
emmylua_parser = "0.3"
rowan = { version = "0.15.16" }
emmylua_parser = "0.5"
rowan = { version = "0.16" }
5 changes: 3 additions & 2 deletions crates/basic/src/parser/lua_node.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use emmylua_parser::{LuaSyntaxKind, LuaSyntaxNode, LuaSyntaxToken, LuaTokenKind};
use mlua::prelude::*;
use rowan::NodeOrToken;

pub enum LuaNodeWrapper {
Node(LuaSyntaxNode),
Expand Down Expand Up @@ -82,8 +83,8 @@ impl LuaUserData for LuaNodeWrapper {
LuaNodeWrapper::Node(node) => node
.children_with_tokens()
.filter_map(|it| match it {
rowan::NodeOrToken::Node(node) => Some(LuaNodeWrapper::Node(node)),
rowan::NodeOrToken::Token(token) => Some(LuaNodeWrapper::Token(token)),
NodeOrToken::Node(node) => Some(LuaNodeWrapper::Node(node)),
NodeOrToken::Token(token) => Some(LuaNodeWrapper::Token(token)),
})
.collect(),
LuaNodeWrapper::Token(_) => vec![],
Expand Down
22 changes: 0 additions & 22 deletions crates/basic/src/parser/lua_syntax_tree.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use emmylua_parser::LuaSyntaxTree as EmmyLuaSyntaxTree;
use mlua::prelude::*;
use rowan::TextSize;

use super::lua_node::LuaNodeWrapper;

Expand All @@ -16,32 +15,11 @@ impl LuaSyntaxTree {
pub fn get_root(&self) -> LuaNodeWrapper {
LuaNodeWrapper::new(self.tree.get_red_root().clone())
}

pub fn get_line_col(&self, offset: usize) -> Option<(usize, usize)> {
let offset = TextSize::from(offset as u32);
let (line, col) = self.tree.get_line_col(offset)?;
Some((line, col))
}

pub fn get_offset(&self, line: usize, col: usize) -> Option<usize> {
let offset = self.tree.get_offset(line, col)?;
Some(offset.into())
}
}

impl LuaUserData for LuaSyntaxTree {
fn add_methods<M: LuaUserDataMethods<Self>>(methods: &mut M) {
methods.add_method("getRoot", |_, this, ()| Ok(this.get_root()));
// methods.add_method("get_chunk_node", |_, this, ()| Ok(this.get_chunk_node()));
methods.add_method("getLineCol", |lua, this, offset: usize| {
let (line, col) = this.get_line_col(offset).unwrap();
let table = lua.create_table()?;
table.set(1, line)?;
table.set(2, col)?;
Ok(table)
});
methods.add_method("getOffset", |_, this, (line, col): (usize, usize)| {
Ok(this.get_offset(line, col))
});
}
}

0 comments on commit c368dbf

Please sign in to comment.