internal: Use Cancellable in favor of Result for clarity
This commit is contained in:
@@ -24,7 +24,7 @@ use crate::{
|
||||
line_index::{LineEndings, LineIndex, PositionEncoding},
|
||||
lsp_ext,
|
||||
lsp_utils::invalid_params_error,
|
||||
semantic_tokens, Result,
|
||||
semantic_tokens,
|
||||
};
|
||||
|
||||
pub(crate) fn position(line_index: &LineIndex, offset: TextSize) -> lsp_types::Position {
|
||||
@@ -429,7 +429,7 @@ pub(crate) fn inlay_hint(
|
||||
line_index: &LineIndex,
|
||||
render_colons: bool,
|
||||
mut inlay_hint: InlayHint,
|
||||
) -> Result<lsp_types::InlayHint> {
|
||||
) -> Cancellable<lsp_types::InlayHint> {
|
||||
match inlay_hint.kind {
|
||||
InlayKind::ParameterHint if render_colons => inlay_hint.label.append_str(":"),
|
||||
InlayKind::TypeHint if render_colons => inlay_hint.label.prepend_str(": "),
|
||||
@@ -518,7 +518,7 @@ pub(crate) fn inlay_hint(
|
||||
fn inlay_hint_label(
|
||||
snap: &GlobalStateSnapshot,
|
||||
label: InlayHintLabel,
|
||||
) -> Result<lsp_types::InlayHintLabel> {
|
||||
) -> Cancellable<lsp_types::InlayHintLabel> {
|
||||
Ok(match label.as_simple_str() {
|
||||
Some(s) => lsp_types::InlayHintLabel::String(s.into()),
|
||||
None => lsp_types::InlayHintLabel::LabelParts(
|
||||
@@ -536,7 +536,7 @@ fn inlay_hint_label(
|
||||
command: None,
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?,
|
||||
.collect::<Cancellable<Vec<_>>>()?,
|
||||
),
|
||||
})
|
||||
}
|
||||
@@ -794,7 +794,7 @@ pub(crate) fn optional_versioned_text_document_identifier(
|
||||
pub(crate) fn location(
|
||||
snap: &GlobalStateSnapshot,
|
||||
frange: FileRange,
|
||||
) -> Result<lsp_types::Location> {
|
||||
) -> Cancellable<lsp_types::Location> {
|
||||
let url = url(snap, frange.file_id);
|
||||
let line_index = snap.file_line_index(frange.file_id)?;
|
||||
let range = range(&line_index, frange.range);
|
||||
@@ -806,7 +806,7 @@ pub(crate) fn location(
|
||||
pub(crate) fn location_from_nav(
|
||||
snap: &GlobalStateSnapshot,
|
||||
nav: NavigationTarget,
|
||||
) -> Result<lsp_types::Location> {
|
||||
) -> Cancellable<lsp_types::Location> {
|
||||
let url = url(snap, nav.file_id);
|
||||
let line_index = snap.file_line_index(nav.file_id)?;
|
||||
let range = range(&line_index, nav.full_range);
|
||||
@@ -818,7 +818,7 @@ pub(crate) fn location_link(
|
||||
snap: &GlobalStateSnapshot,
|
||||
src: Option<FileRange>,
|
||||
target: NavigationTarget,
|
||||
) -> Result<lsp_types::LocationLink> {
|
||||
) -> Cancellable<lsp_types::LocationLink> {
|
||||
let origin_selection_range = match src {
|
||||
Some(src) => {
|
||||
let line_index = snap.file_line_index(src.file_id)?;
|
||||
@@ -840,7 +840,7 @@ pub(crate) fn location_link(
|
||||
fn location_info(
|
||||
snap: &GlobalStateSnapshot,
|
||||
target: NavigationTarget,
|
||||
) -> Result<(lsp_types::Url, lsp_types::Range, lsp_types::Range)> {
|
||||
) -> Cancellable<(lsp_types::Url, lsp_types::Range, lsp_types::Range)> {
|
||||
let line_index = snap.file_line_index(target.file_id)?;
|
||||
|
||||
let target_uri = url(snap, target.file_id);
|
||||
@@ -854,12 +854,12 @@ pub(crate) fn goto_definition_response(
|
||||
snap: &GlobalStateSnapshot,
|
||||
src: Option<FileRange>,
|
||||
targets: Vec<NavigationTarget>,
|
||||
) -> Result<lsp_types::GotoDefinitionResponse> {
|
||||
) -> Cancellable<lsp_types::GotoDefinitionResponse> {
|
||||
if snap.config.location_link() {
|
||||
let links = targets
|
||||
.into_iter()
|
||||
.map(|nav| location_link(snap, src, nav))
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
.collect::<Cancellable<Vec<_>>>()?;
|
||||
Ok(links.into())
|
||||
} else {
|
||||
let locations = targets
|
||||
@@ -867,7 +867,7 @@ pub(crate) fn goto_definition_response(
|
||||
.map(|nav| {
|
||||
location(snap, FileRange { file_id: nav.file_id, range: nav.focus_or_full_range() })
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
.collect::<Cancellable<Vec<_>>>()?;
|
||||
Ok(locations.into())
|
||||
}
|
||||
}
|
||||
@@ -881,7 +881,7 @@ pub(crate) fn snippet_text_document_edit(
|
||||
is_snippet: bool,
|
||||
file_id: FileId,
|
||||
edit: TextEdit,
|
||||
) -> Result<lsp_ext::SnippetTextDocumentEdit> {
|
||||
) -> Cancellable<lsp_ext::SnippetTextDocumentEdit> {
|
||||
let text_document = optional_versioned_text_document_identifier(snap, file_id);
|
||||
let line_index = snap.file_line_index(file_id)?;
|
||||
let mut edits: Vec<_> =
|
||||
@@ -958,7 +958,7 @@ pub(crate) fn snippet_text_document_ops(
|
||||
pub(crate) fn snippet_workspace_edit(
|
||||
snap: &GlobalStateSnapshot,
|
||||
source_change: SourceChange,
|
||||
) -> Result<lsp_ext::SnippetWorkspaceEdit> {
|
||||
) -> Cancellable<lsp_ext::SnippetWorkspaceEdit> {
|
||||
let mut document_changes: Vec<lsp_ext::SnippetDocumentChangeOperation> = Vec::new();
|
||||
|
||||
for op in source_change.file_system_edits {
|
||||
@@ -995,7 +995,7 @@ pub(crate) fn snippet_workspace_edit(
|
||||
pub(crate) fn workspace_edit(
|
||||
snap: &GlobalStateSnapshot,
|
||||
source_change: SourceChange,
|
||||
) -> Result<lsp_types::WorkspaceEdit> {
|
||||
) -> Cancellable<lsp_types::WorkspaceEdit> {
|
||||
assert!(!source_change.is_snippet);
|
||||
snippet_workspace_edit(snap, source_change).map(|it| it.into())
|
||||
}
|
||||
@@ -1048,7 +1048,7 @@ impl From<lsp_ext::SnippetTextEdit>
|
||||
pub(crate) fn call_hierarchy_item(
|
||||
snap: &GlobalStateSnapshot,
|
||||
target: NavigationTarget,
|
||||
) -> Result<lsp_types::CallHierarchyItem> {
|
||||
) -> Cancellable<lsp_types::CallHierarchyItem> {
|
||||
let name = target.name.to_string();
|
||||
let detail = target.description.clone();
|
||||
let kind = target.kind.map(symbol_kind).unwrap_or(lsp_types::SymbolKind::FUNCTION);
|
||||
@@ -1080,7 +1080,7 @@ pub(crate) fn code_action(
|
||||
snap: &GlobalStateSnapshot,
|
||||
assist: Assist,
|
||||
resolve_data: Option<(usize, lsp_types::CodeActionParams)>,
|
||||
) -> Result<lsp_ext::CodeAction> {
|
||||
) -> Cancellable<lsp_ext::CodeAction> {
|
||||
let mut res = lsp_ext::CodeAction {
|
||||
title: assist.label.to_string(),
|
||||
group: assist.group.filter(|_| snap.config.code_action_group()).map(|gr| gr.0),
|
||||
@@ -1113,13 +1113,13 @@ pub(crate) fn code_action(
|
||||
pub(crate) fn runnable(
|
||||
snap: &GlobalStateSnapshot,
|
||||
runnable: Runnable,
|
||||
) -> Result<lsp_ext::Runnable> {
|
||||
) -> Cancellable<lsp_ext::Runnable> {
|
||||
let config = snap.config.runnables();
|
||||
let spec = CargoTargetSpec::for_file(snap, runnable.nav.file_id)?;
|
||||
let workspace_root = spec.as_ref().map(|it| it.workspace_root.clone());
|
||||
let target = spec.as_ref().map(|s| s.target.clone());
|
||||
let (cargo_args, executable_args) =
|
||||
CargoTargetSpec::runnable_args(snap, spec, &runnable.kind, &runnable.cfg)?;
|
||||
CargoTargetSpec::runnable_args(snap, spec, &runnable.kind, &runnable.cfg);
|
||||
let label = runnable.label(target);
|
||||
let location = location_link(snap, None, runnable.nav)?;
|
||||
|
||||
@@ -1142,7 +1142,7 @@ pub(crate) fn code_lens(
|
||||
acc: &mut Vec<lsp_types::CodeLens>,
|
||||
snap: &GlobalStateSnapshot,
|
||||
annotation: Annotation,
|
||||
) -> Result<()> {
|
||||
) -> Cancellable<()> {
|
||||
let client_commands_config = snap.config.client_commands();
|
||||
match annotation.kind {
|
||||
AnnotationKind::Runnable(run) => {
|
||||
|
||||
Reference in New Issue
Block a user