Skip to content

Commit

Permalink
Merge branch 'master' into bzlmod
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron-martin committed Jan 20, 2024
2 parents 5ba2859 + db62a3a commit 732738d
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 8 deletions.
101 changes: 101 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"

[dependencies]
anyhow = "1.0.79"
clap = { version = "4.4.18", features = ["derive"] }
either = "1.9.0"
itertools = "0.12.0"
lsp-types = "0.94.1"
Expand Down
26 changes: 19 additions & 7 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use std::{collections::HashMap, process::Command};
use std::{
collections::HashMap,
path::{Path, PathBuf},
process::Command,
};

use anyhow::anyhow;

Expand All @@ -16,11 +20,21 @@ pub(crate) trait BazelClient {
fn dump_repo_mapping(&self, repo: &str) -> anyhow::Result<HashMap<String, String>>;
}

pub(crate) struct BazelCli;
pub(crate) struct BazelCli {
bazel: PathBuf,
}

impl BazelCli {
pub fn new<P: AsRef<Path>>(bazel: P) -> Self {
Self {
bazel: bazel.as_ref().to_owned(),
}
}
}

impl BazelClient for BazelCli {
fn info(&self) -> anyhow::Result<BazelInfo> {
let output = Command::new("bazel")
let output = Command::new(&self.bazel)
.arg("info")
.current_dir(std::env::current_dir()?)
.output()?;
Expand Down Expand Up @@ -49,16 +63,14 @@ impl BazelClient for BazelCli {
}

fn dump_repo_mapping(&self, repo: &str) -> anyhow::Result<HashMap<String, String>> {
let output = Command::new("bazel")
let output = Command::new(&self.bazel)
.args(["mod", "dump_repo_mapping"])
.arg(repo)
.current_dir(std::env::current_dir()?)
.output()?;

if !output.status.success() {
return Err(anyhow!(
"Command `bazel mod dump_repo_mapping` failed"
));
return Err(anyhow!("Command `bazel mod dump_repo_mapping` failed"));
}

Ok(serde_json::from_slice(&output.stdout)?)
Expand Down
22 changes: 21 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,32 @@ mod label;
#[cfg(test)]
pub mod test_fixture;

use std::path::PathBuf;

use bazel::BazelContext;
use clap::Parser;
use client::BazelCli;
use eval::ContextMode;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Args {
/// Location of the bazel binary
#[arg(long, default_value = "bazel")]
bazel: PathBuf,
}

fn main() -> anyhow::Result<()> {
let ctx = BazelContext::new(BazelCli, ContextMode::Check, true, &[], true)?;
let args = Args::parse();

let ctx = BazelContext::new(
BazelCli::new(args.bazel),
ContextMode::Check,
true,
&[],
true,
)?;

starlark_lsp::server::stdio_server(ctx)?;

Ok(())
Expand Down

0 comments on commit 732738d

Please sign in to comment.