mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
MIR episode 4
This commit is contained in:
parent
001607fdb4
commit
6312fbf521
47 changed files with 2557 additions and 805 deletions
|
@ -574,6 +574,7 @@ pub struct LensConfig {
|
|||
// runnables
|
||||
pub run: bool,
|
||||
pub debug: bool,
|
||||
pub interpret: bool,
|
||||
|
||||
// implementations
|
||||
pub implementations: bool,
|
||||
|
@ -1423,6 +1424,9 @@ impl Config {
|
|||
LensConfig {
|
||||
run: self.data.lens_enable && self.data.lens_run_enable,
|
||||
debug: self.data.lens_enable && self.data.lens_debug_enable,
|
||||
interpret: self.data.lens_enable
|
||||
&& self.data.lens_run_enable
|
||||
&& self.data.interpret_tests,
|
||||
implementations: self.data.lens_enable && self.data.lens_implementations_enable,
|
||||
method_refs: self.data.lens_enable && self.data.lens_references_method_enable,
|
||||
refs_adt: self.data.lens_enable && self.data.lens_references_adt_enable,
|
||||
|
@ -1481,7 +1485,6 @@ impl Config {
|
|||
}
|
||||
},
|
||||
keywords: self.data.hover_documentation_keywords_enable,
|
||||
interpret_tests: self.data.interpret_tests,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -163,6 +163,16 @@ pub(crate) fn handle_view_mir(
|
|||
Ok(res)
|
||||
}
|
||||
|
||||
pub(crate) fn handle_interpret_function(
|
||||
snap: GlobalStateSnapshot,
|
||||
params: lsp_types::TextDocumentPositionParams,
|
||||
) -> Result<String> {
|
||||
let _p = profile::span("handle_interpret_function");
|
||||
let position = from_proto::file_position(&snap, params)?;
|
||||
let res = snap.analysis.interpret_function(position)?;
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
pub(crate) fn handle_view_file_text(
|
||||
snap: GlobalStateSnapshot,
|
||||
params: lsp_types::TextDocumentIdentifier,
|
||||
|
|
|
@ -90,6 +90,14 @@ impl Request for ViewMir {
|
|||
const METHOD: &'static str = "rust-analyzer/viewMir";
|
||||
}
|
||||
|
||||
pub enum InterpretFunction {}
|
||||
|
||||
impl Request for InterpretFunction {
|
||||
type Params = lsp_types::TextDocumentPositionParams;
|
||||
type Result = String;
|
||||
const METHOD: &'static str = "rust-analyzer/interpretFunction";
|
||||
}
|
||||
|
||||
pub enum ViewFileText {}
|
||||
|
||||
impl Request for ViewFileText {
|
||||
|
|
|
@ -665,6 +665,7 @@ impl GlobalState {
|
|||
.on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)
|
||||
.on::<lsp_ext::ViewHir>(handlers::handle_view_hir)
|
||||
.on::<lsp_ext::ViewMir>(handlers::handle_view_mir)
|
||||
.on::<lsp_ext::InterpretFunction>(handlers::handle_interpret_function)
|
||||
.on::<lsp_ext::ViewFileText>(handlers::handle_view_file_text)
|
||||
.on::<lsp_ext::ViewCrateGraph>(handlers::handle_view_crate_graph)
|
||||
.on::<lsp_ext::ViewItemTree>(handlers::handle_view_item_tree)
|
||||
|
|
|
@ -1215,6 +1215,14 @@ pub(crate) fn code_lens(
|
|||
data: None,
|
||||
})
|
||||
}
|
||||
if lens_config.interpret {
|
||||
let command = command::interpret_single(&r);
|
||||
acc.push(lsp_types::CodeLens {
|
||||
range: annotation_range,
|
||||
command: Some(command),
|
||||
data: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
AnnotationKind::HasImpls { pos: file_range, data } => {
|
||||
if !client_commands_config.show_reference {
|
||||
|
@ -1359,6 +1367,15 @@ pub(crate) mod command {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn interpret_single(_runnable: &lsp_ext::Runnable) -> lsp_types::Command {
|
||||
lsp_types::Command {
|
||||
title: "Interpret".into(),
|
||||
command: "rust-analyzer.interpretFunction".into(),
|
||||
// FIXME: use the `_runnable` here.
|
||||
arguments: Some(vec![]),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn goto_location(
|
||||
snap: &GlobalStateSnapshot,
|
||||
nav: &NavigationTarget,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue