aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/src
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-11-04 11:09:21 +0000
committerAleksey Kladov <[email protected]>2018-11-04 11:09:21 +0000
commitf29b0172fbcbc88160980c2e7359f92d7c0d885d (patch)
tree4ec1f709d283d3ea0b7c225a70f6439d67a5ca32 /crates/ra_analysis/src
parentcca5f862de8a4eb4a8990fdca95a4a7686937789 (diff)
Use Default everywhere
Diffstat (limited to 'crates/ra_analysis/src')
-rw-r--r--crates/ra_analysis/src/db.rs19
-rw-r--r--crates/ra_analysis/src/imp.rs12
-rw-r--r--crates/ra_analysis/src/lib.rs7
-rw-r--r--crates/ra_analysis/src/mock_analysis.rs2
4 files changed, 20 insertions, 20 deletions
diff --git a/crates/ra_analysis/src/db.rs b/crates/ra_analysis/src/db.rs
index 9548ec602..627512553 100644
--- a/crates/ra_analysis/src/db.rs
+++ b/crates/ra_analysis/src/db.rs
@@ -2,7 +2,7 @@ use std::sync::Arc;
2 2
3use ra_editor::LineIndex; 3use ra_editor::LineIndex;
4use ra_syntax::{File, SyntaxNode}; 4use ra_syntax::{File, SyntaxNode};
5use salsa; 5use salsa::{self, Database};
6 6
7use crate::{ 7use crate::{
8 db, 8 db,
@@ -15,7 +15,7 @@ use crate::{
15 Cancelable, Canceled, FileId, 15 Cancelable, Canceled, FileId,
16}; 16};
17 17
18#[derive(Default, Debug)] 18#[derive(Debug)]
19pub(crate) struct RootDatabase { 19pub(crate) struct RootDatabase {
20 runtime: salsa::Runtime<RootDatabase>, 20 runtime: salsa::Runtime<RootDatabase>,
21} 21}
@@ -26,6 +26,21 @@ impl salsa::Database for RootDatabase {
26 } 26 }
27} 27}
28 28
29impl Default for RootDatabase {
30 fn default() -> RootDatabase {
31 let mut db = RootDatabase {
32 runtime: Default::default(),
33 };
34 db.query_mut(crate::input::SourceRootQuery)
35 .set(crate::input::WORKSPACE, Default::default());
36 db.query_mut(crate::input::CrateGraphQuery)
37 .set((), Default::default());
38 db.query_mut(crate::input::LibrariesQuery)
39 .set((), Default::default());
40 db
41 }
42}
43
29pub(crate) fn check_canceled(db: &impl salsa::Database) -> Cancelable<()> { 44pub(crate) fn check_canceled(db: &impl salsa::Database) -> Cancelable<()> {
30 if db.salsa_runtime().is_current_revision_canceled() { 45 if db.salsa_runtime().is_current_revision_canceled() {
31 Err(Canceled) 46 Err(Canceled)
diff --git a/crates/ra_analysis/src/imp.rs b/crates/ra_analysis/src/imp.rs
index 77dd71dcf..4f337d163 100644
--- a/crates/ra_analysis/src/imp.rs
+++ b/crates/ra_analysis/src/imp.rs
@@ -86,22 +86,12 @@ impl Default for FileResolverImp {
86 } 86 }
87} 87}
88 88
89#[derive(Debug)] 89#[derive(Debug, Default)]
90pub(crate) struct AnalysisHostImpl { 90pub(crate) struct AnalysisHostImpl {
91 db: db::RootDatabase, 91 db: db::RootDatabase,
92} 92}
93 93
94impl AnalysisHostImpl { 94impl AnalysisHostImpl {
95 pub fn new() -> AnalysisHostImpl {
96 let mut db = db::RootDatabase::default();
97 db.query_mut(crate::input::SourceRootQuery)
98 .set(WORKSPACE, Default::default());
99 db.query_mut(crate::input::CrateGraphQuery)
100 .set((), Default::default());
101 db.query_mut(crate::input::LibrariesQuery)
102 .set((), Default::default());
103 AnalysisHostImpl { db }
104 }
105 pub fn analysis(&self) -> AnalysisImpl { 95 pub fn analysis(&self) -> AnalysisImpl {
106 AnalysisImpl { 96 AnalysisImpl {
107 db: self.db.snapshot(), 97 db: self.db.snapshot(),
diff --git a/crates/ra_analysis/src/lib.rs b/crates/ra_analysis/src/lib.rs
index 6565f69fb..4e4c65f08 100644
--- a/crates/ra_analysis/src/lib.rs
+++ b/crates/ra_analysis/src/lib.rs
@@ -99,17 +99,12 @@ impl AnalysisChange {
99} 99}
100 100
101/// `AnalysisHost` stores the current state of the world. 101/// `AnalysisHost` stores the current state of the world.
102#[derive(Debug)] 102#[derive(Debug, Default)]
103pub struct AnalysisHost { 103pub struct AnalysisHost {
104 imp: AnalysisHostImpl, 104 imp: AnalysisHostImpl,
105} 105}
106 106
107impl AnalysisHost { 107impl AnalysisHost {
108 pub fn new() -> AnalysisHost {
109 AnalysisHost {
110 imp: AnalysisHostImpl::new(),
111 }
112 }
113 /// Returns a snapshot of the current state, which you can query for 108 /// Returns a snapshot of the current state, which you can query for
114 /// semantic information. 109 /// semantic information.
115 pub fn analysis(&self) -> Analysis { 110 pub fn analysis(&self) -> Analysis {
diff --git a/crates/ra_analysis/src/mock_analysis.rs b/crates/ra_analysis/src/mock_analysis.rs
index 76100f548..a7134a0e6 100644
--- a/crates/ra_analysis/src/mock_analysis.rs
+++ b/crates/ra_analysis/src/mock_analysis.rs
@@ -82,7 +82,7 @@ impl MockAnalysis {
82 FileId(idx as u32 + 1) 82 FileId(idx as u32 + 1)
83 } 83 }
84 pub fn analysis_host(self) -> AnalysisHost { 84 pub fn analysis_host(self) -> AnalysisHost {
85 let mut host = AnalysisHost::new(); 85 let mut host = AnalysisHost::default();
86 let mut file_map = Vec::new(); 86 let mut file_map = Vec::new();
87 let mut change = AnalysisChange::new(); 87 let mut change = AnalysisChange::new();
88 for (id, (path, contents)) in self.files.into_iter().enumerate() { 88 for (id, (path, contents)) in self.files.into_iter().enumerate() {