Skip to content

Commit 93a6643

Browse files
committed
Use anyhow
1 parent e7d2bbb commit 93a6643

File tree

6 files changed

+12
-16
lines changed

6 files changed

+12
-16
lines changed

pikelet-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ editor = ["pikelet-editor"]
2020
language-server = ["pikelet-language-server"]
2121

2222
[dependencies]
23+
anyhow = "1.0"
2324
codespan-reporting = "0.9.5"
2425
pikelet = { path = "../pikelet" }
2526
pikelet-editor = { path = "../pikelet-editor", optional = true }

pikelet-cli/src/lib.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::error::Error;
1+
use anyhow::anyhow;
22

33
pub mod repl;
44

@@ -23,14 +23,11 @@ pub enum Options {
2323
}
2424

2525
/// Run the CLI with the given options
26-
pub fn run(options: Options) -> Result<(), Box<dyn Error>> {
26+
pub fn run(options: Options) -> anyhow::Result<()> {
2727
match options {
28-
Options::Check => Err("not yet implemented".into()),
28+
Options::Check => Err(anyhow!("not yet implemented")),
2929
#[cfg(feature = "editor")]
30-
Options::Editor => {
31-
pikelet_editor::run();
32-
Ok(())
33-
}
30+
Options::Editor => Ok(pikelet_editor::run()),
3431
#[cfg(feature = "language-server")]
3532
Options::LanguageServer => pikelet_language_server::run(),
3633
Options::Repl(options) => repl::run(options),

pikelet-cli/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use pikelet_cli::Options;
2-
use std::error::Error;
32
use structopt::StructOpt;
43

5-
fn main() -> Result<(), Box<dyn Error>> {
4+
fn main() -> anyhow::Result<()> {
65
pikelet_cli::run(Options::from_args())
76
}

pikelet-cli/src/repl.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std::error::Error;
21
use std::sync::Arc;
32

43
const HISTORY_FILE_NAME: &str = "history";
@@ -47,7 +46,7 @@ fn term_width() -> usize {
4746
}
4847

4948
/// Run the REPL with the given options.
50-
pub fn run(options: Options) -> Result<(), Box<dyn Error>> {
49+
pub fn run(options: Options) -> anyhow::Result<()> {
5150
use codespan_reporting::files::SimpleFile;
5251
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
5352
use pikelet::lang::{core, surface};

pikelet-language-server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ license = "Apache-2.0"
1515
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1616

1717
[dependencies]
18+
anyhow = "1.0"
1819
flexi_logger = "0.15"
1920
log = "0.4"
2021
lsp-server = "0.3"

pikelet-language-server/src/lib.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
use log::info;
22
use lsp_server::{Connection, Message};
33
use lsp_types::{InitializeParams, ServerCapabilities};
4-
use std::error::Error;
54

6-
pub fn run() -> Result<(), Box<dyn Error>> {
5+
pub fn run() -> anyhow::Result<()> {
76
// Set up logging. Because `stdio_transport` gets a lock on stdout and stdin, we must have
87
// our logging only write out to stderr.
9-
flexi_logger::Logger::with_str("info").start().unwrap();
8+
flexi_logger::Logger::with_str("info").start()?;
109
info!("Starting Pikelet LSP server");
1110

1211
// Create the transport. Includes the stdio (stdin and stdout) versions but this could
1312
// also be implemented to use sockets or HTTP.
1413
let (connection, io_threads) = Connection::stdio();
1514

1615
// Run the server and wait for the two threads to end (typically by trigger LSP Exit event).
17-
let server_capabilities = serde_json::to_value(&ServerCapabilities::default()).unwrap();
16+
let server_capabilities = serde_json::to_value(&ServerCapabilities::default())?;
1817
let initialization_params = connection.initialize(server_capabilities)?;
1918
main_loop(&connection, initialization_params)?;
2019
io_threads.join()?;
@@ -25,7 +24,7 @@ pub fn run() -> Result<(), Box<dyn Error>> {
2524
Ok(())
2625
}
2726

28-
fn main_loop(connection: &Connection, params: serde_json::Value) -> Result<(), Box<dyn Error>> {
27+
fn main_loop(connection: &Connection, params: serde_json::Value) -> anyhow::Result<()> {
2928
let _params: InitializeParams = serde_json::from_value(params).unwrap();
3029

3130
info!("Starting Pikelet main loop");

0 commit comments

Comments
 (0)