rename source_file -> parse

This commit is contained in:
Aleksey Kladov 2019-01-26 11:51:36 +03:00
parent ac757e114e
commit 9457b1f0e6
19 changed files with 41 additions and 47 deletions

View file

@ -10,7 +10,7 @@ use crate::{FilePosition, CallInfo, db::RootDatabase};
/// Computes parameter information for the given call expression.
pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<CallInfo> {
let file = db.source_file(position.file_id);
let file = db.parse(position.file_id);
let syntax = file.syntax();
// Find the calling expression and it's NameRef
@ -22,7 +22,7 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
let symbol = file_symbols
.into_iter()
.find(|it| it.ptr.kind() == FN_DEF)?;
let fn_file = db.source_file(symbol.file_id);
let fn_file = db.parse(symbol.file_id);
let fn_def = symbol.ptr.to_node(&fn_file);
let fn_def = ast::FnDef::cast(fn_def).unwrap();
let mut call_info = CallInfo::new(fn_def)?;

View file

@ -45,7 +45,7 @@ pub use crate::completion::completion_item::{CompletionItem, CompletionItemKind,
/// identifier prefix/fuzzy match should be done higher in the stack, together
/// with ordering of completions (currently this is done by the client).
pub(crate) fn completions(db: &db::RootDatabase, position: FilePosition) -> Option<Completions> {
let original_file = db.source_file(position.file_id);
let original_file = db.parse(position.file_id);
let ctx = CompletionContext::new(db, &original_file, position)?;
let mut acc = Completions::default();

View file

@ -10,7 +10,7 @@ use crate::{
};
pub(crate) fn extend_selection(db: &RootDatabase, frange: FileRange) -> TextRange {
let source_file = db.source_file(frange.file_id);
let source_file = db.parse(frange.file_id);
if let Some(range) = extend_selection_in_macro(db, &source_file, frange) {
return range;
}

View file

@ -11,7 +11,7 @@ pub(crate) fn goto_definition(
db: &RootDatabase,
position: FilePosition,
) -> Option<RangeInfo<Vec<NavigationTarget>>> {
let file = db.source_file(position.file_id);
let file = db.parse(position.file_id);
let syntax = file.syntax();
if let Some(name_ref) = find_node_at_offset::<ast::NameRef>(syntax, position.offset) {
let navs = reference_definition(db, position.file_id, name_ref).to_vec();

View file

@ -7,7 +7,7 @@ use ra_syntax::{
use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget};
pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeInfo<String>> {
let file = db.source_file(position.file_id);
let file = db.parse(position.file_id);
let mut res = Vec::new();
let mut range = None;
@ -53,7 +53,7 @@ pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option<RangeIn
}
pub(crate) fn type_of(db: &RootDatabase, frange: FileRange) -> Option<String> {
let file = db.source_file(frange.file_id);
let file = db.parse(frange.file_id);
let syntax = file.syntax();
let leaf_node = find_covering_node(syntax, frange.range);
// if we picked identifier, expand to pattern/expression
@ -88,7 +88,7 @@ fn doc_text_for(db: &RootDatabase, nav: NavigationTarget) -> Option<String> {
impl NavigationTarget {
fn node(&self, db: &RootDatabase) -> Option<TreeArc<SyntaxNode>> {
let source_file = db.source_file(self.file_id());
let source_file = db.parse(self.file_id());
let source_file = source_file.syntax();
let node = source_file
.descendants()

View file

@ -76,9 +76,9 @@ impl db::RootDatabase {
/// syntax trees. However, if we actually do that, everything is recomputed
/// for some reason. Needs investigation.
pub(crate) fn collect_garbage(&mut self) {
self.query(ra_db::SourceFileQuery)
self.query(ra_db::ParseQuery)
.sweep(SweepStrategy::default().discard_values());
self.query(hir::db::HirSourceFileQuery)
self.query(hir::db::HirParseQuery)
.sweep(SweepStrategy::default().discard_values());
self.query(hir::db::FileItemsQuery)
.sweep(SweepStrategy::default().discard_values());
@ -102,7 +102,7 @@ impl db::RootDatabase {
}
pub(crate) fn find_all_refs(&self, position: FilePosition) -> Vec<(FileId, TextRange)> {
let file = self.source_file(position.file_id);
let file = self.parse(position.file_id);
// Find the binding associated with the offset
let (binding, descr) = match find_binding(self, &file, position) {
None => return Vec::new(),
@ -150,7 +150,7 @@ impl db::RootDatabase {
}
pub(crate) fn diagnostics(&self, file_id: FileId) -> Vec<Diagnostic> {
let syntax = self.source_file(file_id);
let syntax = self.parse(file_id);
let mut res = ra_ide_api_light::diagnostics(&syntax)
.into_iter()
@ -214,7 +214,7 @@ impl db::RootDatabase {
}
pub(crate) fn assists(&self, frange: FileRange) -> Vec<SourceChange> {
let file = self.source_file(frange.file_id);
let file = self.parse(frange.file_id);
assists::assists(&file, frange.range)
.into_iter()
.map(|local_edit| SourceChange::from_local_edit(frange.file_id, local_edit))

View file

@ -313,7 +313,7 @@ impl Analysis {
/// Gets the syntax tree of the file.
pub fn parse(&self, file_id: FileId) -> TreeArc<SourceFile> {
self.db.source_file(file_id).clone()
self.db.parse(file_id).clone()
}
/// Gets the file's `LineIndex`: data structure to convert between absolute
@ -330,21 +330,21 @@ impl Analysis {
/// Returns position of the mathcing brace (all types of braces are
/// supported).
pub fn matching_brace(&self, position: FilePosition) -> Option<TextUnit> {
let file = self.db.source_file(position.file_id);
let file = self.db.parse(position.file_id);
ra_ide_api_light::matching_brace(&file, position.offset)
}
/// Returns a syntax tree represented as `String`, for debug purposes.
// FIXME: use a better name here.
pub fn syntax_tree(&self, file_id: FileId) -> String {
let file = self.db.source_file(file_id);
let file = self.db.parse(file_id);
ra_ide_api_light::syntax_tree(&file)
}
/// Returns an edit to remove all newlines in the range, cleaning up minor
/// stuff like trailing commas.
pub fn join_lines(&self, frange: FileRange) -> SourceChange {
let file = self.db.source_file(frange.file_id);
let file = self.db.parse(frange.file_id);
SourceChange::from_local_edit(
frange.file_id,
ra_ide_api_light::join_lines(&file, frange.range),
@ -354,7 +354,7 @@ impl Analysis {
/// Returns an edit which should be applied when opening a new line, fixing
/// up minor stuff like continuing the comment.
pub fn on_enter(&self, position: FilePosition) -> Option<SourceChange> {
let file = self.db.source_file(position.file_id);
let file = self.db.parse(position.file_id);
let edit = ra_ide_api_light::on_enter(&file, position.offset)?;
Some(SourceChange::from_local_edit(position.file_id, edit))
}
@ -363,14 +363,14 @@ impl Analysis {
/// this works when adding `let =`.
// FIXME: use a snippet completion instead of this hack here.
pub fn on_eq_typed(&self, position: FilePosition) -> Option<SourceChange> {
let file = self.db.source_file(position.file_id);
let file = self.db.parse(position.file_id);
let edit = ra_ide_api_light::on_eq_typed(&file, position.offset)?;
Some(SourceChange::from_local_edit(position.file_id, edit))
}
/// Returns an edit which should be applied when a dot ('.') is typed on a blank line, indenting the line appropriately.
pub fn on_dot_typed(&self, position: FilePosition) -> Option<SourceChange> {
let file = self.db.source_file(position.file_id);
let file = self.db.parse(position.file_id);
let edit = ra_ide_api_light::on_dot_typed(&file, position.offset)?;
Some(SourceChange::from_local_edit(position.file_id, edit))
}
@ -378,13 +378,13 @@ impl Analysis {
/// Returns a tree representation of symbols in the file. Useful to draw a
/// file outline.
pub fn file_structure(&self, file_id: FileId) -> Vec<StructureNode> {
let file = self.db.source_file(file_id);
let file = self.db.parse(file_id);
ra_ide_api_light::file_structure(&file)
}
/// Returns the set of folding ranges.
pub fn folding_ranges(&self, file_id: FileId) -> Vec<Fold> {
let file = self.db.source_file(file_id);
let file = self.db.parse(file_id);
ra_ide_api_light::folding_ranges(&file)
}

View file

@ -25,7 +25,7 @@ pub(crate) fn rename(
position: FilePosition,
new_name: &str,
) -> Option<SourceChange> {
let source_file = db.source_file(position.file_id);
let source_file = db.parse(position.file_id);
let syntax = source_file.syntax();
if let Some((ast_name, ast_module)) = find_name_and_module_at_offset(syntax, position) {

View file

@ -22,7 +22,7 @@ pub enum RunnableKind {
}
pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec<Runnable> {
let source_file = db.source_file(file_id);
let source_file = db.parse(file_id);
source_file
.syntax()
.descendants()

View file

@ -6,7 +6,7 @@ use std::{
use ra_syntax::{AstNode, TreeArc, SourceFile};
use ra_db::{
SourceFileQuery, FileTextQuery, SourceRootId,
ParseQuery, FileTextQuery, SourceRootId,
salsa::{Database, debug::{DebugQueryTable, TableEntry}},
};
@ -17,7 +17,7 @@ use crate::{
pub(crate) fn status(db: &RootDatabase) -> String {
let files_stats = db.query(FileTextQuery).entries::<FilesStats>();
let syntax_tree_stats = db.query(SourceFileQuery).entries::<SyntaxTreeStats>();
let syntax_tree_stats = db.query(ParseQuery).entries::<SyntaxTreeStats>();
let symbols_stats = db
.query(LibrarySymbolsQuery)
.entries::<LibrarySymbolsStats>();

View file

@ -61,7 +61,7 @@ pub(crate) trait SymbolsDatabase: hir::db::HirDatabase {
fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc<SymbolIndex> {
db.check_canceled();
let source_file = db.source_file(file_id);
let source_file = db.parse(file_id);
let mut symbols = source_file
.syntax()
.descendants()

View file

@ -7,7 +7,7 @@ use crate::{
};
pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec<HighlightedRange> {
let source_file = db.source_file(file_id);
let source_file = db.parse(file_id);
let mut res = ra_ide_api_light::highlight(source_file.syntax());
for macro_call in source_file
.syntax()