diff --git a/docker-images/syntax-highlighter/Cargo.lock b/docker-images/syntax-highlighter/Cargo.lock index fa550824cc8ed..4554e3b94a3fa 100644 --- a/docker-images/syntax-highlighter/Cargo.lock +++ b/docker-images/syntax-highlighter/Cargo.lock @@ -79,7 +79,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", "winapi", ] @@ -123,6 +123,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "487f1e0fcbe47deb8b0574e646def1c903389d95241dd1bbcc6ce4a715dfc0c1" + [[package]] name = "bumpalo" version = "3.9.1" @@ -147,6 +153,43 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "4.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42dfd32784433290c51d92c438bb72ea5063797fc3cc9a21a8c4346bebbb2098" +dependencies = [ + "bitflags 2.0.2", + "clap_derive", + "clap_lex", + "is-terminal", + "once_cell", + "strsim", + "termcolor", +] + +[[package]] +name = "clap_derive" +version = "4.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fddf67631444a3a3e3e5ac51c36a5e01335302de677bd78759eaa90ab1f46644" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "033f6b7a4acb1f358c742aaca805c939ee73b4c6209ae4318ec7aca81c42e646" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "clipboard-win" version = "4.4.1" @@ -232,7 +275,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "841ef46f4787d9097405cac4e70fb8644fc037b526e8c14054247c0263c400d0" dependencies = [ - "bitflags", + "bitflags 1.3.2", "proc-macro2", "proc-macro2-diagnostics", "quote", @@ -346,7 +389,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46e245f4c8ec30c6415c56cb132c07e69e74f1942f6b4a4061da748b49f486ca" dependencies = [ "cfg-if", - "rustix", + "rustix 0.34.2", "windows-sys 0.30.0", ] @@ -526,6 +569,12 @@ version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -535,6 +584,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "http" version = "0.2.6" @@ -638,6 +693,29 @@ version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9448015e586b611e5d322f6703812bbca2f1e709d5773ecd38ddb4e3bb649504" +[[package]] +name = "io-lifetimes" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0dd6da19f25979c7270e70fa95ab371ec3b701cd0eefc47667a09785b3c59155" +dependencies = [ + "hermit-abi 0.3.1", + "libc", + "windows-sys 0.45.0", +] + +[[package]] +name = "is-terminal" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8687c819457e979cc940d09cb16e42a1bf70aa6b60a549de6d3a62a0ee90c69e" +dependencies = [ + "hermit-abi 0.3.1", + "io-lifetimes 1.0.8", + "rustix 0.36.10", + "windows-sys 0.45.0", +] + [[package]] name = "itoa" version = "1.0.1" @@ -652,9 +730,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.121" +version = "0.2.140" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efaa7b300f3b5fe8eb6bf21ce3895e1751d9665086af2d64b42f19701015ff4f" +checksum = "99227334921fae1a979cf0bfdfcc6b3e5ce376ef57e16fb6fb3ea2ed6095f80c" [[package]] name = "libloading" @@ -687,6 +765,12 @@ version = "0.0.42" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5284f00d480e1c39af34e72f8ad60b94f47007e3481cd3b731c1d67190ddc7b7" +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + [[package]] name = "lock_api" version = "0.4.7" @@ -819,7 +903,7 @@ version = "0.23.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f866317acbd3a240710c63f065ffb1e4fd466259045ccb504130b7f668f35c6" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cc", "cfg-if", "libc", @@ -841,7 +925,7 @@ version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" dependencies = [ - "hermit-abi", + "hermit-abi 0.1.19", "libc", ] @@ -866,7 +950,7 @@ version = "6.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67ddfe2c93bb389eea6e6d713306880c7f6dcc99a75b659ce145d962c861b225" dependencies = [ - "bitflags", + "bitflags 1.3.2", "lazy_static", "libc", "onig_sys", @@ -882,6 +966,12 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "os_str_bytes" +version = "6.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ceedf44fb00f2d1984b0bc98102627ce622e083e49a5bacdb3e514fa4238e267" + [[package]] name = "output_vt100" version = "0.1.3" @@ -1001,6 +1091,30 @@ dependencies = [ "yansi", ] +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro-hack" version = "0.5.19" @@ -1009,11 +1123,11 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" -version = "1.0.37" +version = "1.0.52" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec757218438d5fda206afc041538b2f6d889286160d649a86a24d37e1235afd1" +checksum = "1d0e1ae9e836cc3beddd63db0df682593d7e2d3d891ae8c9083d2113e1744224" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] @@ -1104,7 +1218,7 @@ version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -1277,14 +1391,28 @@ version = "0.34.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96619609a54d638872db136f56941d34e2a00bb0acf3fa783a90d6b96a093ba2" dependencies = [ - "bitflags", + "bitflags 1.3.2", "errno", - "io-lifetimes", + "io-lifetimes 0.6.1", "libc", - "linux-raw-sys", + "linux-raw-sys 0.0.42", "winapi", ] +[[package]] +name = "rustix" +version = "0.36.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fe885c3a125aa45213b68cc1472a49880cb5923dc23f522ad2791b882228778" +dependencies = [ + "bitflags 1.3.2", + "errno", + "io-lifetimes 1.0.8", + "libc", + "linux-raw-sys 0.1.4", + "windows-sys 0.45.0", +] + [[package]] name = "rustversion" version = "1.0.6" @@ -1297,7 +1425,7 @@ version = "9.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db7826789c0e25614b03e5a54a0717a86f9ff6e6e5247f92b369472869320039" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if", "clipboard-win", "dirs-next", @@ -1357,6 +1485,7 @@ name = "scip-syntax" version = "0.1.0" dependencies = [ "anyhow", + "clap", "insta", "protobuf", "rustc-hash", @@ -1639,6 +1768,12 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d44a3643b4ff9caf57abcee9c2c621d6c03d9135e0d8b589bd9afb5992cb176a" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "syn" version = "1.0.91" @@ -1656,7 +1791,7 @@ version = "4.7.0" source = "git+https://github.com/sourcegraph/syntect?branch=main#7e02c5b4085e6d935b960b8106cdd85da04532d2" dependencies = [ "bincode", - "bitflags", + "bitflags 1.3.2", "flate2", "fnv", "lazy_static", @@ -1675,6 +1810,7 @@ dependencies = [ name = "syntect_server" version = "1.0.1" dependencies = [ + "clap", "rocket", "rustyline", "scip", @@ -1699,6 +1835,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "termcolor" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +dependencies = [ + "winapi-util", +] + [[package]] name = "thiserror" version = "1.0.30" @@ -2115,9 +2260,9 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "ubyte" -version = "0.10.1" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42756bb9e708855de2f8a98195643dff31a97f0485d90d8467b39dc24be9e8fe" +checksum = "c81f0dae7d286ad0d9366d7679a77934cfc3cf3a8d67e82669794412b2368fe6" dependencies = [ "serde", ] @@ -2132,6 +2277,12 @@ dependencies = [ "version_check", ] +[[package]] +name = "unicode-ident" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" + [[package]] name = "unicode-segmentation" version = "1.9.0" @@ -2306,19 +2457,43 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc 0.42.1", - "windows_i686_gnu 0.42.1", - "windows_i686_msvc 0.42.1", - "windows_x86_64_gnu 0.42.1", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", "windows_x86_64_gnullvm", - "windows_x86_64_msvc 0.42.1", + "windows_x86_64_msvc 0.42.2", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" [[package]] name = "windows_aarch64_msvc" @@ -2328,9 +2503,9 @@ checksum = "29277a4435d642f775f63c7d1faeb927adba532886ce0287bd985bffb16b6bca" [[package]] name = "windows_aarch64_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" [[package]] name = "windows_i686_gnu" @@ -2340,9 +2515,9 @@ checksum = "1145e1989da93956c68d1864f32fb97c8f561a8f89a5125f6a2b7ea75524e4b8" [[package]] name = "windows_i686_gnu" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" [[package]] name = "windows_i686_msvc" @@ -2352,9 +2527,9 @@ checksum = "d4a09e3a0d4753b73019db171c1339cd4362c8c44baf1bcea336235e955954a6" [[package]] name = "windows_i686_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" [[package]] name = "windows_x86_64_gnu" @@ -2364,15 +2539,15 @@ checksum = "8ca64fcb0220d58db4c119e050e7af03c69e6f4f415ef69ec1773d9aab422d5a" [[package]] name = "windows_x86_64_gnu" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" [[package]] name = "windows_x86_64_msvc" @@ -2382,9 +2557,9 @@ checksum = "08cabc9f0066848fef4bc6a1c1668e6efce38b661d2aeec75d18d8617eebb5f1" [[package]] name = "windows_x86_64_msvc" -version = "0.42.1" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" [[package]] name = "xml-rs" diff --git a/docker-images/syntax-highlighter/Cargo.toml b/docker-images/syntax-highlighter/Cargo.toml index 32c0fd96ee02e..e90de540d1e3c 100644 --- a/docker-images/syntax-highlighter/Cargo.toml +++ b/docker-images/syntax-highlighter/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" license = "MIT" [dependencies] +clap.workspace = true rocket.workspace = true scip.workspace = true serde.workspace = true @@ -34,6 +35,7 @@ members = [ [workspace.dependencies] anyhow = "1" +clap = { version = "4.1.11", features = [ "derive" ] } rocket = { version = "0.5.0-rc.1", features = ["json"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/Cargo.toml b/docker-images/syntax-highlighter/crates/scip-syntax/Cargo.toml index 73ac6f79efb2a..236e2040054f4 100644 --- a/docker-images/syntax-highlighter/crates/scip-syntax/Cargo.toml +++ b/docker-images/syntax-highlighter/crates/scip-syntax/Cargo.toml @@ -6,10 +6,11 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -scip.workspace = true +anyhow.workspace = true +clap.workspace = true protobuf.workspace = true +scip.workspace = true tree-sitter.workspace = true -anyhow.workspace = true scip-macros = { path = "../scip-macros" } scip-treesitter = { path = "../scip-treesitter" } diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/src/bin/scip-local-nav.rs b/docker-images/syntax-highlighter/crates/scip-syntax/src/bin/scip-local-nav.rs index 0d7b4763b5b20..1e880f62fd12e 100644 --- a/docker-images/syntax-highlighter/crates/scip-syntax/src/bin/scip-local-nav.rs +++ b/docker-images/syntax-highlighter/crates/scip-syntax/src/bin/scip-local-nav.rs @@ -1,12 +1,23 @@ use std::{fs, path::Path}; +use clap::Parser; use scip::{types::Document, write_message_to_file}; use scip_syntax::{languages::LocalConfiguration, locals::parse_tree}; use scip_treesitter_languages::parsers::BundledParser; use walkdir::WalkDir; +// TODO: Could probably add some filters here for managing/enabling/disabling +// certain filetypes. + +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +struct Arguments { + /// Root directory to run local navigation over + root_dir: String, +} + fn parse_files(config: &mut LocalConfiguration, root: &Path, dir: &Path) -> Vec { - // TODO: Filtr + // TODO: Filter let extension = "go"; @@ -61,7 +72,8 @@ fn parse_files(config: &mut LocalConfiguration, root: &Path, dir: &Path) -> Vec< fn main() { println!("scip-local-nav"); - let directory = Path::new("/home/tjdevries/sourcegraph/sourcegraph.git/main/"); + let args = Arguments::parse(); + let directory = Path::new(&args.root_dir); let mut index = scip::types::Index { metadata: Some(scip::types::Metadata { diff --git a/docker-images/syntax-highlighter/crates/scip-syntax/src/bin/scip-perf.rs b/docker-images/syntax-highlighter/crates/scip-syntax/src/bin/scip-perf.rs index f0e94f4a3f474..ea40a648f8718 100644 --- a/docker-images/syntax-highlighter/crates/scip-syntax/src/bin/scip-perf.rs +++ b/docker-images/syntax-highlighter/crates/scip-syntax/src/bin/scip-perf.rs @@ -1,9 +1,17 @@ use std::{path::Path, time::Instant}; +use clap::Parser; use scip_syntax::locals::parse_tree; use scip_treesitter_languages::parsers::BundledParser; use walkdir::WalkDir; +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +struct Arguments { + /// Root directory to run local navigation over + root_dir: String, +} + struct ParseTiming { pub filepath: String, pub duration: std::time::Duration, @@ -43,16 +51,12 @@ fn parse_files(dir: &Path) -> Vec { } fn measure_parsing() { + let args = Arguments::parse(); println!("Measuring parsing"); let start = Instant::now(); - let root = Path::new( - // "/home/tjdevries/sourcegraph/sourcegraph.git/main/", - "/home/tjdevries/sourcegraph/sourcegraph.git/main/internal/database/mocks_temp.go", - // "/home/tjdevries/sourcegraph/scip-semantic/testdata/locals-nested.go", - // "/home/tjdevries/sourcegraph/scip-semantic/testdata/funcs.go", - // "/home/tjdevries/sourcegraph/scip-semantic/testdata/multi-scopes.go", - ); + let root = Path::new(&args.root_dir); + let mut timings = parse_files(root); timings.sort_by(|a, b| a.duration.cmp(&b.duration)); println!("Slowest files:"); diff --git a/docker-images/syntax-highlighter/crates/sg-syntax/src/lib.rs b/docker-images/syntax-highlighter/crates/sg-syntax/src/lib.rs index 1cc49c2548047..8e4ad0f743ef0 100644 --- a/docker-images/syntax-highlighter/crates/sg-syntax/src/lib.rs +++ b/docker-images/syntax-highlighter/crates/sg-syntax/src/lib.rs @@ -283,7 +283,6 @@ pub fn syntect_highlight(q: SourcegraphQuery) -> JsonValue { } pub fn scip_highlight(q: ScipHighlightQuery) -> Result { - dbg!(&q); match q.engine { SyntaxEngine::Syntect => SYNTAX_SET.with(|ss| { let sg_query = SourcegraphQuery { diff --git a/docker-images/syntax-highlighter/src/bin/scip-dump-response.rs b/docker-images/syntax-highlighter/src/bin/scip-dump-response.rs index 3ca25ec8f9806..bfd5d315dbaf0 100644 --- a/docker-images/syntax-highlighter/src/bin/scip-dump-response.rs +++ b/docker-images/syntax-highlighter/src/bin/scip-dump-response.rs @@ -1,11 +1,28 @@ use std::{fs, path::Path}; +use clap::Parser; + +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +struct Arguments { + /// Path to the input file + input: String, + + /// Path to the output file + output: String, + + /// Include locals, default false + #[arg(long)] + include_locals: bool, +} + fn main() -> Result<(), std::io::Error> { println!("scip-dump-response - write a dump for a filepath"); + let args = Arguments::parse(); + // read file from args - let path = std::env::args().nth(1).expect("pass an input filepath"); - let path = Path::new(&path); + let path = Path::new(&args.input); if !path.exists() { return Err(std::io::Error::new( std::io::ErrorKind::NotFound, @@ -13,10 +30,9 @@ fn main() -> Result<(), std::io::Error> { )); } - let output = std::env::args().nth(2).expect("pass an output path"); - let output = Path::new(&output); - + let output = Path::new(&args.output); println!(" reading {:?}", path); + let contents = fs::read_to_string(path)?; println!(" read {} bytes", contents.len()); @@ -37,8 +53,8 @@ fn main() -> Result<(), std::io::Error> { println!(" filetype: {:?}", filetype); - let document = - sg_syntax::treesitter_index(&filetype, &contents, false).expect("parse document"); + let document = sg_syntax::treesitter_index(&filetype, &contents, args.include_locals) + .expect("parse document"); println!(" parsed document"); scip::write_message_to_file(output, document).expect("writes document"); diff --git a/docker-images/syntax-highlighter/src/bin/scip-snapshot.rs b/docker-images/syntax-highlighter/src/bin/scip-snapshot.rs deleted file mode 100644 index 30737039ee591..0000000000000 --- a/docker-images/syntax-highlighter/src/bin/scip-snapshot.rs +++ /dev/null @@ -1,31 +0,0 @@ -use std::fs; - -use scip_treesitter::snapshot::dump_document; -use sg_syntax::treesitter_index; - -fn main() { - if let Some(path) = std::env::args().nth(1) { - let contents = match fs::read_to_string(&path) { - Ok(contents) => contents, - Err(err) => { - eprintln!("Failed to read path: {:?}. {}", path, err); - return; - } - }; - - let document = match treesitter_index("go", &contents, false) { - Ok(document) => document, - Err(err) => { - eprintln!("Failed to index document: {:?}", err); - return; - } - }; - - println!( - "\n\n{}", - dump_document(&document, &contents).expect("to dump document") - ); - } else { - panic!("Must pass a filepath"); - } -} diff --git a/docker-images/syntax-highlighter/src/bin/scip-syntect.rs b/docker-images/syntax-highlighter/src/bin/scip-syntect.rs deleted file mode 100644 index 1cbbf31c7ce82..0000000000000 --- a/docker-images/syntax-highlighter/src/bin/scip-syntect.rs +++ /dev/null @@ -1,42 +0,0 @@ -use std::fs; - -use sg_syntax::{determine_language, SourcegraphQuery}; -use syntect::{ - html::{ClassStyle, ClassedHTMLGenerator}, - parsing::SyntaxSet, -}; - -fn main() -> Result<(), std::io::Error> { - println!("scip-syntect tester"); - let (path, contents) = if let Some(path) = std::env::args().nth(1) { - match fs::read_to_string(&path) { - Ok(contents) => (path, contents), - Err(err) => { - eprintln!("Failed to read path: {:?}. {}", path, err); - return Ok(()); - } - } - } else { - eprintln!("Must pass a path as the argument"); - return Ok(()); - }; - - let q = SourcegraphQuery { - filepath: path, - code: contents.clone(), - ..Default::default() - }; - - let syntax_set = SyntaxSet::load_defaults_newlines(); - let syntax_def = determine_language(&q, &syntax_set).unwrap(); - - let mut html_generator = - ClassedHTMLGenerator::new_with_class_style(syntax_def, &syntax_set, ClassStyle::Spaced); - for line in contents.lines() { - html_generator.parse_html_for_line_which_includes_newline(line); - } - let html = html_generator.finalize(); - println!("{}", html); - - Ok(()) -}