From 3eb56f7a6aab1e9814cb901c8cd90c2b4b3138af Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 Mar 2019 23:35:24 +0300 Subject: introduce Analysis::from_single_file --- crates/ra_ide_api/src/lib.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'crates/ra_ide_api/src') 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 { // API, the API should in theory be usable as a library, or via a different // protocol. impl Analysis { + // Creates an analysis instance for a single file, without any extenal + // dependencies, stdlib support or ability to apply changes. See + // `AnalysisHost` for creating a fully-featured analysis. + pub fn from_single_file(text: String) -> (Analysis, FileId) { + let mut host = AnalysisHost::default(); + let source_root = SourceRootId(0); + let mut change = AnalysisChange::new(); + change.add_root(source_root, true); + let mut crate_graph = CrateGraph::default(); + let file_id = FileId(0); + crate_graph.add_crate_root(file_id, Edition::Edition2018); + change.add_file(source_root, file_id, "main.rs".into(), Arc::new(text)); + change.set_crate_graph(crate_graph); + host.apply_change(change); + (host.analysis(), file_id) + } + /// Debug info about the current state of the analysis pub fn status(&self) -> String { status::status(&*self.db) -- cgit v1.2.3