mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
implement first pass of memory layout viewer
This commit is contained in:
parent
db0add1ce9
commit
cfa15d49aa
9 changed files with 561 additions and 6 deletions
|
@ -1689,6 +1689,34 @@ pub(crate) fn handle_move_item(
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn handle_view_recursive_memory_layout(
|
||||
snap: GlobalStateSnapshot,
|
||||
params: lsp_ext::ViewRecursiveMemoryLayoutParams,
|
||||
) -> Result<Option<lsp_ext::RecursiveMemoryLayout>> {
|
||||
let _p = profile::span("view_recursive_memory_layout");
|
||||
let file_id = from_proto::file_id(&snap, ¶ms.text_document.uri)?;
|
||||
let line_index = snap.file_line_index(file_id)?;
|
||||
let offset = from_proto::offset(&line_index, params.position)?;
|
||||
|
||||
let res = snap.analysis.get_recursive_memory_layout(FilePosition { file_id, offset })?;
|
||||
Ok(res.map(|it| lsp_ext::RecursiveMemoryLayout {
|
||||
nodes: it
|
||||
.nodes
|
||||
.iter()
|
||||
.map(|n| lsp_ext::MemoryLayoutNode {
|
||||
item_name: n.item_name.clone(),
|
||||
typename: n.typename.clone(),
|
||||
size: n.size,
|
||||
offset: n.offset,
|
||||
alignment: n.alignment,
|
||||
parent_idx: n.parent_idx,
|
||||
children_start: n.children_start,
|
||||
children_len: n.children_len,
|
||||
})
|
||||
.collect(),
|
||||
}))
|
||||
}
|
||||
|
||||
fn to_command_link(command: lsp_types::Command, tooltip: String) -> lsp_ext::CommandLink {
|
||||
lsp_ext::CommandLink { tooltip: Some(tooltip), command }
|
||||
}
|
||||
|
|
|
@ -182,6 +182,40 @@ pub struct ExpandedMacro {
|
|||
pub expansion: String,
|
||||
}
|
||||
|
||||
pub enum ViewRecursiveMemoryLayout {}
|
||||
|
||||
impl Request for ViewRecursiveMemoryLayout {
|
||||
type Params = ViewRecursiveMemoryLayoutParams;
|
||||
type Result = Option<RecursiveMemoryLayout>;
|
||||
const METHOD: &'static str = "rust-analyzer/viewRecursiveMemoryLayout";
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ViewRecursiveMemoryLayoutParams {
|
||||
pub text_document: TextDocumentIdentifier,
|
||||
pub position: Position,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RecursiveMemoryLayout {
|
||||
pub nodes: Vec<MemoryLayoutNode>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct MemoryLayoutNode {
|
||||
pub item_name: String,
|
||||
pub typename: String,
|
||||
pub size: u64,
|
||||
pub offset: u64,
|
||||
pub alignment: u64,
|
||||
pub parent_idx: i64,
|
||||
pub children_start: i64,
|
||||
pub children_len: u64,
|
||||
}
|
||||
|
||||
pub enum CancelFlycheck {}
|
||||
|
||||
impl Notification for CancelFlycheck {
|
||||
|
|
|
@ -753,6 +753,7 @@ impl GlobalState {
|
|||
)
|
||||
.on::<lsp_types::request::WillRenameFiles>(handlers::handle_will_rename_files)
|
||||
.on::<lsp_ext::Ssr>(handlers::handle_ssr)
|
||||
.on::<lsp_ext::ViewRecursiveMemoryLayout>(handlers::handle_view_recursive_memory_layout)
|
||||
.finish();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue