From 3ccd05fedc46796f793295901a8619492256468e Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Mon, 18 Nov 2019 02:47:50 +0800 Subject: Add recursive expand in vscode --- crates/ra_lsp_server/src/main_loop.rs | 1 + crates/ra_lsp_server/src/main_loop/handlers.rs | 15 +++++++++++++++ crates/ra_lsp_server/src/req.rs | 15 +++++++++++++++ 3 files changed, 31 insertions(+) (limited to 'crates/ra_lsp_server') diff --git a/crates/ra_lsp_server/src/main_loop.rs b/crates/ra_lsp_server/src/main_loop.rs index 379dab438..f828efdee 100644 --- a/crates/ra_lsp_server/src/main_loop.rs +++ b/crates/ra_lsp_server/src/main_loop.rs @@ -436,6 +436,7 @@ fn on_request( })? .on::(handlers::handle_analyzer_status)? .on::(handlers::handle_syntax_tree)? + .on::(handlers::handle_expand_macro)? .on::(handlers::handle_on_type_formatting)? .on::(handlers::handle_document_symbol)? .on::(handlers::handle_workspace_symbol)? diff --git a/crates/ra_lsp_server/src/main_loop/handlers.rs b/crates/ra_lsp_server/src/main_loop/handlers.rs index 20f9aee13..783b0a827 100644 --- a/crates/ra_lsp_server/src/main_loop/handlers.rs +++ b/crates/ra_lsp_server/src/main_loop/handlers.rs @@ -47,6 +47,21 @@ pub fn handle_syntax_tree(world: WorldSnapshot, params: req::SyntaxTreeParams) - Ok(res) } +pub fn handle_expand_macro( + world: WorldSnapshot, + params: req::ExpandMacroParams, +) -> Result> { + let _p = profile("handle_expand_macro"); + let file_id = params.text_document.try_conv_with(&world)?; + let line_index = world.analysis().file_line_index(file_id)?; + let offset = params.position.map(|p| p.conv_with(&line_index)); + + match offset { + None => Ok(None), + Some(offset) => Ok(world.analysis().expand_macro(FilePosition { file_id, offset })?), + } +} + pub fn handle_selection_range( world: WorldSnapshot, params: req::SelectionRangeParams, diff --git a/crates/ra_lsp_server/src/req.rs b/crates/ra_lsp_server/src/req.rs index d25fc5726..dbc0e9624 100644 --- a/crates/ra_lsp_server/src/req.rs +++ b/crates/ra_lsp_server/src/req.rs @@ -45,6 +45,21 @@ pub struct SyntaxTreeParams { pub range: Option, } +pub enum ExpandMacro {} + +impl Request for ExpandMacro { + type Params = ExpandMacroParams; + type Result = Option<(String, String)>; + const METHOD: &'static str = "rust-analyzer/expandMacro"; +} + +#[derive(Deserialize, Debug)] +#[serde(rename_all = "camelCase")] +pub struct ExpandMacroParams { + pub text_document: TextDocumentIdentifier, + pub position: Option, +} + pub enum SelectionRangeRequest {} impl Request for SelectionRangeRequest { -- cgit v1.2.3