aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r--crates/ra_ide_api/src/lib.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs
index b8a4adbce..81ca57035 100644
--- a/crates/ra_ide_api/src/lib.rs
+++ b/crates/ra_ide_api/src/lib.rs
@@ -211,6 +211,23 @@ pub struct Analysis {
211// API, the API should in theory be usable as a library, or via a different 211// API, the API should in theory be usable as a library, or via a different
212// protocol. 212// protocol.
213impl Analysis { 213impl Analysis {
214 // Creates an analysis instance for a single file, without any extenal
215 // dependencies, stdlib support or ability to apply changes. See
216 // `AnalysisHost` for creating a fully-featured analysis.
217 pub fn from_single_file(text: String) -> (Analysis, FileId) {
218 let mut host = AnalysisHost::default();
219 let source_root = SourceRootId(0);
220 let mut change = AnalysisChange::new();
221 change.add_root(source_root, true);
222 let mut crate_graph = CrateGraph::default();
223 let file_id = FileId(0);
224 crate_graph.add_crate_root(file_id, Edition::Edition2018);
225 change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text));
226 change.set_crate_graph(crate_graph);
227 host.apply_change(change);
228 (host.analysis(), file_id)
229 }
230
214 /// Debug info about the current state of the analysis 231 /// Debug info about the current state of the analysis
215 pub fn status(&self) -> String { 232 pub fn status(&self) -> String {
216 status::status(&*self.db) 233 status::status(&*self.db)