aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/lib.rs
diff options
context:
space:
mode:
authorVille Penttinen <[email protected]>2019-03-04 06:54:54 +0000
committerVille Penttinen <[email protected]>2019-03-04 07:02:01 +0000
commit16ecd276f036de9b5dccdbcce55b25a2a5699385 (patch)
tree9e8e9ea50064a2987ca17a0e4bd5a75c80e2ab3e /crates/ra_ide_api/src/lib.rs
parent0db95fc812d2c839e847527b774dfda170266cec (diff)
Implement syntax tree support for syntax inside string
This allows us to select a string or portions of it and try parsing it as rust syntax. This is mostly helpful when developing tests where the test itself contains some rust syntax as a string.
Diffstat (limited to 'crates/ra_ide_api/src/lib.rs')
-rw-r--r--crates/ra_ide_api/src/lib.rs11
1 files changed, 3 insertions, 8 deletions
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index 3e7cfbb54..b8a4adbce 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -32,13 +32,14 @@ mod references;
32mod impls; 32mod impls;
33mod assists; 33mod assists;
34mod diagnostics; 34mod diagnostics;
35mod syntax_tree;
35 36
36#[cfg(test)] 37#[cfg(test)]
37mod marks; 38mod marks;
38 39
39use std::sync::Arc; 40use std::sync::Arc;
40 41
41use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit, AstNode, algo}; 42use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit};
42use ra_text_edit::TextEdit; 43use ra_text_edit::TextEdit;
43use ra_db::{ 44use ra_db::{
44 SourceDatabase, CheckCanceled, 45 SourceDatabase, CheckCanceled,
@@ -246,13 +247,7 @@ impl Analysis {
246 /// Returns a syntax tree represented as `String`, for debug purposes. 247 /// Returns a syntax tree represented as `String`, for debug purposes.
247 // FIXME: use a better name here. 248 // FIXME: use a better name here.
248 pub fn syntax_tree(&self, file_id: FileId, text_range: Option<TextRange>) -> String { 249 pub fn syntax_tree(&self, file_id: FileId, text_range: Option<TextRange>) -> String {
249 if let Some(text_range) = text_range { 250 syntax_tree::syntax_tree(&self.db, file_id, 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 }
256 } 251 }
257 252
258 /// Returns an edit to remove all newlines in the range, cleaning up minor 253 /// Returns an edit to remove all newlines in the range, cleaning up minor