Skip to content

Commit

Permalink
Make Rust side of editor handler more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
DavisVaughan committed Jul 14, 2023
1 parent f55ed98 commit 0d51d92
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions crates/ark/src/lsp/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use harp::vector::CharacterVector;
use harp::vector::Vector;
use libR_sys::*;
use stdext::unwrap;
use tokio::runtime::Runtime;
use tower_lsp::lsp_types::ShowDocumentParams;
use tower_lsp::lsp_types::Url;
Expand All @@ -19,13 +20,25 @@ unsafe extern "C" fn ps_editor(file: SEXP, _title: SEXP) -> SEXP {
let rt = Runtime::new().unwrap();
let globals = R_CALLBACK_GLOBALS.as_ref().unwrap();
let files = CharacterVector::new_unchecked(file);

for file in files.iter() {
if let Some(file) = file {
rt.block_on(async move {
let uri = Url::from_file_path(&file);

let uri = unwrap!(uri, Err(_) => {
// The R side of this handles most issues, but we don't want to panic
// if some unknown file path slips through.
// `from_file_path()` doesn't return `Display`able errors, so we
// can't necessarily give a good reason.
log::error!("Can't open file at '{}'.", file);
return;
});

globals
.lsp_client
.show_document(ShowDocumentParams {
uri: Url::from_file_path(file).unwrap(),
uri,
external: Some(false),
take_focus: Some(true),
selection: None,
Expand All @@ -36,5 +49,5 @@ unsafe extern "C" fn ps_editor(file: SEXP, _title: SEXP) -> SEXP {
}
}

file
R_NilValue
}

0 comments on commit 0d51d92

Please sign in to comment.