mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
prepare to move run/debug splitting to handlers
This commit is contained in:
parent
325140a165
commit
148e11aa9e
2 changed files with 50 additions and 32 deletions
|
@ -26,7 +26,7 @@ use lsp_types::{
|
||||||
};
|
};
|
||||||
use project_model::TargetKind;
|
use project_model::TargetKind;
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
use stdx::format_to;
|
use stdx::{format_to, never};
|
||||||
use syntax::{algo, ast, AstNode, TextRange, TextSize};
|
use syntax::{algo, ast, AstNode, TextRange, TextSize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -1133,41 +1133,53 @@ pub(crate) fn handle_code_lens(
|
||||||
let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?;
|
let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?;
|
||||||
let cargo_target_spec = CargoTargetSpec::for_file(&snap, file_id)?;
|
let cargo_target_spec = CargoTargetSpec::for_file(&snap, file_id)?;
|
||||||
|
|
||||||
let lenses = snap
|
let annotations = snap.analysis.annotations(
|
||||||
.analysis
|
&AnnotationConfig {
|
||||||
.annotations(
|
binary_target: cargo_target_spec
|
||||||
&AnnotationConfig {
|
.map(|spec| {
|
||||||
binary_target: cargo_target_spec
|
matches!(
|
||||||
.map(|spec| {
|
spec.target_kind,
|
||||||
matches!(
|
TargetKind::Bin | TargetKind::Example | TargetKind::Test
|
||||||
spec.target_kind,
|
)
|
||||||
TargetKind::Bin | TargetKind::Example | TargetKind::Test
|
})
|
||||||
)
|
.unwrap_or(false),
|
||||||
})
|
annotate_runnables: lens_config.runnable(),
|
||||||
.unwrap_or(false),
|
annotate_impls: lens_config.implementations,
|
||||||
annotate_runnables: lens_config.runnable(),
|
annotate_references: lens_config.refs,
|
||||||
annotate_impls: lens_config.implementations,
|
annotate_method_references: lens_config.method_refs,
|
||||||
annotate_references: lens_config.refs,
|
run: lens_config.run,
|
||||||
annotate_method_references: lens_config.method_refs,
|
debug: lens_config.debug,
|
||||||
run: lens_config.run,
|
},
|
||||||
debug: lens_config.debug,
|
file_id,
|
||||||
},
|
)?;
|
||||||
file_id,
|
|
||||||
)?
|
|
||||||
.into_iter()
|
|
||||||
.map(|annotation| to_proto::code_lens(&snap, annotation).unwrap())
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
Ok(Some(lenses))
|
let mut res = Vec::new();
|
||||||
|
for a in annotations {
|
||||||
|
to_proto::code_lens(&mut res, &snap, a)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(Some(res))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn handle_code_lens_resolve(
|
pub(crate) fn handle_code_lens_resolve(
|
||||||
snap: GlobalStateSnapshot,
|
snap: GlobalStateSnapshot,
|
||||||
code_lens: CodeLens,
|
code_lens: CodeLens,
|
||||||
) -> Result<CodeLens> {
|
) -> Result<CodeLens> {
|
||||||
let annotation = from_proto::annotation(&snap, code_lens)?;
|
let annotation = from_proto::annotation(&snap, code_lens.clone())?;
|
||||||
|
let annotation = snap.analysis.resolve_annotation(annotation)?;
|
||||||
|
|
||||||
to_proto::code_lens(&snap, snap.analysis.resolve_annotation(annotation)?)
|
let mut acc = Vec::new();
|
||||||
|
to_proto::code_lens(&mut acc, &snap, annotation)?;
|
||||||
|
|
||||||
|
let res = match acc.pop() {
|
||||||
|
Some(it) if acc.is_empty() => it,
|
||||||
|
_ => {
|
||||||
|
never!();
|
||||||
|
code_lens
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn handle_document_highlight(
|
pub(crate) fn handle_document_highlight(
|
||||||
|
|
|
@ -988,9 +988,10 @@ pub(crate) fn runnable(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn code_lens(
|
pub(crate) fn code_lens(
|
||||||
|
acc: &mut Vec<lsp_types::CodeLens>,
|
||||||
snap: &GlobalStateSnapshot,
|
snap: &GlobalStateSnapshot,
|
||||||
annotation: Annotation,
|
annotation: Annotation,
|
||||||
) -> Result<lsp_types::CodeLens> {
|
) -> Result<()> {
|
||||||
match annotation.kind {
|
match annotation.kind {
|
||||||
AnnotationKind::Runnable { debug, runnable: run } => {
|
AnnotationKind::Runnable { debug, runnable: run } => {
|
||||||
let line_index = snap.file_line_index(run.nav.file_id)?;
|
let line_index = snap.file_line_index(run.nav.file_id)?;
|
||||||
|
@ -1002,7 +1003,11 @@ pub(crate) fn code_lens(
|
||||||
let command =
|
let command =
|
||||||
if debug { command::debug_single(&r) } else { command::run_single(&r, &title) };
|
if debug { command::debug_single(&r) } else { command::run_single(&r, &title) };
|
||||||
|
|
||||||
Ok(lsp_types::CodeLens { range: annotation_range, command: Some(command), data: None })
|
acc.push(lsp_types::CodeLens {
|
||||||
|
range: annotation_range,
|
||||||
|
command: Some(command),
|
||||||
|
data: None,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
AnnotationKind::HasImpls { position: file_position, data } => {
|
AnnotationKind::HasImpls { position: file_position, data } => {
|
||||||
let line_index = snap.file_line_index(file_position.file_id)?;
|
let line_index = snap.file_line_index(file_position.file_id)?;
|
||||||
|
@ -1041,7 +1046,7 @@ pub(crate) fn code_lens(
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(lsp_types::CodeLens {
|
acc.push(lsp_types::CodeLens {
|
||||||
range: annotation_range,
|
range: annotation_range,
|
||||||
command,
|
command,
|
||||||
data: Some(to_value(lsp_ext::CodeLensResolveData::Impls(goto_params)).unwrap()),
|
data: Some(to_value(lsp_ext::CodeLensResolveData::Impls(goto_params)).unwrap()),
|
||||||
|
@ -1070,13 +1075,14 @@ pub(crate) fn code_lens(
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(lsp_types::CodeLens {
|
acc.push(lsp_types::CodeLens {
|
||||||
range: annotation_range,
|
range: annotation_range,
|
||||||
command,
|
command,
|
||||||
data: Some(to_value(lsp_ext::CodeLensResolveData::References(doc_pos)).unwrap()),
|
data: Some(to_value(lsp_ext::CodeLensResolveData::References(doc_pos)).unwrap()),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) mod command {
|
pub(crate) mod command {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue