diff --git a/.github/actions/setup-environment/action.yml b/.github/actions/setup-environment/action.yml index 9d21893..826944a 100644 --- a/.github/actions/setup-environment/action.yml +++ b/.github/actions/setup-environment/action.yml @@ -3,8 +3,18 @@ description: "Setup Environment" runs: using: "composite" steps: + - name: Run sccache-cache + uses: mozilla-actions/sccache-action@v0.0.8 - uses: actions-rust-lang/setup-rust-toolchain@v1 with: toolchain: nightly components: rustc-codegen-cranelift-preview, rustfmt + cache-on-failure: true + env: + SCCACHE_GHA_ENABLED: "true" + RUSTC_WRAPPER: "sccache" + - uses: taiki-e/install-action@nextest + env: + SCCACHE_GHA_ENABLED: "true" + RUSTC_WRAPPER: "sccache" diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml new file mode 100644 index 0000000..5157827 --- /dev/null +++ b/.github/workflows/codspeed.yml @@ -0,0 +1,39 @@ +name: CodSpeed + +on: + push: + branches: + - "main" # or "master" + pull_request: + # `workflow_dispatch` allows CodSpeed to trigger backtest + # performance analysis in order to generate initial data. + workflow_dispatch: + +jobs: + benchmarks: + name: Run benchmarks + runs-on: ubuntu-latest-16 + steps: + - uses: actions/checkout@v4 + + - uses: ./.github/actions/setup-environment + - name: Cache Repos + id: cache-repos + uses: actions/cache@v4 + with: + path: /tmp/pink-bench + key: ${{ runner.os }}-pink-bench-${{ hashFiles('benches/parse.rs') }} + + - name: Build the benchmark target(s) + run: | + cargo install cargo-codspeed --locked + cargo codspeed build --features stable + env: + SCCACHE_GHA_ENABLED: "true" + RUSTC_WRAPPER: "sccache" + + - name: Run the benchmarks + uses: CodSpeedHQ/action@v3 + with: + run: RUST_LOG=info,resolution=warn cargo codspeed run + token: ${{ secrets.CODSPEED_TOKEN }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b28ed74..3708894 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,4 +21,6 @@ jobs: run: | ~/.cargo/bin/cargo-nextest nextest run --workspace --features stable env: - CARGO_TERM_COLOR: always + CARGO_TERM_COLOR: always + SCCACHE_GHA_ENABLED: "true" + RUSTC_WRAPPER: "sccache" diff --git a/Cargo.lock b/Cargo.lock index 6dd469b..7785f18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -38,18 +38,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b27ba24e4d8a188489d5a03c7fabc167a60809a383cdb4d15feb37479cd2a48" dependencies = [ - "itertools", + "itertools 0.10.5", "proc-macro2", "quote", "syn 1.0.109", ] -[[package]] -name = "anes" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" - [[package]] name = "anstream" version = "0.6.18" @@ -219,12 +213,6 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" -[[package]] -name = "cast" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" - [[package]] name = "cc" version = "1.2.12" @@ -242,33 +230,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "ciborium" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" -dependencies = [ - "ciborium-io", - "ciborium-ll", - "serde", -] - -[[package]] -name = "ciborium-io" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" - -[[package]] -name = "ciborium-ll" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" -dependencies = [ - "ciborium-io", - "half", -] - [[package]] name = "clap" version = "4.5.28" @@ -289,6 +250,7 @@ dependencies = [ "anstyle", "clap_lex", "strsim", + "terminal_size", ] [[package]] @@ -454,10 +416,11 @@ dependencies = [ "codegen-sdk-ast", "codegen-sdk-common", "codegen-sdk-resolution", - "criterion", + "codspeed-divan-compat", "env_logger", "git2", "log", + "rayon", "rkyv", "salsa", "sysinfo", @@ -813,12 +776,81 @@ dependencies = [ "tree-sitter", ] +[[package]] +name = "codspeed" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60e744216bfa9add3b1f2505587cbbb837923232ed10963609f4a6e3cbd99c3e" +dependencies = [ + "colored", + "libc", + "serde", + "serde_json", + "uuid", +] + +[[package]] +name = "codspeed-divan-compat" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "806a6278f157d8feb1b7c90e74a2fffab443b0d24d9a45a8565575536d6b65a9" +dependencies = [ + "codspeed", + "codspeed-divan-compat-macros", + "codspeed-divan-compat-walltime", +] + +[[package]] +name = "codspeed-divan-compat-macros" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e0cbe93863db07e8605ce3769dc7351412cf3516411fbbed8ea5a2cd0903623" +dependencies = [ + "divan-macros", + "itertools 0.14.0", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn 2.0.98", +] + +[[package]] +name = "codspeed-divan-compat-walltime" +version = "2.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0febef7d70f067b596da567d0921a83372af6a0719896e7dcbb6dbd4ed8f527b" +dependencies = [ + "cfg-if", + "clap", + "codspeed", + "condtype", + "divan-macros", + "libc", + "regex-lite", +] + [[package]] name = "colorchoice" version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990" +[[package]] +name = "colored" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" +dependencies = [ + "lazy_static", + "windows-sys 0.59.0", +] + +[[package]] +name = "condtype" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf0a07a401f374238ab8e2f11a104d2851bf9ce711ec69804834de8af45c7af" + [[package]] name = "console" version = "0.15.10" @@ -856,42 +888,6 @@ dependencies = [ "libc", ] -[[package]] -name = "criterion" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" -dependencies = [ - "anes", - "cast", - "ciborium", - "clap", - "criterion-plot", - "is-terminal", - "itertools", - "num-traits", - "once_cell", - "oorandom", - "plotters", - "rayon", - "regex", - "serde", - "serde_derive", - "serde_json", - "tinytemplate", - "walkdir", -] - -[[package]] -name = "criterion-plot" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" -dependencies = [ - "cast", - "itertools", -] - [[package]] name = "crossbeam-channel" version = "0.5.14" @@ -935,12 +931,6 @@ version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" -[[package]] -name = "crunchy" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43da5946c66ffcc7745f48db692ffbb10a83bfe0afd96235c5c2a4fb23994929" - [[package]] name = "crypto-common" version = "0.1.6" @@ -1007,6 +997,17 @@ dependencies = [ "syn 2.0.98", ] +[[package]] +name = "divan-macros" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dc51d98e636f5e3b0759a39257458b22619cac7e96d932da6eeb052891bb67c" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.98", +] + [[package]] name = "downcast" version = "0.11.0" @@ -1217,16 +1218,6 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8d1add55171497b4705a648c6b583acafb01d58050a51727785f0b2c8e0a2b2" -[[package]] -name = "half" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" -dependencies = [ - "cfg-if", - "crunchy", -] - [[package]] name = "hashbrown" version = "0.14.5" @@ -1266,12 +1257,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hermit-abi" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" - [[package]] name = "humantime" version = "2.1.0" @@ -1496,17 +1481,6 @@ dependencies = [ "similar", ] -[[package]] -name = "is-terminal" -version = "0.4.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e19b23d53f35ce9f56aebc7d1bb4e6ac1e9c0db7ac85c8d1760c04379edced37" -dependencies = [ - "hermit-abi", - "libc", - "windows-sys 0.59.0", -] - [[package]] name = "is_terminal_polyfill" version = "1.70.1" @@ -1522,6 +1496,15 @@ dependencies = [ "either", ] +[[package]] +name = "itertools" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" +dependencies = [ + "either", +] + [[package]] name = "itoa" version = "1.0.14" @@ -1642,6 +1625,12 @@ version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" +[[package]] +name = "linux-raw-sys" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db9c683daf087dc577b7506e9695b3d556a9f3849903fa28186283afd6809e9" + [[package]] name = "litemap" version = "0.7.5" @@ -1838,15 +1827,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg", -] - [[package]] name = "number_prefix" version = "0.4.0" @@ -1868,12 +1848,6 @@ version = "1.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "945462a4b81e43c4e3ba96bd7b49d834c6f61198356aa858733bc4acf3cbe62e" -[[package]] -name = "oorandom" -version = "11.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" - [[package]] name = "openssl-probe" version = "0.1.6" @@ -2024,34 +1998,6 @@ version = "0.3.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "953ec861398dccce10c670dfeaf3ec4911ca479e9c02154b3a215178c5f566f2" -[[package]] -name = "plotters" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747" -dependencies = [ - "num-traits", - "plotters-backend", - "plotters-svg", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "plotters-backend" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a" - -[[package]] -name = "plotters-svg" -version = "0.3.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670" -dependencies = [ - "plotters-backend", -] - [[package]] name = "pluralizer" version = "0.5.0" @@ -2321,6 +2267,12 @@ dependencies = [ "regex-syntax 0.8.5", ] +[[package]] +name = "regex-lite" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a" + [[package]] name = "regex-syntax" version = "0.6.29" @@ -2438,7 +2390,20 @@ dependencies = [ "bitflags 2.8.0", "errno", "libc", - "linux-raw-sys", + "linux-raw-sys 0.4.15", + "windows-sys 0.59.0", +] + +[[package]] +name = "rustix" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7178faa4b75a30e269c71e61c353ce2748cf3d76f0c44c393f4e60abf49b825" +dependencies = [ + "bitflags 2.8.0", + "errno", + "libc", + "linux-raw-sys 0.9.2", "windows-sys 0.59.0", ] @@ -2706,7 +2671,17 @@ dependencies = [ "fastrand", "getrandom", "once_cell", - "rustix", + "rustix 0.38.44", + "windows-sys 0.59.0", +] + +[[package]] +name = "terminal_size" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "45c6481c4829e4cc63825e62c49186a34538b7b2750b73b266581ffb612fb5ed" +dependencies = [ + "rustix 1.0.2", "windows-sys 0.59.0", ] @@ -2778,16 +2753,6 @@ dependencies = [ "zerovec", ] -[[package]] -name = "tinytemplate" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" -dependencies = [ - "serde", - "serde_json", -] - [[package]] name = "tinyvec" version = "1.8.1" @@ -3077,6 +3042,9 @@ name = "uuid" version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c1f41ffb7cf259f1ecc2876861a17e7142e63ead296f671f81f6ae85903e0d6" +dependencies = [ + "getrandom", +] [[package]] name = "valuable" @@ -3129,7 +3097,6 @@ checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ "cfg-if", "once_cell", - "rustversion", "wasm-bindgen-macro", ] @@ -3179,16 +3146,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "web-sys" -version = "0.3.77" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" -dependencies = [ - "js-sys", - "wasm-bindgen", -] - [[package]] name = "web-time" version = "1.1.0" diff --git a/Cargo.toml b/Cargo.toml index e3bc7c3..4d295db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,9 +48,10 @@ stable = ["codegen-sdk-analyzer/stable", "typescript", "tsx", "jsx", "javascript default = ["json"] [dev-dependencies] test-log = { workspace = true } -criterion = { version = "0.5", features = ["html_reports"] } git2 = { version = "0.20.0" } tempfile = {workspace = true} +divan = { version = "2.9.1", package = "codspeed-divan-compat" } +rayon = { workspace = true } [workspace] members = [ "codegen-sdk-analyzer", diff --git a/README.md b/README.md index 4f861fa..ce8bfd9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Pink +[![CodSpeed Badge](https://img.shields.io/endpoint?url=https://codspeed.io/badge.json)](https://codspeed.io/codegen-sh/pink) + This is a rewrite of the core of the [Codegen SDK](https://github.com/codegen-sh/codegen) in Rust. ## Goals diff --git a/benches/parse.rs b/benches/parse.rs index dea5c0b..5d257a8 100644 --- a/benches/parse.rs +++ b/benches/parse.rs @@ -1,9 +1,21 @@ -use std::{hint::black_box, path::PathBuf}; +use std::{ + fmt::{self, Display}, + path::PathBuf, +}; + +use divan::AllocProfiler; +use rayon::prelude::*; +#[global_allocator] +static ALLOC: AllocProfiler = AllocProfiler::system(); use codegen_sdk_analyzer::Codebase; -use criterion::{Criterion, criterion_group, criterion_main}; -fn clone_repo(url: String, name: String, tmp_dir: &tempfile::TempDir) -> PathBuf { - let repo_path = tmp_dir.path().join(name); +// fn thread_counts() -> Vec { +// vec![/* available parallelism */ 0, 1, 4, 8] +// } +const TMP_PATH: &str = "/tmp/pink-bench"; + +fn clone_repo(url: String, name: String) -> PathBuf { + let repo_path = PathBuf::from(TMP_PATH).join(name); if !repo_path.exists() { log::info!("Cloning repo: {} to {}", url, repo_path.display()); let mut fetch_opts = git2::FetchOptions::new(); @@ -12,25 +24,81 @@ fn clone_repo(url: String, name: String, tmp_dir: &tempfile::TempDir) -> PathBuf .fetch_options(fetch_opts) .clone(&url, &repo_path) .unwrap(); + log::info!("Cloned repo: {} to {}", url, repo_path.display()); } repo_path } -fn parse_nest(path: &PathBuf) { - let _ = Codebase::new(path.clone()); +struct Repo { + pub name: &'static str, + pub url: &'static str, +} +impl Display for Repo { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.name) + } +} +const REPOS: &[Repo] = &[ + // Typescript libraries + Repo { + name: "nest", + url: "https://github.com/nestjs/nest", + }, + // Repo { + // name: "react", + // url: "https://github.com/facebook/react", + // }, + // Repo { + // name: "vscode", + // url: "https://github.com/microsoft/vscode", + // }, + // Python libraries + // Repo { + // name: "pytorch", + // url: "https://github.com/pytorch/pytorch", + // }, + Repo { + name: "mypy", + url: "https://github.com/python/mypy", + }, + // Repo { + // name: "django", + // url: "https://github.com/django/django", + // }, + // Go libraries + Repo { + name: "gin", + url: "https://github.com/gin-gonic/gin", + }, + // Repo { + // name: "kubernetes", + // url: "https://github.com/kubernetes/kubernetes", + // }, + // Rust libraries + Repo { + name: "tokio", + url: "https://github.com/tokio-rs/tokio", + }, + Repo { + name: "rust-analyzer", + url: "https://github.com/rust-lang/rust-analyzer", + }, +]; +const fn repo_indices() -> [usize; REPOS.len()] { + [0, 1, 2, 3, 4] +} +#[divan::bench(consts = repo_indices())] +fn parse(bencher: divan::Bencher) { + let repo = &REPOS[REPO]; + log::info!("Parsing repo: {}", repo.name); + let repo_path = clone_repo(repo.url.to_string(), repo.name.to_string()); + bencher.bench(|| Codebase::new(repo_path.clone())); } -fn criterion_benchmark(c: &mut Criterion) { +fn main() { env_logger::init(); - let temp_dir = tempfile::tempdir().unwrap(); - let repo_path = clone_repo( - "https://github.com/nestjs/nest".to_string(), - "nest".to_string(), - &temp_dir, - ); - c.bench_function("parse_nest", |b| { - b.iter(|| parse_nest(black_box(&repo_path))) + REPOS.par_iter().for_each(|repo| { + clone_repo(repo.url.to_string(), repo.name.to_string()); }); + // Run registered benchmarks. + divan::main(); } - -criterion_group!(benches, criterion_benchmark); -criterion_main!(benches); diff --git a/languages/codegen-sdk-go/Cargo.toml b/languages/codegen-sdk-go/Cargo.toml index af1927c..a5d3686 100644 --- a/languages/codegen-sdk-go/Cargo.toml +++ b/languages/codegen-sdk-go/Cargo.toml @@ -9,6 +9,8 @@ repository.workspace = true name = "codegen-sdk-go" description = "Go language support for codegen-sdk" +[lib] +crate-type = ["cdylib", "lib"] [dependencies] codegen-sdk-common = { workspace = true, features = ["go"] } diff --git a/languages/codegen-sdk-java/Cargo.toml b/languages/codegen-sdk-java/Cargo.toml index 49bff15..9b23210 100644 --- a/languages/codegen-sdk-java/Cargo.toml +++ b/languages/codegen-sdk-java/Cargo.toml @@ -9,6 +9,8 @@ repository.workspace = true name = "codegen-sdk-java" description = "Java language support for codegen-sdk" +[lib] +crate-type = ["cdylib", "lib"] [dependencies] codegen-sdk-common = { workspace = true, features = ["java"] } diff --git a/languages/codegen-sdk-javascript/Cargo.toml b/languages/codegen-sdk-javascript/Cargo.toml index 0a57bad..cfcacae 100644 --- a/languages/codegen-sdk-javascript/Cargo.toml +++ b/languages/codegen-sdk-javascript/Cargo.toml @@ -9,6 +9,8 @@ repository.workspace = true name = "codegen-sdk-javascript" description = "Javascript language support for codegen-sdk" +[lib] +crate-type = ["cdylib", "lib"] [dependencies] codegen-sdk-common = { workspace = true, features = ["typescript"] } diff --git a/languages/codegen-sdk-json/Cargo.toml b/languages/codegen-sdk-json/Cargo.toml index 779c9a0..a7fba78 100644 --- a/languages/codegen-sdk-json/Cargo.toml +++ b/languages/codegen-sdk-json/Cargo.toml @@ -7,6 +7,8 @@ homepage.workspace = true authors.workspace = true repository.workspace = true name = "codegen-sdk-json" +[lib] +crate-type = ["cdylib", "lib"] [dependencies] @@ -15,8 +17,8 @@ salsa = { workspace = true } tree-sitter = { workspace = true } derive_more = { workspace = true } ambassador = { workspace = true } -indextree ={ workspace = true } -subenum = {workspace = true} +indextree = { workspace = true } +subenum = { workspace = true } bytes = { workspace = true } codegen-sdk-cst = { workspace = true } codegen-sdk-ast = { workspace = true } diff --git a/languages/codegen-sdk-jsx/Cargo.toml b/languages/codegen-sdk-jsx/Cargo.toml index e8efa4d..bbd0a4f 100644 --- a/languages/codegen-sdk-jsx/Cargo.toml +++ b/languages/codegen-sdk-jsx/Cargo.toml @@ -9,7 +9,8 @@ repository.workspace = true name = "codegen-sdk-jsx" description = "JSX language support for codegen-sdk" - +[lib] +crate-type = ["cdylib", "lib"] [dependencies] codegen-sdk-common = { workspace = true, features = ["typescript"] } salsa = { workspace = true } diff --git a/languages/codegen-sdk-markdown/Cargo.toml b/languages/codegen-sdk-markdown/Cargo.toml index 67b613f..8da889f 100644 --- a/languages/codegen-sdk-markdown/Cargo.toml +++ b/languages/codegen-sdk-markdown/Cargo.toml @@ -9,6 +9,8 @@ repository.workspace = true name = "codegen-sdk-markdown" description = "Markdown language support for codegen-sdk" +[lib] +crate-type = ["cdylib", "lib"] [dependencies] codegen-sdk-common = { workspace = true, features = ["markdown"] } diff --git a/languages/codegen-sdk-python/Cargo.toml b/languages/codegen-sdk-python/Cargo.toml index d92ee7a..a88d56b 100644 --- a/languages/codegen-sdk-python/Cargo.toml +++ b/languages/codegen-sdk-python/Cargo.toml @@ -9,6 +9,8 @@ repository.workspace = true name = "codegen-sdk-python" description = "Python language support for codegen-sdk" +[lib] +crate-type = ["cdylib", "lib"] [dependencies] codegen-sdk-common = { workspace = true, features = ["python"] } diff --git a/languages/codegen-sdk-python/src/lib.rs b/languages/codegen-sdk-python/src/lib.rs index 055032a..8a1bd20 100644 --- a/languages/codegen-sdk-python/src/lib.rs +++ b/languages/codegen-sdk-python/src/lib.rs @@ -99,7 +99,14 @@ pub mod ast { type ReferenceType = crate::ast::Call<'db>; #[salsa::tracked(return_ref)] fn resolve(self, db: &'db dyn codegen_sdk_resolution::Db, name: String) -> Vec { - let tree = self.node(db).unwrap().tree(db); + let node = match self.node(db) { + Some(node) => node, + None => { + log::warn!(target: "resolution", "No node found for file: {:?}", self.id(db)); + return Vec::new(); + } + }; + let tree = node.tree(db); let mut results = Vec::new(); for (def_name, defs) in self.definitions(db).functions(db).into_iter() { if *def_name == name { diff --git a/languages/codegen-sdk-ruby/Cargo.toml b/languages/codegen-sdk-ruby/Cargo.toml index a46c889..09b9f22 100644 --- a/languages/codegen-sdk-ruby/Cargo.toml +++ b/languages/codegen-sdk-ruby/Cargo.toml @@ -9,6 +9,8 @@ repository.workspace = true name = "codegen-sdk-ruby" description = "Ruby language support for codegen-sdk" +[lib] +crate-type = ["cdylib", "lib"] [dependencies] codegen-sdk-common = { workspace = true, features = ["ruby"] } diff --git a/languages/codegen-sdk-rust/Cargo.toml b/languages/codegen-sdk-rust/Cargo.toml index 7ac58b5..5489259 100644 --- a/languages/codegen-sdk-rust/Cargo.toml +++ b/languages/codegen-sdk-rust/Cargo.toml @@ -9,6 +9,8 @@ repository.workspace = true name = "codegen-sdk-rust" description = "Rust language support for codegen-sdk" +[lib] +crate-type = ["cdylib", "lib"] [dependencies] codegen-sdk-common = { workspace = true, features = ["rust"] } diff --git a/languages/codegen-sdk-toml/Cargo.toml b/languages/codegen-sdk-toml/Cargo.toml index cf65f8f..1608ad4 100644 --- a/languages/codegen-sdk-toml/Cargo.toml +++ b/languages/codegen-sdk-toml/Cargo.toml @@ -9,6 +9,8 @@ repository.workspace = true name = "codegen-sdk-toml" description = "TOML language support for codegen-sdk" +[lib] +crate-type = ["cdylib", "lib"] [dependencies] codegen-sdk-common = { workspace = true, features = ["toml"] } diff --git a/languages/codegen-sdk-ts_query/Cargo.toml b/languages/codegen-sdk-ts_query/Cargo.toml index 9fb91f7..722798c 100644 --- a/languages/codegen-sdk-ts_query/Cargo.toml +++ b/languages/codegen-sdk-ts_query/Cargo.toml @@ -7,6 +7,8 @@ homepage.workspace = true authors.workspace = true repository.workspace = true name = "codegen-sdk-ts_query" +[lib] +crate-type = ["cdylib", "lib"] [dependencies] @@ -15,7 +17,7 @@ salsa = { workspace = true } tree-sitter = { workspace = true } derive_more = { workspace = true } ambassador = { workspace = true } -subenum = {workspace = true} +subenum = { workspace = true } bytes = { workspace = true } codegen-sdk-cst = { workspace = true } indextree = { workspace = true } diff --git a/languages/codegen-sdk-tsx/Cargo.toml b/languages/codegen-sdk-tsx/Cargo.toml index fb6b358..e87f6c9 100644 --- a/languages/codegen-sdk-tsx/Cargo.toml +++ b/languages/codegen-sdk-tsx/Cargo.toml @@ -9,6 +9,8 @@ repository.workspace = true name = "codegen-sdk-tsx" description = "TSX language support for codegen-sdk" +[lib] +crate-type = ["cdylib", "lib"] [dependencies] codegen-sdk-common = { workspace = true, features = ["typescript"] } diff --git a/languages/codegen-sdk-typescript/Cargo.toml b/languages/codegen-sdk-typescript/Cargo.toml index 74999fe..f0453be 100644 --- a/languages/codegen-sdk-typescript/Cargo.toml +++ b/languages/codegen-sdk-typescript/Cargo.toml @@ -9,6 +9,8 @@ repository.workspace = true name = "codegen-sdk-typescript" description = "Typescript language support for codegen-sdk" +[lib] +crate-type = ["cdylib", "lib"] [dependencies] codegen-sdk-common = { workspace = true, features = ["typescript"] } diff --git a/languages/codegen-sdk-yaml/Cargo.toml b/languages/codegen-sdk-yaml/Cargo.toml index de8d370..53a5293 100644 --- a/languages/codegen-sdk-yaml/Cargo.toml +++ b/languages/codegen-sdk-yaml/Cargo.toml @@ -9,6 +9,8 @@ repository.workspace = true name = "codegen-sdk-yaml" description = "YAML language support for codegen-sdk" +[lib] +crate-type = ["cdylib", "lib"] [dependencies] codegen-sdk-common = { workspace = true, features = ["yaml"] }