mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
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:
parent
0db95fc812
commit
16ecd276f0
3 changed files with 206 additions and 8 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue