Skip to content

Commit

Permalink
add return
Browse files Browse the repository at this point in the history
  • Loading branch information
matoous committed Jan 8, 2024
1 parent 3d5201e commit 7633b26
Showing 1 changed file with 69 additions and 48 deletions.
117 changes: 69 additions & 48 deletions helix-term/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1180,58 +1180,79 @@ impl Application {
let language_server = language_server!();
let offset_encoding = language_server.offset_encoding();

if params.external.unwrap_or_default() {
self.jobs
.callback(crate::open_external_url_callback(params.uri));
return;
}

let path = match params.uri.to_file_path() {
Ok(path) => path,
Err(_) => {
log::error!("Unsupported file URI: {}", params.uri);
return;
let success = match params {
lsp::ShowDocumentParams {
external: Some(true),
uri,
..
} => {
self.jobs.callback(crate::open_external_url_callback(uri));
true
}
};

let action = match params.take_focus {
Some(true) => helix_view::editor::Action::Replace,
_ => helix_view::editor::Action::HorizontalSplit,
};
lsp::ShowDocumentParams {
uri,
selection,
take_focus,
..
} => {
match uri.to_file_path() {
Ok(path) => {
let action = match take_focus {
Some(true) => helix_view::editor::Action::Replace,
_ => helix_view::editor::Action::HorizontalSplit,
};

let doc = match self.editor.open(&path, action) {
Ok(id) => doc_mut!(self.editor, &id),
Err(err) => {
log::error!("failed to open path: {:?}: {:?}", params.uri, err);
return;
match self.editor.open(&path, action) {
Ok(id) => {
let doc = doc_mut!(self.editor, &id);
if let Some(range) = selection {
// TODO: convert inside server
if let Some(new_range) = lsp_range_to_range(
doc.text(),
range,
offset_encoding,
) {
let view = view_mut!(self.editor);

// we flip the range so that the cursor sits on the start of the symbol
// (for example start of the function).
doc.set_selection(
view.id,
Selection::single(
new_range.head,
new_range.anchor,
),
);
if action.align_view(view, doc.id()) {
align_view(doc, view, Align::Center);
}
} else {
log::warn!(
"lsp position out of bounds - {:?}",
range
);
};
};
true
}
Err(err) => {
log::error!(
"failed to open path: {:?}: {:?}",
uri,
err
);
false
}
}
}
Err(err) => {
log::error!("unsupported file URI: {}: {:?}", uri, err);
false
}
}
}
};

if let Some(range) = params.selection {
// TODO: convert inside server
let new_range = if let Some(new_range) =
lsp_range_to_range(doc.text(), range, offset_encoding)
{
new_range
} else {
log::warn!("lsp position out of bounds - {:?}", range);
return;
};

let view = view_mut!(self.editor);

// we flip the range so that the cursor sits on the start of the symbol
// (for example start of the function).
doc.set_selection(
view.id,
Selection::single(new_range.head, new_range.anchor),
);
if action.align_view(view, doc.id()) {
align_view(doc, view, Align::Center);
}
}

Ok(serde_json::Value::Null)
Ok(json!(lsp::ShowDocumentResult { success }))
}
};

Expand Down

0 comments on commit 7633b26

Please sign in to comment.