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.
This commit is contained in:
@@ -32,13 +32,14 @@ mod references;
|
||||
mod impls;
|
||||
mod assists;
|
||||
mod diagnostics;
|
||||
mod syntax_tree;
|
||||
|
||||
#[cfg(test)]
|
||||
mod marks;
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit, AstNode, algo};
|
||||
use ra_syntax::{SourceFile, TreeArc, TextRange, TextUnit};
|
||||
use ra_text_edit::TextEdit;
|
||||
use ra_db::{
|
||||
SourceDatabase, CheckCanceled,
|
||||
@@ -246,13 +247,7 @@ impl Analysis {
|
||||
/// Returns a syntax tree represented as `String`, for debug purposes.
|
||||
// FIXME: use a better name here.
|
||||
pub fn syntax_tree(&self, file_id: FileId, text_range: Option<TextRange>) -> String {
|
||||
if let Some(text_range) = text_range {
|
||||
let file = self.db.parse(file_id);
|
||||
let node = algo::find_covering_node(file.syntax(), text_range);
|
||||
node.debug_dump()
|
||||
} else {
|
||||
self.db.parse(file_id).syntax().debug_dump()
|
||||
}
|
||||
syntax_tree::syntax_tree(&self.db, file_id, text_range)
|
||||
}
|
||||
|
||||
/// Returns an edit to remove all newlines in the range, cleaning up minor
|
||||
|
||||
Reference in New Issue
Block a user