Skip to content

Commit 19c6cbd

Browse files
bors[bot]matklad
andcommitted
Merge #187
187: Use Default everywhere r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
2 parents cca5f86 + f29b017 commit 19c6cbd

File tree

7 files changed

+23
-34
lines changed

7 files changed

+23
-34
lines changed

crates/ra_analysis/src/db.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::sync::Arc;
22

33
use ra_editor::LineIndex;
44
use ra_syntax::{File, SyntaxNode};
5-
use salsa;
5+
use salsa::{self, Database};
66

77
use crate::{
88
db,
@@ -15,7 +15,7 @@ use crate::{
1515
Cancelable, Canceled, FileId,
1616
};
1717

18-
#[derive(Default, Debug)]
18+
#[derive(Debug)]
1919
pub(crate) struct RootDatabase {
2020
runtime: salsa::Runtime<RootDatabase>,
2121
}
@@ -26,6 +26,21 @@ impl salsa::Database for RootDatabase {
2626
}
2727
}
2828

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+
2944
pub(crate) fn check_canceled(db: &impl salsa::Database) -> Cancelable<()> {
3045
if db.salsa_runtime().is_current_revision_canceled() {
3146
Err(Canceled)

crates/ra_analysis/src/imp.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,12 @@ impl Default for FileResolverImp {
8686
}
8787
}
8888

89-
#[derive(Debug)]
89+
#[derive(Debug, Default)]
9090
pub(crate) struct AnalysisHostImpl {
9191
db: db::RootDatabase,
9292
}
9393

9494
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-
}
10595
pub fn analysis(&self) -> AnalysisImpl {
10696
AnalysisImpl {
10797
db: self.db.snapshot(),

crates/ra_analysis/src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,12 @@ impl AnalysisChange {
9999
}
100100

101101
/// `AnalysisHost` stores the current state of the world.
102-
#[derive(Debug)]
102+
#[derive(Debug, Default)]
103103
pub struct AnalysisHost {
104104
imp: AnalysisHostImpl,
105105
}
106106

107107
impl AnalysisHost {
108-
pub fn new() -> AnalysisHost {
109-
AnalysisHost {
110-
imp: AnalysisHostImpl::new(),
111-
}
112-
}
113108
/// Returns a snapshot of the current state, which you can query for
114109
/// semantic information.
115110
pub fn analysis(&self) -> Analysis {

crates/ra_analysis/src/mock_analysis.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl MockAnalysis {
8282
FileId(idx as u32 + 1)
8383
}
8484
pub fn analysis_host(self) -> AnalysisHost {
85-
let mut host = AnalysisHost::new();
85+
let mut host = AnalysisHost::default();
8686
let mut file_map = Vec::new();
8787
let mut change = AnalysisChange::new();
8888
for (id, (path, contents)) in self.files.into_iter().enumerate() {

crates/ra_lsp_server/src/main_loop/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn main_loop(
6161
let (ws_worker, ws_watcher) = workspace_loader();
6262

6363
info!("server initialized, serving requests");
64-
let mut state = ServerWorldState::new();
64+
let mut state = ServerWorldState::default();
6565

6666
let mut pending_requests = FxHashSet::default();
6767
let mut subs = Subscriptions::new();

crates/ra_lsp_server/src/path_map.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ impl fmt::Debug for PathMap {
2828
}
2929

3030
impl PathMap {
31-
pub fn new() -> PathMap {
32-
Default::default()
33-
}
3431
pub fn get_or_insert(&mut self, path: PathBuf, root: Root) -> (bool, FileId) {
3532
let mut inserted = false;
3633
let file_id = self
@@ -117,7 +114,7 @@ mod test {
117114

118115
#[test]
119116
fn test_resolve() {
120-
let mut m = PathMap::new();
117+
let mut m = PathMap::default();
121118
let (_, id1) = m.get_or_insert(PathBuf::from("/foo"), Root::Workspace);
122119
let (_, id2) = m.get_or_insert(PathBuf::from("/foo/bar.rs"), Root::Workspace);
123120
assert_eq!(m.resolve(id1, &RelativePath::new("bar.rs")), Some(id2),)

crates/ra_lsp_server/src/server_world.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::{
1717
Result,
1818
};
1919

20-
#[derive(Debug)]
20+
#[derive(Debug, Default)]
2121
pub struct ServerWorldState {
2222
pub workspaces: Arc<Vec<CargoWorkspace>>,
2323
pub analysis_host: AnalysisHost,
@@ -32,14 +32,6 @@ pub struct ServerWorld {
3232
}
3333

3434
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-
}
4335
pub fn apply_fs_changes(&mut self, events: Vec<FileEvent>) {
4436
let mut change = AnalysisChange::new();
4537
let mut inserted = false;

0 commit comments

Comments
 (0)