aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/lib.rs
diff options
context:
space:
mode:
authorVille Penttinen <[email protected]>2019-03-03 10:02:55 +0000
committerVille Penttinen <[email protected]>2019-03-03 17:49:50 +0000
commitac52d9a1f1a94e2c836c8a04a316f6454936a79a (patch)
treebf0e217ed101a32c1597fb6ed0e20fc755954d2c /crates/ra_ide_api/src/lib.rs
parent17aaece6b39c2fb525be0eccce4626fc622e8236 (diff)
Add optional range parameter to SyntaxTreeParams
When range is provided, instead of showing the syntax for the whole file, we'll show the syntax tree for the given range.
Diffstat (limited to 'crates/ra_ide_api/src/lib.rs')
-rw-r--r--crates/ra_ide_api/src/lib.rs12
1 files changed, 9 insertions, 3 deletions
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index 6546d0644..3e7cfbb54 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -38,7 +38,7 @@ mod marks;
38 38
39use std::sync::Arc; 39use std::sync::Arc;
40 40
41use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit, AstNode}; 41use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit, AstNode, algo};
42use ra_text_edit::TextEdit; 42use ra_text_edit::TextEdit;
43use ra_db::{ 43use ra_db::{
44 SourceDatabase, CheckCanceled, 44 SourceDatabase, CheckCanceled,
@@ -245,8 +245,14 @@ impl Analysis {
245 245
246 /// Returns a syntax tree represented as `String`, for debug purposes. 246 /// Returns a syntax tree represented as `String`, for debug purposes.
247 // FIXME: use a better name here. 247 // FIXME: use a better name here.
248 pub fn syntax_tree(&self, file_id: FileId) -> String { 248 pub fn syntax_tree(&self, file_id: FileId, text_range: Option<TextRange>) -> String {
249 self.db.parse(file_id).syntax().debug_dump() 249 if let Some(text_range) = text_range {
250 let file = self.db.parse(file_id);
251 let node = algo::find_covering_node(file.syntax(), text_range);
252 node.debug_dump()
253 } else {
254 self.db.parse(file_id).syntax().debug_dump()
255 }
250 } 256 }
251 257
252 /// Returns an edit to remove all newlines in the range, cleaning up minor 258 /// Returns an edit to remove all newlines in the range, cleaning up minor