mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 05:45:12 +00:00
Rename File -> SourceFileNode
This commit is contained in:
parent
2119fe2143
commit
f8b36bbc3b
23 changed files with 117 additions and 102 deletions
|
@ -2,7 +2,7 @@ use ra_editor::find_node_at_offset;
|
|||
use ra_syntax::{
|
||||
algo::visit::{visitor, visitor_ctx, Visitor, VisitorCtx},
|
||||
ast::{self, AstChildren, LoopBodyOwner, ModuleItemOwner},
|
||||
AstNode, AtomEdit, File,
|
||||
AstNode, AtomEdit, SourceFileNode,
|
||||
SyntaxKind::*,
|
||||
SyntaxNodeRef, TextUnit,
|
||||
};
|
||||
|
@ -63,7 +63,7 @@ pub(crate) fn resolve_based_completion(
|
|||
pub(crate) fn find_target_module(
|
||||
module_tree: &ModuleTree,
|
||||
module_id: ModuleId,
|
||||
file: &File,
|
||||
file: &SourceFileNode,
|
||||
offset: TextUnit,
|
||||
) -> Option<ModuleId> {
|
||||
let name_ref: ast::NameRef = find_node_at_offset(file.syntax(), offset)?;
|
||||
|
@ -142,7 +142,7 @@ pub(crate) fn scope_completion(
|
|||
}
|
||||
|
||||
fn complete_module_items(
|
||||
file: &File,
|
||||
file: &SourceFileNode,
|
||||
items: AstChildren<ast::ModuleItem>,
|
||||
this_item: Option<ast::NameRef>,
|
||||
acc: &mut Vec<CompletionItem>,
|
||||
|
@ -164,7 +164,7 @@ fn complete_module_items(
|
|||
);
|
||||
}
|
||||
|
||||
fn complete_name_ref(file: &File, name_ref: ast::NameRef, acc: &mut Vec<CompletionItem>) {
|
||||
fn complete_name_ref(file: &SourceFileNode, name_ref: ast::NameRef, acc: &mut Vec<CompletionItem>) {
|
||||
if !is_node::<ast::Path>(name_ref.syntax()) {
|
||||
return;
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ fn is_node<'a, N: AstNode<'a>>(node: SyntaxNodeRef<'a>) -> bool {
|
|||
}
|
||||
|
||||
fn complete_expr_keywords(
|
||||
file: &File,
|
||||
file: &SourceFileNode,
|
||||
fn_def: ast::FnDef,
|
||||
name_ref: ast::NameRef,
|
||||
acc: &mut Vec<CompletionItem>,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use ra_editor::LineIndex;
|
||||
use ra_syntax::{File, SyntaxNode};
|
||||
use ra_syntax::{SourceFileNode, SyntaxNode};
|
||||
use salsa::{self, Database};
|
||||
|
||||
use crate::{
|
||||
|
@ -85,7 +85,7 @@ salsa::database_storage! {
|
|||
|
||||
salsa::query_group! {
|
||||
pub(crate) trait SyntaxDatabase: crate::input::FilesDatabase {
|
||||
fn file_syntax(file_id: FileId) -> File {
|
||||
fn file_syntax(file_id: FileId) -> SourceFileNode {
|
||||
type FileSyntaxQuery;
|
||||
}
|
||||
fn file_lines(file_id: FileId) -> Arc<LineIndex> {
|
||||
|
@ -103,9 +103,9 @@ salsa::query_group! {
|
|||
}
|
||||
}
|
||||
|
||||
fn file_syntax(db: &impl SyntaxDatabase, file_id: FileId) -> File {
|
||||
fn file_syntax(db: &impl SyntaxDatabase, file_id: FileId) -> SourceFileNode {
|
||||
let text = db.file_text(file_id);
|
||||
File::parse(&*text)
|
||||
SourceFileNode::parse(&*text)
|
||||
}
|
||||
fn file_lines(db: &impl SyntaxDatabase, file_id: FileId) -> Arc<LineIndex> {
|
||||
let text = db.file_text(file_id);
|
||||
|
|
|
@ -272,7 +272,7 @@ pub fn resolve_local_name<'a>(
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ra_editor::find_node_at_offset;
|
||||
use ra_syntax::File;
|
||||
use ra_syntax::SourceFileNode;
|
||||
use test_utils::extract_offset;
|
||||
|
||||
use super::*;
|
||||
|
@ -287,7 +287,7 @@ mod tests {
|
|||
buf.push_str(&code[off..]);
|
||||
buf
|
||||
};
|
||||
let file = File::parse(&code);
|
||||
let file = SourceFileNode::parse(&code);
|
||||
let marker: ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap();
|
||||
let fn_def: ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap();
|
||||
let scopes = FnScopes::new(fn_def);
|
||||
|
@ -376,7 +376,7 @@ mod tests {
|
|||
|
||||
fn do_check_local_name(code: &str, expected_offset: u32) {
|
||||
let (off, code) = extract_offset(code);
|
||||
let file = File::parse(&code);
|
||||
let file = SourceFileNode::parse(&code);
|
||||
let fn_def: ast::FnDef = find_node_at_offset(file.syntax(), off).unwrap();
|
||||
let name_ref: ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap();
|
||||
|
||||
|
|
|
@ -95,10 +95,10 @@ fn collect_imports(tree: ast::UseTree, acc: &mut Vec<Entry>) {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use ra_syntax::{ast::ModuleItemOwner, File};
|
||||
use ra_syntax::{ast::ModuleItemOwner, SourceFileNode};
|
||||
|
||||
fn do_check(code: &str, expected: &[&str]) {
|
||||
let file = File::parse(&code);
|
||||
let file = SourceFileNode::parse(&code);
|
||||
let scope = ModuleScope::new(file.ast().items());
|
||||
let actual = scope.entries.iter().map(|it| it.name()).collect::<Vec<_>>();
|
||||
assert_eq!(expected, actual.as_slice());
|
||||
|
|
|
@ -7,7 +7,7 @@ use std::{
|
|||
use ra_editor::{self, find_node_at_offset, FileSymbol, LineIndex, LocalEdit};
|
||||
use ra_syntax::{
|
||||
ast::{self, ArgListOwner, Expr, NameOwner},
|
||||
AstNode, File, SmolStr,
|
||||
AstNode, SourceFileNode, SmolStr,
|
||||
SyntaxKind::*,
|
||||
SyntaxNodeRef, TextRange, TextUnit,
|
||||
};
|
||||
|
@ -27,7 +27,7 @@ use crate::{
|
|||
input::{FilesDatabase, SourceRoot, SourceRootId, WORKSPACE},
|
||||
symbol_index::SymbolIndex,
|
||||
AnalysisChange, Cancelable, CrateGraph, CrateId, Diagnostic, FileId, FileResolver,
|
||||
FileSystemEdit, FilePosition, Query, SourceChange, SourceFileEdit,
|
||||
FileSystemEdit, FilePosition, Query, SourceChange, SourceFileNodeEdit,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
|
@ -180,7 +180,7 @@ impl fmt::Debug for AnalysisImpl {
|
|||
}
|
||||
|
||||
impl AnalysisImpl {
|
||||
pub fn file_syntax(&self, file_id: FileId) -> File {
|
||||
pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode {
|
||||
self.db.file_syntax(file_id)
|
||||
}
|
||||
pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
|
||||
|
@ -562,7 +562,7 @@ impl AnalysisImpl {
|
|||
|
||||
impl SourceChange {
|
||||
pub(crate) fn from_local_edit(file_id: FileId, label: &str, edit: LocalEdit) -> SourceChange {
|
||||
let file_edit = SourceFileEdit {
|
||||
let file_edit = SourceFileNodeEdit {
|
||||
file_id,
|
||||
edits: edit.edit.into_atoms(),
|
||||
};
|
||||
|
|
|
@ -20,7 +20,7 @@ pub mod mock_analysis;
|
|||
|
||||
use std::{fmt, sync::Arc};
|
||||
|
||||
use ra_syntax::{AtomEdit, File, TextRange, TextUnit};
|
||||
use ra_syntax::{AtomEdit, SourceFileNode, TextRange, TextUnit};
|
||||
use rayon::prelude::*;
|
||||
use relative_path::RelativePathBuf;
|
||||
|
||||
|
@ -128,13 +128,13 @@ pub struct FilePosition {
|
|||
#[derive(Debug)]
|
||||
pub struct SourceChange {
|
||||
pub label: String,
|
||||
pub source_file_edits: Vec<SourceFileEdit>,
|
||||
pub source_file_edits: Vec<SourceFileNodeEdit>,
|
||||
pub file_system_edits: Vec<FileSystemEdit>,
|
||||
pub cursor_position: Option<FilePosition>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct SourceFileEdit {
|
||||
pub struct SourceFileNodeEdit {
|
||||
pub file_id: FileId,
|
||||
pub edits: Vec<AtomEdit>,
|
||||
}
|
||||
|
@ -204,16 +204,16 @@ pub struct Analysis {
|
|||
}
|
||||
|
||||
impl Analysis {
|
||||
pub fn file_syntax(&self, file_id: FileId) -> File {
|
||||
pub fn file_syntax(&self, file_id: FileId) -> SourceFileNode {
|
||||
self.imp.file_syntax(file_id).clone()
|
||||
}
|
||||
pub fn file_line_index(&self, file_id: FileId) -> Arc<LineIndex> {
|
||||
self.imp.file_line_index(file_id)
|
||||
}
|
||||
pub fn extend_selection(&self, file: &File, range: TextRange) -> TextRange {
|
||||
pub fn extend_selection(&self, file: &SourceFileNode, range: TextRange) -> TextRange {
|
||||
ra_editor::extend_selection(file, range).unwrap_or(range)
|
||||
}
|
||||
pub fn matching_brace(&self, file: &File, offset: TextUnit) -> Option<TextUnit> {
|
||||
pub fn matching_brace(&self, file: &SourceFileNode, offset: TextUnit) -> Option<TextUnit> {
|
||||
ra_editor::matching_brace(file, offset)
|
||||
}
|
||||
pub fn syntax_tree(&self, file_id: FileId) -> String {
|
||||
|
@ -309,7 +309,7 @@ pub struct LibraryData {
|
|||
impl LibraryData {
|
||||
pub fn prepare(files: Vec<(FileId, String)>, file_resolver: Arc<FileResolver>) -> LibraryData {
|
||||
let symbol_index = SymbolIndex::for_files(files.par_iter().map(|(file_id, text)| {
|
||||
let file = File::parse(text);
|
||||
let file = SourceFileNode::parse(text);
|
||||
(*file_id, file)
|
||||
}));
|
||||
LibraryData {
|
||||
|
|
|
@ -6,7 +6,7 @@ use std::{
|
|||
use fst::{self, Streamer};
|
||||
use ra_editor::{file_symbols, FileSymbol};
|
||||
use ra_syntax::{
|
||||
File,
|
||||
SourceFileNode,
|
||||
SyntaxKind::{self, *},
|
||||
};
|
||||
use rayon::prelude::*;
|
||||
|
@ -34,7 +34,9 @@ impl Hash for SymbolIndex {
|
|||
}
|
||||
|
||||
impl SymbolIndex {
|
||||
pub(crate) fn for_files(files: impl ParallelIterator<Item = (FileId, File)>) -> SymbolIndex {
|
||||
pub(crate) fn for_files(
|
||||
files: impl ParallelIterator<Item = (FileId, SourceFileNode)>,
|
||||
) -> SymbolIndex {
|
||||
let mut symbols = files
|
||||
.flat_map(|(file_id, file)| {
|
||||
file_symbols(&file)
|
||||
|
@ -51,7 +53,7 @@ impl SymbolIndex {
|
|||
SymbolIndex { symbols, map }
|
||||
}
|
||||
|
||||
pub(crate) fn for_file(file_id: FileId, file: File) -> SymbolIndex {
|
||||
pub(crate) fn for_file(file_id: FileId, file: SourceFileNode) -> SymbolIndex {
|
||||
SymbolIndex::for_files(rayon::iter::once((file_id, file)))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use ra_syntax::{File, SyntaxKind, SyntaxNode, SyntaxNodeRef, TextRange};
|
||||
use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, TextRange};
|
||||
|
||||
use crate::db::SyntaxDatabase;
|
||||
use crate::FileId;
|
||||
|
@ -43,7 +43,7 @@ impl LocalSyntaxPtr {
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn resolve(self, file: &File) -> SyntaxNode {
|
||||
pub(crate) fn resolve(self, file: &SourceFileNode) -> SyntaxNode {
|
||||
let mut curr = file.syntax();
|
||||
loop {
|
||||
if curr.range() == self.range && curr.kind() == self.kind {
|
||||
|
@ -67,7 +67,7 @@ impl LocalSyntaxPtr {
|
|||
#[test]
|
||||
fn test_local_syntax_ptr() {
|
||||
use ra_syntax::{ast, AstNode};
|
||||
let file = File::parse("struct Foo { f: u32, }");
|
||||
let file = SourceFileNode::parse("struct Foo { f: u32, }");
|
||||
let field = file
|
||||
.syntax()
|
||||
.descendants()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue