mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +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_syntax::{File, SyntaxNode};
|
||||
use salsa;
|
||||
use salsa::{self, Database};
|
||||
|
||||
use crate::{
|
||||
db,
|
||||
|
@ -15,7 +15,7 @@ use crate::{
|
|||
Cancelable, Canceled, FileId,
|
||||
};
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct 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<()> {
|
||||
if db.salsa_runtime().is_current_revision_canceled() {
|
||||
Err(Canceled)
|
||||
|
|
|
@ -86,22 +86,12 @@ impl Default for FileResolverImp {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct AnalysisHostImpl {
|
||||
db: db::RootDatabase,
|
||||
}
|
||||
|
||||
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 {
|
||||
AnalysisImpl {
|
||||
db: self.db.snapshot(),
|
||||
|
|
|
@ -99,17 +99,12 @@ impl AnalysisChange {
|
|||
}
|
||||
|
||||
/// `AnalysisHost` stores the current state of the world.
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Default)]
|
||||
pub struct AnalysisHost {
|
||||
imp: AnalysisHostImpl,
|
||||
}
|
||||
|
||||
impl AnalysisHost {
|
||||
pub fn new() -> AnalysisHost {
|
||||
AnalysisHost {
|
||||
imp: AnalysisHostImpl::new(),
|
||||
}
|
||||
}
|
||||
/// Returns a snapshot of the current state, which you can query for
|
||||
/// semantic information.
|
||||
pub fn analysis(&self) -> Analysis {
|
||||
|
|
|
@ -82,7 +82,7 @@ impl MockAnalysis {
|
|||
FileId(idx as u32 + 1)
|
||||
}
|
||||
pub fn analysis_host(self) -> AnalysisHost {
|
||||
let mut host = AnalysisHost::new();
|
||||
let mut host = AnalysisHost::default();
|
||||
let mut file_map = Vec::new();
|
||||
let mut change = AnalysisChange::new();
|
||||
for (id, (path, contents)) in self.files.into_iter().enumerate() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue