Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax-highlighter: tidy up exectuables #49685

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
251 changes: 213 additions & 38 deletions docker-images/syntax-highlighter/Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docker-images/syntax-highlighter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ edition = "2021"
license = "MIT"

[dependencies]
clap.workspace = true
rocket.workspace = true
scip.workspace = true
serde.workspace = true
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Document> {
// TODO: Filtr
// TODO: Filter

let extension = "go";

Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -43,16 +51,12 @@ fn parse_files(dir: &Path) -> Vec<ParseTiming> {
}

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:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ pub fn syntect_highlight(q: SourcegraphQuery) -> JsonValue {
}

pub fn scip_highlight(q: ScipHighlightQuery) -> Result<JsonValue, JsonValue> {
dbg!(&q);
match q.engine {
SyntaxEngine::Syntect => SYNTAX_SET.with(|ss| {
let sg_query = SourcegraphQuery {
Expand Down
30 changes: 23 additions & 7 deletions docker-images/syntax-highlighter/src/bin/scip-dump-response.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
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,
"file not found",
));
}

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());

Expand All @@ -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");
Expand Down
31 changes: 0 additions & 31 deletions docker-images/syntax-highlighter/src/bin/scip-snapshot.rs

This file was deleted.

42 changes: 0 additions & 42 deletions docker-images/syntax-highlighter/src/bin/scip-syntect.rs

This file was deleted.