diff --git a/Cargo.toml b/Cargo.toml index bfbc8e4..45e1d9e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,14 +2,36 @@ [workspace] members = ["crates/*", "xtask/"] +resolver = "2" [workspace.dependencies] -parser = {path = "./crates/parser", version = "0.1.0"} -vfs = {path = "./crates/vfs", version = "0.1.0"} -syntax = {path = './crates/syntax', version = "0.1.0"} -circom-lsp = {path = './crates/lsp', version = "*"} -common = { path = './crates/common', version = "*"} -database = {path = "./crates/database", version = "*"} +# Internal crates +parser = { path = "./crates/parser" } +vfs = { path = "./crates/vfs" } +syntax = { path = "./crates/syntax" } +circom-lsp = { path = "./crates/lsp" } + +# External crates +logos = "0.12.0" +rowan = "0.15.13" +lsp-types = "0.94.1" +lsp-server = "0.7.6" + +serde = "1.0.216" +serde_json = "1.0.78" + +anyhow = "1.0.79" +dashmap = "5.5.3" +path-absolutize = "3.1.1" + +# For testing +insta = { version = "1.41.1" } + +[profile.dev.package.insta] +opt-level = 3 + +[profile.dev.package.similar] +opt-level = 3 [workspace.package] rust-version = "1.71" diff --git a/README.md b/README.md index fbfbf04..70fe09c 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,65 @@ -# Install -Install follow those commands: - -```bash -git clone https://github.com/vuvoth/ccls -cd ccls -cargo xtask install --server -cargo xtask install --client -``` +# CCLS + +A language server for [Circom](https://docs.circom.io/), built with Rust and TypeScript. + +## ๐Ÿš€ Installation + +1. **Clone the repository:** + ```bash + git clone https://github.com/vuvoth/ccls.git + cd ccls + ``` + +2. **Install Rust** (if not already installed): + ๐Ÿ‘‰ https://www.rust-lang.org/tools/install + +3. **Build or test the project:** + ```bash + cargo test # Run tests + cargo build # Build the project + ``` + +--- + +## ๐Ÿงช Running Tests (with `insta` snapshots) + +Optional, but recommended for snapshot testing. + +1. **Install `cargo-insta`:** + ```bash + curl -LsSf https://insta.rs/install.sh | sh + ``` + +2. **Run the tests:** + ```bash + cargo test + ``` + +3. **Review snapshot changes:** + ```bash + cargo insta review + ``` + +๐Ÿ“˜ More info: [Insta Quickstart](https://insta.rs/docs/quickstart/) + +--- + +## ๐Ÿž Debugging the Extension + +1. **Install CCLS server and client:** + ```bash + cargo xtask install --server + cargo xtask install --client + npm audit fix --force # optional + ``` + +2. **Run the extension in VSCode:** + - Open the `ccls` project in VSCode. + - Open the *Run and Debug* panel. + - Select `Run Extension (Debug Build)` and start debugging. + +3. A new VSCode window will open. + Open a Circom file and try features like **Go to Definition**. + +--- + diff --git a/SNAPSHOT_TEST.md b/SNAPSHOT_TEST.md deleted file mode 100644 index 304166f..0000000 --- a/SNAPSHOT_TEST.md +++ /dev/null @@ -1,11 +0,0 @@ -# Snapshot Test - -* Run all tests: - ``` - cargo test - ``` - -* Review snapshot changes - ``` - cargo insta review - ``` \ No newline at end of file diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml deleted file mode 100644 index b7ee3f6..0000000 --- a/crates/common/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "common" -version = "0.1.0" -edition = "2021" -rust-version.workspace = true - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] diff --git a/crates/common/src/lib.rs b/crates/common/src/lib.rs deleted file mode 100644 index 8b13789..0000000 --- a/crates/common/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/crates/database/Cargo.toml b/crates/database/Cargo.toml deleted file mode 100644 index 58ea405..0000000 --- a/crates/database/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "database" -version = "0.1.0" -edition = "2021" -rust-version.workspace = true - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -rowan = "0.15.13" diff --git a/crates/database/src/lib.rs b/crates/database/src/lib.rs deleted file mode 100644 index 8b13789..0000000 --- a/crates/database/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/crates/database/src/main.rs b/crates/database/src/main.rs deleted file mode 100644 index e7a11a9..0000000 --- a/crates/database/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - println!("Hello, world!"); -} diff --git a/crates/lsp/Cargo.toml b/crates/lsp/Cargo.toml index 1e410f8..d0d0726 100644 --- a/crates/lsp/Cargo.toml +++ b/crates/lsp/Cargo.toml @@ -6,33 +6,20 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +parser = { workspace = true } +vfs = { workspace = true } +syntax = { workspace = true } -env_logger = "0.9.0" -serde_json = "1.0.78" -serde = { version = "1.0", features = ["derive"] } -log = "0.4.18" +rowan = { workspace = true } +lsp-server = { workspace = true } +lsp-types = { workspace = true, features = ["proposed"] } -lsp-server = "0.7.6" +serde_json = { workspace = true } +serde = { workspace = true, features = ["derive"] } -rowan = "0.15.15" - -lsp-types = {version = "0.94.1", features = ["proposed"]} -parser.workspace = true -vfs.workspace = true -syntax.workspace = true - -anyhow = "1.0.79" -dashmap = "5.5.3" -path-absolutize = "3.1.1" - -[profile] -dev.debug = 2 +anyhow = { workspace = true } +dashmap = { workspace = true } +path-absolutize = { workspace = true } [dev-dependencies] -# for snapshot testing, yaml format -insta = { version = "1.41.1", features = ["yaml"] } - -[profile.dev.package] -# compile slightly slower once, but use less memory, have faster diffs -insta.opt-level = 3 -similar.opt-level = 3 +insta = { workspace = true, features = ["yaml"] } diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index 0173d54..6eb11c7 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -6,21 +6,10 @@ version = "0.1.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -logos = "0.12.0" -lsp-types = {version = "0.94.1", features = ["proposed"]} -rowan = "0.15.15" -num-traits = "0.2" -num-derive = "0.2" -serde = "1.0.216" - -[profile.dev] -debug = 2 +logos = { workspace = true } +lsp-types = { workspace = true, features = ["proposed"] } +rowan = { workspace = true } +serde = { workspace = true } [dev-dependencies] -# for snapshot testing, yaml format -insta = { version = "1.41.1", features = ["yaml"] } - -[profile.dev.package] -# compile slightly slower once, but use less memory, have faster diffs -insta.opt-level = 3 -similar.opt-level = 3 \ No newline at end of file +insta = { workspace = true, features = ["yaml"] } diff --git a/crates/parser/src/grammar/statement.rs b/crates/parser/src/grammar/statement.rs index d2d585f..93976d9 100644 --- a/crates/parser/src/grammar/statement.rs +++ b/crates/parser/src/grammar/statement.rs @@ -1,5 +1,3 @@ -use crate::token_kind::TokenKind; - use super::{block::block, expression::expression, *}; pub(super) fn statement(p: &mut Parser) { diff --git a/crates/syntax/Cargo.toml b/crates/syntax/Cargo.toml index 795f0b1..2ea37aa 100644 --- a/crates/syntax/Cargo.toml +++ b/crates/syntax/Cargo.toml @@ -7,15 +7,10 @@ rust-version.workspace = true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rowan = "0.15.13" -parser.workspace = true -lsp-types = {version = "0.94.1", features = ["proposed"]} +parser = { workspace = true } -[dev-dependencies] -# for snapshot testing, yaml format -insta = { version = "1.41.1", features = ["yaml"] } +rowan = { workspace = true } +lsp-types = { workspace = true, features = ["proposed"] } -[profile.dev.package] -# compile slightly slower once, but use less memory, have faster diffs -insta.opt-level = 3 -similar.opt-level = 3 \ No newline at end of file +[dev-dependencies] +insta = { workspace = true, features = ["yaml"] } diff --git a/crates/syntax/src/lib.rs b/crates/syntax/src/lib.rs index 81704de..622b4ac 100644 --- a/crates/syntax/src/lib.rs +++ b/crates/syntax/src/lib.rs @@ -1,5 +1,3 @@ pub mod abstract_syntax_tree; pub mod syntax; pub mod syntax_node; -mod utils; -mod view_syntax; diff --git a/crates/syntax/src/syntax.rs b/crates/syntax/src/syntax.rs index bc07f3b..f7a87ca 100644 --- a/crates/syntax/src/syntax.rs +++ b/crates/syntax/src/syntax.rs @@ -87,11 +87,16 @@ pub fn syntax_node_from_source(source: &str, scope: Scope) -> SyntaxNode { syntax } +#[cfg(test)] +mod test_utils; + #[cfg(test)] mod tests { - use crate::test_syntax; use parser::grammar::entry::Scope; + use crate::syntax::test_utils::view_ast; + use crate::test_syntax; + #[test] fn pragma_happy_test() { test_syntax!("/src/test_files/happy/pragma.circom", Scope::Pragma); diff --git a/crates/syntax/src/view_syntax.rs b/crates/syntax/src/syntax/test_utils.rs similarity index 70% rename from crates/syntax/src/view_syntax.rs rename to crates/syntax/src/syntax/test_utils.rs index 270c710..6a876ef 100644 --- a/crates/syntax/src/view_syntax.rs +++ b/crates/syntax/src/syntax/test_utils.rs @@ -1,17 +1,20 @@ -use crate::syntax_node::SyntaxNode; - pub use rowan::{NodeOrToken, WalkEvent}; -fn level_str(level: u32) -> String { - let mut ans = String::from(""); +use crate::syntax_node::SyntaxNode; - for _i in 0..level { - ans.push_str("| "); - } - ans +#[macro_export] +macro_rules! test_syntax { + ($file_path:expr, $scope: expr) => { + let crate_path = std::env::var("CARGO_MANIFEST_DIR").unwrap(); + + let full_path = format!("{}{}", crate_path, $file_path); + let source = std::fs::read_to_string(full_path).expect("Should not failed"); + let syntax = crate::syntax::syntax_node_from_source(&source, $scope); + insta::assert_snapshot!($file_path, view_ast(&syntax)); + }; } -pub(crate) fn view_ast(node: &SyntaxNode) -> String { +pub fn view_ast(node: &SyntaxNode) -> String { let mut level = 0; let mut result = String::new(); for event in node.preorder_with_tokens() { @@ -47,3 +50,12 @@ pub(crate) fn view_ast(node: &SyntaxNode) -> String { } return result; } + +fn level_str(level: u32) -> String { + let mut ans = String::from(""); + + for _i in 0..level { + ans.push_str("| "); + } + ans +} diff --git a/crates/syntax/src/utils.rs b/crates/syntax/src/utils.rs deleted file mode 100644 index f173682..0000000 --- a/crates/syntax/src/utils.rs +++ /dev/null @@ -1,10 +0,0 @@ -#[macro_export] -macro_rules! test_syntax { - ($file_path:expr, $scope: expr) => { - let crate_path = std::env::var("CARGO_MANIFEST_DIR").unwrap(); - let full_path = format!("{}{}", crate_path, $file_path); - let source = std::fs::read_to_string(full_path).expect("Should not failed"); - let syntax = crate::syntax::syntax_node_from_source(&source, $scope); - insta::assert_snapshot!($file_path, crate::view_syntax::view_ast(&syntax)); - }; -} diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index 5fe9391..7b711b3 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -7,11 +7,7 @@ edition = "2021" rust-version.workspace = true [dependencies] -anyhow = "1.0.62" -flate2 = "1.0.24" -write-json = "0.1.2" +anyhow = { workspace = true } xshell = "0.2.2" xflags = "0.3.0" -time = { version = "0.3", default-features = false } -zip = { version = "0.6", default-features = false, features = ["deflate", "time"] } -# Avoid adding more dependencies to this crate \ No newline at end of file +# Avoid adding more dependencies to this crate