From 9457b1f0e64d38e7dc24d8c66a52ffef759d4dbf Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 26 Jan 2019 11:51:36 +0300 Subject: rename source_file -> parse --- crates/ra_db/src/lib.rs | 4 ++-- crates/ra_hir/src/db.rs | 4 ++-- crates/ra_hir/src/ids.rs | 9 +++------ crates/ra_hir/src/nameres/lower.rs | 2 +- crates/ra_hir/src/query_definitions.rs | 7 ++----- crates/ra_hir/src/source_binder.rs | 4 ++-- crates/ra_hir/src/ty/tests.rs | 2 +- crates/ra_ide_api/src/call_info.rs | 4 ++-- crates/ra_ide_api/src/completion.rs | 2 +- crates/ra_ide_api/src/extend_selection.rs | 2 +- crates/ra_ide_api/src/goto_definition.rs | 2 +- crates/ra_ide_api/src/hover.rs | 6 +++--- crates/ra_ide_api/src/imp.rs | 10 +++++----- crates/ra_ide_api/src/lib.rs | 18 +++++++++--------- crates/ra_ide_api/src/rename.rs | 2 +- crates/ra_ide_api/src/runnables.rs | 2 +- crates/ra_ide_api/src/status.rs | 4 ++-- crates/ra_ide_api/src/symbol_index.rs | 2 +- crates/ra_ide_api/src/syntax_highlighting.rs | 2 +- 19 files changed, 41 insertions(+), 47 deletions(-) diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 2664dc69a..6e17f33f0 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs @@ -71,7 +71,7 @@ pub trait SourceDatabase: salsa::Database + CheckCanceled { #[salsa::input] fn file_text(&self, file_id: FileId) -> Arc; // Parses the file into the syntax tree. - fn source_file(&self, file_id: FileId) -> TreeArc; + fn parse(&self, file_id: FileId) -> TreeArc; /// Path to a file, relative to the root of its source root. #[salsa::input] fn file_relative_path(&self, file_id: FileId) -> RelativePathBuf; @@ -98,7 +98,7 @@ fn source_root_crates(db: &impl SourceDatabase, id: SourceRootId) -> Arc TreeArc { +fn parse(db: &impl SourceDatabase, file_id: FileId) -> TreeArc { let text = db.file_text(file_id); SourceFile::parse(&*text) } diff --git a/crates/ra_hir/src/db.rs b/crates/ra_hir/src/db.rs index 9b5b79d38..5df4bd4a1 100644 --- a/crates/ra_hir/src/db.rs +++ b/crates/ra_hir/src/db.rs @@ -20,8 +20,8 @@ use crate::{ #[salsa::query_group(HirDatabaseStorage)] pub trait HirDatabase: SourceDatabase + AsRef { - #[salsa::invoke(HirFileId::hir_source_file)] - fn hir_source_file(&self, file_id: HirFileId) -> TreeArc; + #[salsa::invoke(HirFileId::hir_parse)] + fn hir_parse(&self, file_id: HirFileId) -> TreeArc; #[salsa::invoke(crate::macros::expand_macro_invocation)] fn expand_macro_invocation(&self, invoc: MacroCallId) -> Option>; diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 5272656ec..7dd4b540e 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs @@ -86,12 +86,9 @@ impl HirFileId { } } - pub(crate) fn hir_source_file( - db: &impl HirDatabase, - file_id: HirFileId, - ) -> TreeArc { + pub(crate) fn hir_parse(db: &impl HirDatabase, file_id: HirFileId) -> TreeArc { match file_id.0 { - HirFileIdRepr::File(file_id) => db.source_file(file_id), + HirFileIdRepr::File(file_id) => db.parse(file_id), HirFileIdRepr::Macro(m) => { if let Some(exp) = db.expand_macro_invocation(m) { return exp.file(); @@ -370,7 +367,7 @@ impl SourceFileItems { self.arena.iter().map(|(_id, i)| i).collect::>(), ); } - pub fn id_of_source_file(&self) -> SourceFileItemId { + pub fn id_of_parse(&self) -> SourceFileItemId { let (id, _syntax) = self.arena.iter().next().unwrap(); id } diff --git a/crates/ra_hir/src/nameres/lower.rs b/crates/ra_hir/src/nameres/lower.rs index b4fe99ea7..1d77548f3 100644 --- a/crates/ra_hir/src/nameres/lower.rs +++ b/crates/ra_hir/src/nameres/lower.rs @@ -129,7 +129,7 @@ impl LoweredModule { let id = loc.id(db); let file_id = HirFileId::from(id); //FIXME: expand recursively - for item in db.hir_source_file(file_id).items() { + for item in db.hir_parse(file_id).items() { self.add_def_id(source_map, db, module, file_id, item); } } diff --git a/crates/ra_hir/src/query_definitions.rs b/crates/ra_hir/src/query_definitions.rs index cf8c7e435..61c93a964 100644 --- a/crates/ra_hir/src/query_definitions.rs +++ b/crates/ra_hir/src/query_definitions.rs @@ -23,7 +23,7 @@ pub(super) fn fn_scopes(db: &impl HirDatabase, func: Function) -> Arc } pub(super) fn file_items(db: &impl HirDatabase, file_id: HirFileId) -> Arc { - let source_file = db.hir_source_file(file_id); + let source_file = db.hir_parse(file_id); let res = SourceFileItems::new(file_id, &source_file); Arc::new(res) } @@ -34,10 +34,7 @@ pub(super) fn file_item( ) -> TreeArc { match source_item_id.item_id { Some(id) => db.file_items(source_item_id.file_id)[id].to_owned(), - None => db - .hir_source_file(source_item_id.file_id) - .syntax() - .to_owned(), + None => db.hir_parse(source_item_id.file_id).syntax().to_owned(), } } diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index dbe040805..c0b3f1cd4 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -43,7 +43,7 @@ pub fn module_from_declaration( /// Locates the module by position in the source code. pub fn module_from_position(db: &impl HirDatabase, position: FilePosition) -> Option { - let file = db.source_file(position.file_id); + let file = db.parse(position.file_id); match find_node_at_offset::(file.syntax(), position.offset) { Some(m) if !m.has_semi() => module_from_inline(db, position.file_id.into(), m), _ => module_from_file_id(db, position.file_id.into()), @@ -95,7 +95,7 @@ fn module_from_source(db: &impl HirDatabase, source: SourceItemId) -> Option Option { - let file = db.source_file(position.file_id); + let file = db.parse(position.file_id); let fn_def = find_node_at_offset::(file.syntax(), position.offset)?; function_from_source(db, position.file_id, fn_def) } diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 0eb4da06e..e0b0689f8 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -547,7 +547,7 @@ fn quux() { fn infer(content: &str) -> String { let (db, _, file_id) = MockDatabase::with_single_file(content); - let source_file = db.source_file(file_id); + let source_file = db.parse(file_id); let mut acc = String::new(); for fn_def in source_file .syntax() diff --git a/crates/ra_ide_api/src/call_info.rs b/crates/ra_ide_api/src/call_info.rs index 728f2df30..3267fff96 100644 --- a/crates/ra_ide_api/src/call_info.rs +++ b/crates/ra_ide_api/src/call_info.rs @@ -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 { - 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 Option { - 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(); diff --git a/crates/ra_ide_api/src/extend_selection.rs b/crates/ra_ide_api/src/extend_selection.rs index 1cd955357..cd2ebe471 100644 --- a/crates/ra_ide_api/src/extend_selection.rs +++ b/crates/ra_ide_api/src/extend_selection.rs @@ -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; } diff --git a/crates/ra_ide_api/src/goto_definition.rs b/crates/ra_ide_api/src/goto_definition.rs index 180cc7c80..2a20c20ee 100644 --- a/crates/ra_ide_api/src/goto_definition.rs +++ b/crates/ra_ide_api/src/goto_definition.rs @@ -11,7 +11,7 @@ pub(crate) fn goto_definition( db: &RootDatabase, position: FilePosition, ) -> Option>> { - 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::(syntax, position.offset) { let navs = reference_definition(db, position.file_id, name_ref).to_vec(); diff --git a/crates/ra_ide_api/src/hover.rs b/crates/ra_ide_api/src/hover.rs index b6d727399..ff9ae2d9c 100644 --- a/crates/ra_ide_api/src/hover.rs +++ b/crates/ra_ide_api/src/hover.rs @@ -7,7 +7,7 @@ use ra_syntax::{ use crate::{db::RootDatabase, RangeInfo, FilePosition, FileRange, NavigationTarget}; pub(crate) fn hover(db: &RootDatabase, position: FilePosition) -> Option> { - 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 Option { - 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 { impl NavigationTarget { fn node(&self, db: &RootDatabase) -> Option> { - 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() diff --git a/crates/ra_ide_api/src/imp.rs b/crates/ra_ide_api/src/imp.rs index 1222fdc44..399433a01 100644 --- a/crates/ra_ide_api/src/imp.rs +++ b/crates/ra_ide_api/src/imp.rs @@ -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 { - 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 { - 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)) diff --git a/crates/ra_ide_api/src/lib.rs b/crates/ra_ide_api/src/lib.rs index 62a1934f4..43c8bea71 100644 --- a/crates/ra_ide_api/src/lib.rs +++ b/crates/ra_ide_api/src/lib.rs @@ -313,7 +313,7 @@ impl Analysis { /// Gets the syntax tree of the file. pub fn parse(&self, file_id: FileId) -> TreeArc { - 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 { - 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 { - 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 { - 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 { - 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 { - 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 { - let file = self.db.source_file(file_id); + let file = self.db.parse(file_id); ra_ide_api_light::folding_ranges(&file) } diff --git a/crates/ra_ide_api/src/rename.rs b/crates/ra_ide_api/src/rename.rs index 81ca0537c..db5ccf969 100644 --- a/crates/ra_ide_api/src/rename.rs +++ b/crates/ra_ide_api/src/rename.rs @@ -25,7 +25,7 @@ pub(crate) fn rename( position: FilePosition, new_name: &str, ) -> Option { - 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) { diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs index 0f2d00f13..dc8c40ea6 100644 --- a/crates/ra_ide_api/src/runnables.rs +++ b/crates/ra_ide_api/src/runnables.rs @@ -22,7 +22,7 @@ pub enum RunnableKind { } pub(crate) fn runnables(db: &RootDatabase, file_id: FileId) -> Vec { - let source_file = db.source_file(file_id); + let source_file = db.parse(file_id); source_file .syntax() .descendants() diff --git a/crates/ra_ide_api/src/status.rs b/crates/ra_ide_api/src/status.rs index 59159df98..e11eed223 100644 --- a/crates/ra_ide_api/src/status.rs +++ b/crates/ra_ide_api/src/status.rs @@ -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::(); - let syntax_tree_stats = db.query(SourceFileQuery).entries::(); + let syntax_tree_stats = db.query(ParseQuery).entries::(); let symbols_stats = db .query(LibrarySymbolsQuery) .entries::(); diff --git a/crates/ra_ide_api/src/symbol_index.rs b/crates/ra_ide_api/src/symbol_index.rs index 230ff410e..72c93f530 100644 --- a/crates/ra_ide_api/src/symbol_index.rs +++ b/crates/ra_ide_api/src/symbol_index.rs @@ -61,7 +61,7 @@ pub(crate) trait SymbolsDatabase: hir::db::HirDatabase { fn file_symbols(db: &impl SymbolsDatabase, file_id: FileId) -> Arc { 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() diff --git a/crates/ra_ide_api/src/syntax_highlighting.rs b/crates/ra_ide_api/src/syntax_highlighting.rs index 16d23e140..26bde495b 100644 --- a/crates/ra_ide_api/src/syntax_highlighting.rs +++ b/crates/ra_ide_api/src/syntax_highlighting.rs @@ -7,7 +7,7 @@ use crate::{ }; pub(crate) fn highlight(db: &RootDatabase, file_id: FileId) -> Vec { - 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() -- cgit v1.2.3