Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Add elba repl --ide-mode-socket
Browse files Browse the repository at this point in the history
  - Add the ability to run the Idris REPL in IDE socket mode after
    dependencies are built; this automatically sets elba's
    verbosity to "none."

See #43.
  • Loading branch information
David Cao committed Apr 16, 2019
1 parent 92ca813 commit 02358b7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
19 changes: 17 additions & 2 deletions src/bin/cmds/repl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::{args, get};
use clap::{App, Arg, ArgMatches, SubCommand};
use elba::{
cli::build,
util::{config::Config, errors::Res},
util::{config::Config, errors::Res, shell::Verbosity},
};
use failure::{format_err, ResultExt};
use std::env::current_dir;
Expand All @@ -21,6 +21,12 @@ pub fn cli() -> App<'static, 'static> {
.long("ide-mode")
.help("Launches the interactive IDE backend instead of a normal REPL"),
)
.arg(
Arg::with_name("ide-mode-socket")
.long("ide-mode-socket")
.conflicts_with("ide-mode")
.help("Launches the IDE socket backend"),
)
.args(&args::backends())
}

Expand All @@ -34,8 +40,17 @@ pub fn exec(c: &mut Config, args: &ArgMatches) -> Res<String> {
args.values_of("bin").map(|x| x.collect::<Vec<_>>()),
);

let interactivity = if args.is_present("ide-mode") {
build::Interactivity::IDE
} else if args.is_present("ide-mode-socket") {
c.verbosity(Verbosity::None);
build::Interactivity::Socket
} else {
build::Interactivity::Normal
};

let backend = get::backends(c, args);
let ctx = get::build_ctx(c, args);

build::repl(&ctx, &project, &ts, &backend, args.is_present("ide-mode"))
build::repl(&ctx, &project, &ts, &backend, interactivity)
}
17 changes: 13 additions & 4 deletions src/lib/cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,19 @@ pub fn install(
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum Interactivity {
Normal,
IDE,
Socket,
}

pub fn repl(
ctx: &BuildCtx,
project: &Path,
targets: &(bool, Option<Vec<&str>>),
backend: &Backend,
ide: bool,
interactivity: Interactivity,
) -> Res<String> {
let mut contents = String::new();
let project = find_manifest_root(project)?;
Expand Down Expand Up @@ -434,11 +441,13 @@ pub fn repl(
process.arg(&target.1);
}

if ide {
match interactivity {
// In ide-mode, we only want to pass the current file as the arg.
// An editor should be in charge of dealing with this.
process.arg("--ide-mode");
}
Interactivity::IDE => { process.arg("--ide-mode"); },
Interactivity::Socket => { process.arg("--ide-mode-socket"); },
_ => {},
};

// The moment of truth:
process
Expand Down

0 comments on commit 02358b7

Please sign in to comment.