diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-04 11:09:57 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-11-04 11:09:57 +0000 |
commit | 19c6cbd9540ef87850161cad7e108b380eceea24 (patch) | |
tree | 4ec1f709d283d3ea0b7c225a70f6439d67a5ca32 /crates | |
parent | cca5f862de8a4eb4a8990fdca95a4a7686937789 (diff) | |
parent | f29b0172fbcbc88160980c2e7359f92d7c0d885d (diff) |
Merge #187
187: Use Default everywhere r=matklad a=matklad
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_analysis/src/db.rs | 19 | ||||
-rw-r--r-- | crates/ra_analysis/src/imp.rs | 12 | ||||
-rw-r--r-- | crates/ra_analysis/src/lib.rs | 7 | ||||
-rw-r--r-- | crates/ra_analysis/src/mock_analysis.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/main_loop/mod.rs | 2 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/path_map.rs | 5 | ||||
-rw-r--r-- | crates/ra_lsp_server/src/server_world.rs | 10 |
7 files changed, 23 insertions, 34 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 | ||
3 | use ra_editor::LineIndex; | 3 | use ra_editor::LineIndex; |
4 | use ra_syntax::{File, SyntaxNode}; | 4 | use ra_syntax::{File, SyntaxNode}; |
5 | use salsa; | 5 | use salsa::{self, Database}; |
6 | 6 | ||
7 | use crate::{ | 7 | use 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)] |
19 | pub(crate) struct RootDatabase { | 19 | pub(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 | ||
29 | impl 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 | |||
29 | pub(crate) fn check_canceled(db: &impl salsa::Database) -> Cancelable<()> { | 44 | pub(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)] |
90 | pub(crate) struct AnalysisHostImpl { | 90 | pub(crate) struct AnalysisHostImpl { |
91 | db: db::RootDatabase, | 91 | db: db::RootDatabase, |
92 | } | 92 | } |
93 | 93 | ||
94 | impl AnalysisHostImpl { | 94 | impl 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)] |
103 | pub struct AnalysisHost { | 103 | pub struct AnalysisHost { |
104 | imp: AnalysisHostImpl, | 104 | imp: AnalysisHostImpl, |
105 | } | 105 | } |
106 | 106 | ||
107 | impl AnalysisHost { | 107 | impl 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() { |
diff --git a/crates/ra_lsp_server/src/main_loop/mod.rs b/crates/ra_lsp_server/src/main_loop/mod.rs index c568706bd..1eb147539 100644 --- a/crates/ra_lsp_server/src/main_loop/mod.rs +++ b/crates/ra_lsp_server/src/main_loop/mod.rs | |||
@@ -61,7 +61,7 @@ pub fn main_loop( | |||
61 | let (ws_worker, ws_watcher) = workspace_loader(); | 61 | let (ws_worker, ws_watcher) = workspace_loader(); |
62 | 62 | ||
63 | info!("server initialized, serving requests"); | 63 | info!("server initialized, serving requests"); |
64 | let mut state = ServerWorldState::new(); | 64 | let mut state = ServerWorldState::default(); |
65 | 65 | ||
66 | let mut pending_requests = FxHashSet::default(); | 66 | let mut pending_requests = FxHashSet::default(); |
67 | let mut subs = Subscriptions::new(); | 67 | let mut subs = Subscriptions::new(); |
diff --git a/crates/ra_lsp_server/src/path_map.rs b/crates/ra_lsp_server/src/path_map.rs index dd09fa10a..87eabf9be 100644 --- a/crates/ra_lsp_server/src/path_map.rs +++ b/crates/ra_lsp_server/src/path_map.rs | |||
@@ -28,9 +28,6 @@ impl fmt::Debug for PathMap { | |||
28 | } | 28 | } |
29 | 29 | ||
30 | impl PathMap { | 30 | impl PathMap { |
31 | pub fn new() -> PathMap { | ||
32 | Default::default() | ||
33 | } | ||
34 | pub fn get_or_insert(&mut self, path: PathBuf, root: Root) -> (bool, FileId) { | 31 | pub fn get_or_insert(&mut self, path: PathBuf, root: Root) -> (bool, FileId) { |
35 | let mut inserted = false; | 32 | let mut inserted = false; |
36 | let file_id = self | 33 | let file_id = self |
@@ -117,7 +114,7 @@ mod test { | |||
117 | 114 | ||
118 | #[test] | 115 | #[test] |
119 | fn test_resolve() { | 116 | fn test_resolve() { |
120 | let mut m = PathMap::new(); | 117 | let mut m = PathMap::default(); |
121 | let (_, id1) = m.get_or_insert(PathBuf::from("/foo"), Root::Workspace); | 118 | let (_, id1) = m.get_or_insert(PathBuf::from("/foo"), Root::Workspace); |
122 | let (_, id2) = m.get_or_insert(PathBuf::from("/foo/bar.rs"), Root::Workspace); | 119 | let (_, id2) = m.get_or_insert(PathBuf::from("/foo/bar.rs"), Root::Workspace); |
123 | assert_eq!(m.resolve(id1, &RelativePath::new("bar.rs")), Some(id2),) | 120 | assert_eq!(m.resolve(id1, &RelativePath::new("bar.rs")), Some(id2),) |
diff --git a/crates/ra_lsp_server/src/server_world.rs b/crates/ra_lsp_server/src/server_world.rs index 3e76d2527..3e7670fcc 100644 --- a/crates/ra_lsp_server/src/server_world.rs +++ b/crates/ra_lsp_server/src/server_world.rs | |||
@@ -17,7 +17,7 @@ use crate::{ | |||
17 | Result, | 17 | Result, |
18 | }; | 18 | }; |
19 | 19 | ||
20 | #[derive(Debug)] | 20 | #[derive(Debug, Default)] |
21 | pub struct ServerWorldState { | 21 | pub struct ServerWorldState { |
22 | pub workspaces: Arc<Vec<CargoWorkspace>>, | 22 | pub workspaces: Arc<Vec<CargoWorkspace>>, |
23 | pub analysis_host: AnalysisHost, | 23 | pub analysis_host: AnalysisHost, |
@@ -32,14 +32,6 @@ pub struct ServerWorld { | |||
32 | } | 32 | } |
33 | 33 | ||
34 | impl ServerWorldState { | 34 | impl ServerWorldState { |
35 | pub fn new() -> ServerWorldState { | ||
36 | ServerWorldState { | ||
37 | workspaces: Arc::new(Vec::new()), | ||
38 | analysis_host: AnalysisHost::new(), | ||
39 | path_map: PathMap::new(), | ||
40 | mem_map: FxHashMap::default(), | ||
41 | } | ||
42 | } | ||
43 | pub fn apply_fs_changes(&mut self, events: Vec<FileEvent>) { | 35 | pub fn apply_fs_changes(&mut self, events: Vec<FileEvent>) { |
44 | let mut change = AnalysisChange::new(); | 36 | let mut change = AnalysisChange::new(); |
45 | let mut inserted = false; | 37 | let mut inserted = false; |