diff options
author | Aleksey Kladov <[email protected]> | 2019-03-20 20:35:24 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-03-20 20:38:59 +0000 |
commit | 3eb56f7a6aab1e9814cb901c8cd90c2b4b3138af (patch) | |
tree | 807d6a51e6b949ca2932d2f93b39f38a4fdce532 /crates/ra_ide_api | |
parent | 90ff3ba64133c1bcae9d49709c4dd704ae59b1ee (diff) |
introduce Analysis::from_single_file
Diffstat (limited to 'crates/ra_ide_api')
-rw-r--r-- | crates/ra_ide_api/src/lib.rs | 17 |
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. |
213 | impl Analysis { | 213 | impl 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) |