Add "view file text" command to debug sync issues

This commit is contained in:
Jonas Schievink 2022-03-31 14:50:33 +02:00
parent 259182b50b
commit ec2d023383
8 changed files with 89 additions and 1 deletions

View file

@ -123,6 +123,14 @@ pub(crate) fn handle_view_hir(
Ok(res)
}
pub(crate) fn handle_view_file_text(
snap: GlobalStateSnapshot,
params: lsp_types::TextDocumentIdentifier,
) -> Result<String> {
let file_id = from_proto::file_id(&snap, &params.uri)?;
Ok(snap.analysis.file_text(file_id)?.to_string())
}
pub(crate) fn handle_view_item_tree(
snap: GlobalStateSnapshot,
params: lsp_ext::ViewItemTreeParams,

View file

@ -70,6 +70,14 @@ impl Request for ViewHir {
const METHOD: &'static str = "rust-analyzer/viewHir";
}
pub enum ViewFileText {}
impl Request for ViewFileText {
type Params = lsp_types::TextDocumentIdentifier;
type Result = String;
const METHOD: &'static str = "rust-analyzer/viewFileText";
}
#[derive(Deserialize, Serialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct ViewCrateGraphParams {

View file

@ -590,6 +590,7 @@ impl GlobalState {
.on::<lsp_ext::AnalyzerStatus>(handlers::handle_analyzer_status)
.on::<lsp_ext::SyntaxTree>(handlers::handle_syntax_tree)
.on::<lsp_ext::ViewHir>(handlers::handle_view_hir)
.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)
.on::<lsp_ext::ExpandMacro>(handlers::handle_expand_macro)