mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 09:27:27 +00:00
Use Default everywhere
This commit is contained in:
parent
cca5f862de
commit
f29b0172fb
7 changed files with 23 additions and 34 deletions
|
@ -2,7 +2,7 @@ use std::sync::Arc;
|
||||||
|
|
||||||
use ra_editor::LineIndex;
|
use ra_editor::LineIndex;
|
||||||
use ra_syntax::{File, SyntaxNode};
|
use ra_syntax::{File, SyntaxNode};
|
||||||
use salsa;
|
use salsa::{self, Database};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db,
|
db,
|
||||||
|
@ -15,7 +15,7 @@ use crate::{
|
||||||
Cancelable, Canceled, FileId,
|
Cancelable, Canceled, FileId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct RootDatabase {
|
pub(crate) struct RootDatabase {
|
||||||
runtime: salsa::Runtime<RootDatabase>,
|
runtime: salsa::Runtime<RootDatabase>,
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,21 @@ impl salsa::Database for RootDatabase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for RootDatabase {
|
||||||
|
fn default() -> RootDatabase {
|
||||||
|
let mut db = RootDatabase {
|
||||||
|
runtime: Default::default(),
|
||||||
|
};
|
||||||
|
db.query_mut(crate::input::SourceRootQuery)
|
||||||
|
.set(crate::input::WORKSPACE, Default::default());
|
||||||
|
db.query_mut(crate::input::CrateGraphQuery)
|
||||||
|
.set((), Default::default());
|
||||||
|
db.query_mut(crate::input::LibrariesQuery)
|
||||||
|
.set((), Default::default());
|
||||||
|
db
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn check_canceled(db: &impl salsa::Database) -> Cancelable<()> {
|
pub(crate) fn check_canceled(db: &impl salsa::Database) -> Cancelable<()> {
|
||||||
if db.salsa_runtime().is_current_revision_canceled() {
|
if db.salsa_runtime().is_current_revision_canceled() {
|
||||||
Err(Canceled)
|
Err(Canceled)
|
||||||
|
|
|
@ -86,22 +86,12 @@ impl Default for FileResolverImp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
pub(crate) struct AnalysisHostImpl {
|
pub(crate) struct AnalysisHostImpl {
|
||||||
db: db::RootDatabase,
|
db: db::RootDatabase,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AnalysisHostImpl {
|
impl AnalysisHostImpl {
|
||||||
pub fn new() -> AnalysisHostImpl {
|
|
||||||
let mut db = db::RootDatabase::default();
|
|
||||||
db.query_mut(crate::input::SourceRootQuery)
|
|
||||||
.set(WORKSPACE, Default::default());
|
|
||||||
db.query_mut(crate::input::CrateGraphQuery)
|
|
||||||
.set((), Default::default());
|
|
||||||
db.query_mut(crate::input::LibrariesQuery)
|
|
||||||
.set((), Default::default());
|
|
||||||
AnalysisHostImpl { db }
|
|
||||||
}
|
|
||||||
pub fn analysis(&self) -> AnalysisImpl {
|
pub fn analysis(&self) -> AnalysisImpl {
|
||||||
AnalysisImpl {
|
AnalysisImpl {
|
||||||
db: self.db.snapshot(),
|
db: self.db.snapshot(),
|
||||||
|
|
|
@ -99,17 +99,12 @@ impl AnalysisChange {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// `AnalysisHost` stores the current state of the world.
|
/// `AnalysisHost` stores the current state of the world.
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
pub struct AnalysisHost {
|
pub struct AnalysisHost {
|
||||||
imp: AnalysisHostImpl,
|
imp: AnalysisHostImpl,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AnalysisHost {
|
impl AnalysisHost {
|
||||||
pub fn new() -> AnalysisHost {
|
|
||||||
AnalysisHost {
|
|
||||||
imp: AnalysisHostImpl::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// Returns a snapshot of the current state, which you can query for
|
/// Returns a snapshot of the current state, which you can query for
|
||||||
/// semantic information.
|
/// semantic information.
|
||||||
pub fn analysis(&self) -> Analysis {
|
pub fn analysis(&self) -> Analysis {
|
||||||
|
|
|
@ -82,7 +82,7 @@ impl MockAnalysis {
|
||||||
FileId(idx as u32 + 1)
|
FileId(idx as u32 + 1)
|
||||||
}
|
}
|
||||||
pub fn analysis_host(self) -> AnalysisHost {
|
pub fn analysis_host(self) -> AnalysisHost {
|
||||||
let mut host = AnalysisHost::new();
|
let mut host = AnalysisHost::default();
|
||||||
let mut file_map = Vec::new();
|
let mut file_map = Vec::new();
|
||||||
let mut change = AnalysisChange::new();
|
let mut change = AnalysisChange::new();
|
||||||
for (id, (path, contents)) in self.files.into_iter().enumerate() {
|
for (id, (path, contents)) in self.files.into_iter().enumerate() {
|
||||||
|
|
|
@ -61,7 +61,7 @@ pub fn main_loop(
|
||||||
let (ws_worker, ws_watcher) = workspace_loader();
|
let (ws_worker, ws_watcher) = workspace_loader();
|
||||||
|
|
||||||
info!("server initialized, serving requests");
|
info!("server initialized, serving requests");
|
||||||
let mut state = ServerWorldState::new();
|
let mut state = ServerWorldState::default();
|
||||||
|
|
||||||
let mut pending_requests = FxHashSet::default();
|
let mut pending_requests = FxHashSet::default();
|
||||||
let mut subs = Subscriptions::new();
|
let mut subs = Subscriptions::new();
|
||||||
|
|
|
@ -28,9 +28,6 @@ impl fmt::Debug for PathMap {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PathMap {
|
impl PathMap {
|
||||||
pub fn new() -> PathMap {
|
|
||||||
Default::default()
|
|
||||||
}
|
|
||||||
pub fn get_or_insert(&mut self, path: PathBuf, root: Root) -> (bool, FileId) {
|
pub fn get_or_insert(&mut self, path: PathBuf, root: Root) -> (bool, FileId) {
|
||||||
let mut inserted = false;
|
let mut inserted = false;
|
||||||
let file_id = self
|
let file_id = self
|
||||||
|
@ -117,7 +114,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_resolve() {
|
fn test_resolve() {
|
||||||
let mut m = PathMap::new();
|
let mut m = PathMap::default();
|
||||||
let (_, id1) = m.get_or_insert(PathBuf::from("/foo"), Root::Workspace);
|
let (_, id1) = m.get_or_insert(PathBuf::from("/foo"), Root::Workspace);
|
||||||
let (_, id2) = m.get_or_insert(PathBuf::from("/foo/bar.rs"), Root::Workspace);
|
let (_, id2) = m.get_or_insert(PathBuf::from("/foo/bar.rs"), Root::Workspace);
|
||||||
assert_eq!(m.resolve(id1, &RelativePath::new("bar.rs")), Some(id2),)
|
assert_eq!(m.resolve(id1, &RelativePath::new("bar.rs")), Some(id2),)
|
||||||
|
|
|
@ -17,7 +17,7 @@ use crate::{
|
||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
pub struct ServerWorldState {
|
pub struct ServerWorldState {
|
||||||
pub workspaces: Arc<Vec<CargoWorkspace>>,
|
pub workspaces: Arc<Vec<CargoWorkspace>>,
|
||||||
pub analysis_host: AnalysisHost,
|
pub analysis_host: AnalysisHost,
|
||||||
|
@ -32,14 +32,6 @@ pub struct ServerWorld {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServerWorldState {
|
impl ServerWorldState {
|
||||||
pub fn new() -> ServerWorldState {
|
|
||||||
ServerWorldState {
|
|
||||||
workspaces: Arc::new(Vec::new()),
|
|
||||||
analysis_host: AnalysisHost::new(),
|
|
||||||
path_map: PathMap::new(),
|
|
||||||
mem_map: FxHashMap::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn apply_fs_changes(&mut self, events: Vec<FileEvent>) {
|
pub fn apply_fs_changes(&mut self, events: Vec<FileEvent>) {
|
||||||
let mut change = AnalysisChange::new();
|
let mut change = AnalysisChange::new();
|
||||||
let mut inserted = false;
|
let mut inserted = false;
|
||||||
|
|
Loading…
Reference in a new issue