rename file_syntax -> source_file

This commit is contained in:
Aleksey Kladov 2018-11-28 02:25:03 +03:00
parent 65c064b2a9
commit ec45dfea1e
6 changed files with 18 additions and 18 deletions

View file

@ -29,7 +29,7 @@ pub(crate) fn completions(
db: &db::RootDatabase, db: &db::RootDatabase,
position: FilePosition, position: FilePosition,
) -> Cancelable<Option<Vec<CompletionItem>>> { ) -> Cancelable<Option<Vec<CompletionItem>>> {
let original_file = db.file_syntax(position.file_id); let original_file = db.source_file(position.file_id);
// Insert a fake ident to get a valid parse tree // Insert a fake ident to get a valid parse tree
let file = { let file = {
let edit = AtomEdit::insert(position.offset, "intellijRulezz".to_string()); let edit = AtomEdit::insert(position.offset, "intellijRulezz".to_string());

View file

@ -117,7 +117,7 @@ salsa::database_storage! {
fn crate_graph() for crate::input::CrateGraphQuery; fn crate_graph() for crate::input::CrateGraphQuery;
} }
impl SyntaxDatabase { impl SyntaxDatabase {
fn file_syntax() for FileSyntaxQuery; fn source_file() for SourceFileQuery;
fn file_lines() for FileLinesQuery; fn file_lines() for FileLinesQuery;
} }
impl symbol_index::SymbolsDatabase { impl symbol_index::SymbolsDatabase {
@ -139,8 +139,8 @@ salsa::database_storage! {
salsa::query_group! { salsa::query_group! {
pub(crate) trait SyntaxDatabase: crate::input::FilesDatabase + BaseDatabase { pub(crate) trait SyntaxDatabase: crate::input::FilesDatabase + BaseDatabase {
fn file_syntax(file_id: FileId) -> SourceFileNode { fn source_file(file_id: FileId) -> SourceFileNode {
type FileSyntaxQuery; type SourceFileQuery;
} }
fn file_lines(file_id: FileId) -> Arc<LineIndex> { fn file_lines(file_id: FileId) -> Arc<LineIndex> {
type FileLinesQuery; type FileLinesQuery;
@ -148,7 +148,7 @@ salsa::query_group! {
} }
} }
fn file_syntax(db: &impl SyntaxDatabase, file_id: FileId) -> SourceFileNode { fn source_file(db: &impl SyntaxDatabase, file_id: FileId) -> SourceFileNode {
let text = db.file_text(file_id); let text = db.file_text(file_id);
SourceFileNode::parse(&*text) SourceFileNode::parse(&*text)
} }

View file

@ -49,7 +49,7 @@ impl Module {
db: &impl HirDatabase, db: &impl HirDatabase,
position: FilePosition, position: FilePosition,
) -> Cancelable<Option<Module>> { ) -> Cancelable<Option<Module>> {
let file = db.file_syntax(position.file_id); let file = db.source_file(position.file_id);
let module_source = match find_node_at_offset::<ast::Module>(file.syntax(), position.offset) let module_source = match find_node_at_offset::<ast::Module>(file.syntax(), position.offset)
{ {
Some(m) if !m.has_semi() => ModuleSource::new_inline(db, position.file_id, m), Some(m) if !m.has_semi() => ModuleSource::new_inline(db, position.file_id, m),
@ -346,7 +346,7 @@ impl ModuleSource {
pub(crate) fn resolve(self, db: &impl HirDatabase) -> ModuleSourceNode { pub(crate) fn resolve(self, db: &impl HirDatabase) -> ModuleSourceNode {
match self { match self {
ModuleSource::SourceFile(file_id) => { ModuleSource::SourceFile(file_id) => {
let syntax = db.file_syntax(file_id); let syntax = db.source_file(file_id);
ModuleSourceNode::SourceFile(syntax.ast().owned()) ModuleSourceNode::SourceFile(syntax.ast().owned())
} }
ModuleSource::Module(item_id) => { ModuleSource::Module(item_id) => {

View file

@ -38,7 +38,7 @@ pub(super) fn fn_scopes(db: &impl HirDatabase, fn_id: FnId) -> Arc<FnScopes> {
} }
pub(super) fn file_items(db: &impl HirDatabase, file_id: FileId) -> Arc<SourceFileItems> { pub(super) fn file_items(db: &impl HirDatabase, file_id: FileId) -> Arc<SourceFileItems> {
let source_file = db.file_syntax(file_id); let source_file = db.source_file(file_id);
let source_file = source_file.borrowed(); let source_file = source_file.borrowed();
let mut res = SourceFileItems::default(); let mut res = SourceFileItems::default();
source_file source_file

View file

@ -18,7 +18,7 @@ use salsa::{Database, ParallelDatabase};
use crate::{ use crate::{
completion::{completions, CompletionItem}, completion::{completions, CompletionItem},
db::{self, FileSyntaxQuery, SyntaxDatabase}, db::{self, SourceFileQuery, SyntaxDatabase},
hir::{ hir::{
self, self,
FnSignatureInfo, FnSignatureInfo,
@ -189,7 +189,7 @@ impl fmt::Debug for AnalysisImpl {
impl AnalysisImpl { impl AnalysisImpl {
pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode { pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode {
self.db.file_syntax(file_id) self.db.source_file(file_id)
} }
pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> { pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
self.db.file_lines(file_id) self.db.file_lines(file_id)
@ -220,7 +220,7 @@ impl AnalysisImpl {
.collect() .collect()
}; };
self.db self.db
.query(FileSyntaxQuery) .query(SourceFileQuery)
.sweep(salsa::SweepStrategy::default().discard_values()); .sweep(salsa::SweepStrategy::default().discard_values());
Ok(query.search(&buf)) Ok(query.search(&buf))
} }
@ -270,7 +270,7 @@ impl AnalysisImpl {
&self, &self,
position: FilePosition, position: FilePosition,
) -> Cancelable<Vec<(FileId, FileSymbol)>> { ) -> Cancelable<Vec<(FileId, FileSymbol)>> {
let file = self.db.file_syntax(position.file_id); let file = self.db.source_file(position.file_id);
let syntax = file.syntax(); let syntax = file.syntax();
if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) { if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) {
if let Some(fn_descr) = if let Some(fn_descr) =
@ -322,7 +322,7 @@ impl AnalysisImpl {
} }
pub fn find_all_refs(&self, position: FilePosition) -> Vec<(FileId, TextRange)> { pub fn find_all_refs(&self, position: FilePosition) -> Vec<(FileId, TextRange)> {
let file = self.db.file_syntax(position.file_id); let file = self.db.source_file(position.file_id);
// Find the binding associated with the offset // Find the binding associated with the offset
let (binding, descr) = match find_binding(&self.db, &file, position) { let (binding, descr) = match find_binding(&self.db, &file, position) {
None => return Vec::new(), None => return Vec::new(),
@ -365,13 +365,13 @@ impl AnalysisImpl {
file_id: FileId, file_id: FileId,
symbol: FileSymbol, symbol: FileSymbol,
) -> Cancelable<Option<String>> { ) -> Cancelable<Option<String>> {
let file = self.db.file_syntax(file_id); let file = self.db.source_file(file_id);
Ok(symbol.docs(&file)) Ok(symbol.docs(&file))
} }
pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> { pub fn diagnostics(&self, file_id: FileId) -> Cancelable<Vec<Diagnostic>> {
let syntax = self.db.file_syntax(file_id); let syntax = self.db.source_file(file_id);
let mut res = ra_editor::diagnostics(&syntax) let mut res = ra_editor::diagnostics(&syntax)
.into_iter() .into_iter()
@ -459,7 +459,7 @@ impl AnalysisImpl {
&self, &self,
position: FilePosition, position: FilePosition,
) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> { ) -> Cancelable<Option<(FnSignatureInfo, Option<usize>)>> {
let file = self.db.file_syntax(position.file_id); let file = self.db.source_file(position.file_id);
let syntax = file.syntax(); let syntax = file.syntax();
// Find the calling expression and it's NameRef // Find the calling expression and it's NameRef
@ -470,7 +470,7 @@ impl AnalysisImpl {
let file_symbols = self.index_resolve(name_ref)?; let file_symbols = self.index_resolve(name_ref)?;
for (fn_file_id, fs) in file_symbols { for (fn_file_id, fs) in file_symbols {
if fs.kind == FN_DEF { if fs.kind == FN_DEF {
let fn_file = self.db.file_syntax(fn_file_id); let fn_file = self.db.source_file(fn_file_id);
if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) { if let Some(fn_def) = find_node_at_offset(fn_file.syntax(), fs.node_range.start()) {
let descr = hir::Function::guess_from_source(&*self.db, fn_file_id, fn_def); let descr = hir::Function::guess_from_source(&*self.db, fn_file_id, fn_def);
if let Some(descriptor) = descr.signature_info(&*self.db) { if let Some(descriptor) = descr.signature_info(&*self.db) {

View file

@ -32,7 +32,7 @@ salsa::query_group! {
fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> { fn file_symbols(db: &impl SyntaxDatabase, file_id: FileId) -> Cancelable<Arc<SymbolIndex>> {
db.check_canceled()?; db.check_canceled()?;
let syntax = db.file_syntax(file_id); let syntax = db.source_file(file_id);
Ok(Arc::new(SymbolIndex::for_file(file_id, syntax))) Ok(Arc::new(SymbolIndex::for_file(file_id, syntax)))
} }