mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Fix typos in ARCHITECTURE.md and a number of crates
specifically: gen_lsp_server, ra_arena, ra_cli, ra_db, ra_hir
This commit is contained in:
parent
f8261d611a
commit
0b8fbb4fad
23 changed files with 150 additions and 91 deletions
|
@ -13,8 +13,8 @@ use crate::{
|
|||
ty::InferenceResult,
|
||||
};
|
||||
|
||||
/// hir::Crate describes a single crate. It's the main inteface with which
|
||||
/// crate's dependencies interact. Mostly, it should be just a proxy for the
|
||||
/// hir::Crate describes a single crate. It's the main interface with which
|
||||
/// a crate's dependencies interact. Mostly, it should be just a proxy for the
|
||||
/// root module.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Crate {
|
||||
|
@ -78,6 +78,7 @@ impl Module {
|
|||
pub fn definition_source(&self, db: &impl HirDatabase) -> Cancelable<(FileId, ModuleSource)> {
|
||||
self.definition_source_impl(db)
|
||||
}
|
||||
|
||||
/// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.
|
||||
/// `None` for the crate root.
|
||||
pub fn declaration_source(
|
||||
|
@ -91,20 +92,24 @@ impl Module {
|
|||
pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> {
|
||||
self.krate_impl(db)
|
||||
}
|
||||
|
||||
/// Topmost parent of this module. Every module has a `crate_root`, but some
|
||||
/// might miss `krate`. This can happen if a module's file is not included
|
||||
/// into any module tree of any target from Cargo.toml.
|
||||
/// might be missing `krate`. This can happen if a module's file is not included
|
||||
/// in the module tree of any target in Cargo.toml.
|
||||
pub fn crate_root(&self, db: &impl HirDatabase) -> Cancelable<Module> {
|
||||
self.crate_root_impl(db)
|
||||
}
|
||||
|
||||
/// Finds a child module with the specified name.
|
||||
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
|
||||
self.child_impl(db, name)
|
||||
}
|
||||
|
||||
/// Finds a parent module.
|
||||
pub fn parent(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> {
|
||||
self.parent_impl(db)
|
||||
}
|
||||
|
||||
pub fn path_to_root(&self, db: &impl HirDatabase) -> Cancelable<Vec<Module>> {
|
||||
let mut res = vec![self.clone()];
|
||||
let mut curr = self.clone();
|
||||
|
@ -114,13 +119,16 @@ impl Module {
|
|||
}
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
/// Returns a `ModuleScope`: a set of items, visible in this module.
|
||||
pub fn scope(&self, db: &impl HirDatabase) -> Cancelable<ModuleScope> {
|
||||
self.scope_impl(db)
|
||||
}
|
||||
|
||||
pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> Cancelable<PerNs<DefId>> {
|
||||
self.resolve_path_impl(db, path)
|
||||
}
|
||||
|
||||
pub fn problems(
|
||||
&self,
|
||||
db: &impl HirDatabase,
|
||||
|
@ -140,6 +148,7 @@ impl StructField {
|
|||
pub fn name(&self) -> &Name {
|
||||
&self.name
|
||||
}
|
||||
|
||||
pub fn type_ref(&self) -> &TypeRef {
|
||||
&self.type_ref
|
||||
}
|
||||
|
@ -160,18 +169,21 @@ impl VariantData {
|
|||
_ => &[],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_struct(&self) -> bool {
|
||||
match self {
|
||||
VariantData::Struct(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_tuple(&self) -> bool {
|
||||
match self {
|
||||
VariantData::Tuple(..) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_unit(&self) -> bool {
|
||||
match self {
|
||||
VariantData::Unit => true,
|
||||
|
|
|
@ -26,6 +26,7 @@ pub trait HirDatabase: SyntaxDatabase
|
|||
type HirSourceFileQuery;
|
||||
use fn HirFileId::hir_source_file;
|
||||
}
|
||||
|
||||
fn expand_macro_invocation(invoc: MacroCallId) -> Option<Arc<MacroExpansion>> {
|
||||
type ExpandMacroCallQuery;
|
||||
use fn crate::macros::expand_macro_invocation;
|
||||
|
@ -80,10 +81,12 @@ pub trait HirDatabase: SyntaxDatabase
|
|||
type InputModuleItemsQuery;
|
||||
use fn query_definitions::input_module_items;
|
||||
}
|
||||
|
||||
fn item_map(source_root_id: SourceRootId) -> Cancelable<Arc<ItemMap>> {
|
||||
type ItemMapQuery;
|
||||
use fn query_definitions::item_map;
|
||||
}
|
||||
|
||||
fn module_tree(source_root_id: SourceRootId) -> Cancelable<Arc<ModuleTree>> {
|
||||
type ModuleTreeQuery;
|
||||
use fn crate::module_tree::ModuleTree::module_tree_query;
|
||||
|
|
|
@ -33,8 +33,7 @@ pub struct Body {
|
|||
/// IDs. This is needed to go from e.g. a position in a file to the HIR
|
||||
/// expression containing it; but for type inference etc., we want to operate on
|
||||
/// a structure that is agnostic to the actual positions of expressions in the
|
||||
/// file, so that we don't recompute the type inference whenever some whitespace
|
||||
/// is typed.
|
||||
/// file, so that we don't recompute types whenever some whitespace is typed.
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct BodySyntaxMapping {
|
||||
body: Arc<Body>,
|
||||
|
@ -74,20 +73,25 @@ impl BodySyntaxMapping {
|
|||
pub fn expr_syntax(&self, expr: ExprId) -> Option<LocalSyntaxPtr> {
|
||||
self.expr_syntax_mapping_back.get(expr).cloned()
|
||||
}
|
||||
|
||||
pub fn syntax_expr(&self, ptr: LocalSyntaxPtr) -> Option<ExprId> {
|
||||
self.expr_syntax_mapping.get(&ptr).cloned()
|
||||
}
|
||||
|
||||
pub fn node_expr(&self, node: &ast::Expr) -> Option<ExprId> {
|
||||
self.expr_syntax_mapping
|
||||
.get(&LocalSyntaxPtr::new(node.syntax()))
|
||||
.cloned()
|
||||
}
|
||||
|
||||
pub fn pat_syntax(&self, pat: PatId) -> Option<LocalSyntaxPtr> {
|
||||
self.pat_syntax_mapping_back.get(pat).cloned()
|
||||
}
|
||||
|
||||
pub fn syntax_pat(&self, ptr: LocalSyntaxPtr) -> Option<PatId> {
|
||||
self.pat_syntax_mapping.get(&ptr).cloned()
|
||||
}
|
||||
|
||||
pub fn node_pat(&self, node: &ast::Pat) -> Option<PatId> {
|
||||
self.pat_syntax_mapping
|
||||
.get(&LocalSyntaxPtr::new(node.syntax()))
|
||||
|
|
|
@ -9,25 +9,25 @@ use crate::{
|
|||
|
||||
use crate::code_model_api::Module;
|
||||
|
||||
/// hir makes a heavy use of ids: integer (u32) handlers to various things. You
|
||||
/// hir makes heavy use of ids: integer (u32) handlers to various things. You
|
||||
/// can think of id as a pointer (but without a lifetime) or a file descriptor
|
||||
/// (but for hir objects).
|
||||
///
|
||||
/// This module defines a bunch of ids we are using. The most important ones are
|
||||
/// probably `HirFileId` and `DefId`.
|
||||
|
||||
/// Input to the analyzer is a set of file, where each file is indetified by
|
||||
/// Input to the analyzer is a set of files, where each file is indentified by
|
||||
/// `FileId` and contains source code. However, another source of source code in
|
||||
/// Rust are macros: each macro can be thought of as producing a "temporary
|
||||
/// file". To assign id to such file, we use the id of a macro call that
|
||||
/// file". To assign an id to such a file, we use the id of the macro call that
|
||||
/// produced the file. So, a `HirFileId` is either a `FileId` (source code
|
||||
/// written by user), or a `MacroCallId` (source code produced by macro).
|
||||
///
|
||||
/// What is a `MacroCallId`? Simplifying, it's a `HirFileId` of a file containin
|
||||
/// the call plus the offset of the macro call in the file. Note that this is a
|
||||
/// recursive definition! Nethetheless, size_of of `HirFileId` is finite
|
||||
/// recursive definition! However, the size_of of `HirFileId` is finite
|
||||
/// (because everything bottoms out at the real `FileId`) and small
|
||||
/// (`MacroCallId` uses location interner).
|
||||
/// (`MacroCallId` uses the location interner).
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub struct HirFileId(HirFileIdRepr);
|
||||
|
||||
|
@ -235,7 +235,7 @@ pub struct SourceItemId {
|
|||
pub(crate) item_id: Option<SourceFileItemId>,
|
||||
}
|
||||
|
||||
/// Maps item's `SyntaxNode`s to `SourceFileItemId` and back.
|
||||
/// Maps items' `SyntaxNode`s to `SourceFileItemId`s and back.
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct SourceFileItems {
|
||||
file_id: HirFileId,
|
||||
|
|
|
@ -128,13 +128,13 @@ impl ImplItem {
|
|||
pub struct ImplId(pub RawId);
|
||||
impl_arena_id!(ImplId);
|
||||
|
||||
/// Collection of impl blocks is a two-step process: First we collect the blocks
|
||||
/// per-module; then we build an index of all impl blocks in the crate. This
|
||||
/// way, we avoid having to do this process for the whole crate whenever someone
|
||||
/// types in any file; as long as the impl blocks in the file don't change, we
|
||||
/// don't need to do the second step again.
|
||||
/// The collection of impl blocks is a two-step process: first we collect the
|
||||
/// blocks per-module; then we build an index of all impl blocks in the crate.
|
||||
/// This way, we avoid having to do this process for the whole crate whenever
|
||||
/// a file is changed; as long as the impl blocks in the file don't change,
|
||||
/// we don't need to do the second step again.
|
||||
///
|
||||
/// (The second step does not yet exist currently.)
|
||||
/// (The second step does not yet exist.)
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub struct ModuleImplBlocks {
|
||||
impls: Arena<ImplId, ImplData>,
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
//! HIR (previsouly known as descriptors) provides a high-level OO acess to Rust
|
||||
//! code.
|
||||
//! HIR (previously known as descriptors) provides a high-level object oriented
|
||||
//! access to Rust code.
|
||||
//!
|
||||
//! The principal difference between HIR and syntax trees is that HIR is bound
|
||||
//! to a particular crate instance. That is, it has cfg flags and features
|
||||
//! applied. So, there relation between syntax and HIR is many-to-one.
|
||||
//! applied. So, the relation between syntax and HIR is many-to-one.
|
||||
|
||||
macro_rules! ctry {
|
||||
($expr:expr) => {
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
/// that is produced after expansion. See `HirFileId` and `MacroCallId` for how
|
||||
/// do we do that.
|
||||
///
|
||||
/// When file-management question is resolved, all that is left is a token tree
|
||||
/// to token tree transformation plus hygent. We don't have either of thouse
|
||||
/// yet, so all macros are string based at the moment!
|
||||
/// When the file-management question is resolved, all that is left is a
|
||||
/// token-tree-to-token-tree transformation plus hygiene. We don't have either of
|
||||
/// those yet, so all macros are string based at the moment!
|
||||
use std::sync::Arc;
|
||||
|
||||
use ra_db::LocalSyntaxPtr;
|
||||
|
|
|
@ -85,9 +85,9 @@ impl_arena_id!(LinkId);
|
|||
|
||||
/// Physically, rust source is organized as a set of files, but logically it is
|
||||
/// organized as a tree of modules. Usually, a single file corresponds to a
|
||||
/// single module, but it is not nessary the case.
|
||||
/// single module, but it is not neccessarily always the case.
|
||||
///
|
||||
/// Module encapsulate the logic of transitioning from the fuzzy world of files
|
||||
/// `ModuleTree` encapsulates the logic of transitioning from the fuzzy world of files
|
||||
/// (which can have multiple parents) to the precise world of modules (which
|
||||
/// always have one parent).
|
||||
#[derive(Default, Debug, PartialEq, Eq)]
|
||||
|
|
|
@ -3,7 +3,7 @@ use std::fmt;
|
|||
use ra_syntax::{ast, SmolStr};
|
||||
|
||||
/// `Name` is a wrapper around string, which is used in hir for both references
|
||||
/// and declarations. In theory, names should also carry hygene info, but we are
|
||||
/// and declarations. In theory, names should also carry hygiene info, but we are
|
||||
/// not there yet!
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
pub struct Name {
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
//! Name resolution algorithm. The end result of the algorithm is `ItemMap`: a
|
||||
//! map with maps each module to it's scope: the set of items, visible in the
|
||||
//! Name resolution algorithm. The end result of the algorithm is an `ItemMap`:
|
||||
//! a map which maps each module to its scope: the set of items visible in the
|
||||
//! module. That is, we only resolve imports here, name resolution of item
|
||||
//! bodies will be done in a separate step.
|
||||
//!
|
||||
//! Like Rustc, we use an interative per-crate algorithm: we start with scopes
|
||||
//! Like Rustc, we use an interactive per-crate algorithm: we start with scopes
|
||||
//! containing only directly defined items, and then iteratively resolve
|
||||
//! imports.
|
||||
//!
|
||||
//! To make this work nicely in the IDE scenarios, we place `InputModuleItems`
|
||||
//! To make this work nicely in the IDE scenario, we place `InputModuleItems`
|
||||
//! in between raw syntax and name resolution. `InputModuleItems` are computed
|
||||
//! using only the module's syntax, and it is all directly defined items plus
|
||||
//! imports. The plain is to make `InputModuleItems` independent of local
|
||||
//! modifications (that is, typing inside a function shold not change IMIs),
|
||||
//! such that the results of name resolution can be preserved unless the module
|
||||
//! imports. The plan is to make `InputModuleItems` independent of local
|
||||
//! modifications (that is, typing inside a function should not change IMIs),
|
||||
//! so that the results of name resolution can be preserved unless the module
|
||||
//! structure itself is modified.
|
||||
use std::sync::Arc;
|
||||
|
||||
|
@ -34,7 +34,7 @@ use crate::{
|
|||
module_tree::{ModuleId, ModuleTree},
|
||||
};
|
||||
|
||||
/// Item map is the result of the name resolution. Item map contains, for each
|
||||
/// `ItemMap` is the result of name resolution. It contains, for each
|
||||
/// module, the set of visible items.
|
||||
// FIXME: currenty we compute item map per source-root. We should do it per crate instead.
|
||||
#[derive(Default, Debug, PartialEq, Eq)]
|
||||
|
@ -59,9 +59,9 @@ impl ModuleScope {
|
|||
/// A set of items and imports declared inside a module, without relation to
|
||||
/// other modules.
|
||||
///
|
||||
/// This stands in-between raw syntax and name resolution and alow us to avoid
|
||||
/// recomputing name res: if `InputModuleItems` are the same, we can avoid
|
||||
/// running name resolution.
|
||||
/// This sits in-between raw syntax and name resolution and allows us to avoid
|
||||
/// recomputing name res: if two instance of `InputModuleItems` are the same, we
|
||||
/// can avoid redoing name resolution.
|
||||
#[derive(Debug, Default, PartialEq, Eq)]
|
||||
pub struct InputModuleItems {
|
||||
pub(crate) items: Vec<ModuleItem>,
|
||||
|
@ -114,7 +114,7 @@ enum ImportKind {
|
|||
Named(NamedImport),
|
||||
}
|
||||
|
||||
/// Resolution is basically `DefId` atm, but it should account for stuff like
|
||||
/// `Resolution` is basically `DefId` atm, but it should account for stuff like
|
||||
/// multiple namespaces, ambiguity and errors.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Resolution {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/// Lookup hir elements using position in the source code. This is a lossy
|
||||
/// Lookup hir elements using positions in the source code. This is a lossy
|
||||
/// transformation: in general, a single source might correspond to several
|
||||
/// modules, functions, etc, due to macros, cfgs and `#[path=]` attributes on
|
||||
/// modules.
|
||||
|
|
|
@ -144,7 +144,7 @@ pub enum Ty {
|
|||
Bool,
|
||||
|
||||
/// The primitive character type; holds a Unicode scalar value
|
||||
/// (a non-surrogate code point). Written as `char`.
|
||||
/// (a non-surrogate code point). Written as `char`.
|
||||
Char,
|
||||
|
||||
/// A primitive signed integer type. For example, `i32`.
|
||||
|
@ -204,7 +204,7 @@ pub enum Ty {
|
|||
// `|a| yield a`.
|
||||
// Generator(DefId, GeneratorSubsts<'tcx>, hir::GeneratorMovability),
|
||||
|
||||
// A type representin the types stored inside a generator.
|
||||
// A type representing the types stored inside a generator.
|
||||
// This should only appear in GeneratorInteriors.
|
||||
// GeneratorWitness(Binder<&'tcx List<Ty<'tcx>>>),
|
||||
/// The never type `!`.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
//! In certain situations, rust automatically inserts derefs as necessary: For
|
||||
//! In certain situations, rust automatically inserts derefs as necessary: for
|
||||
//! example, field accesses `foo.bar` still work when `foo` is actually a
|
||||
//! reference to a type with the field `bar`. This is an approximation of the
|
||||
//! logic in rustc (which lives in librustc_typeck/check/autoderef.rs).
|
||||
|
|
|
@ -15,7 +15,7 @@ use crate::{
|
|||
};
|
||||
|
||||
// These tests compare the inference results for all expressions in a file
|
||||
// against snapshots of the current results. If you change something and these
|
||||
// against snapshots of the expected results. If you change something and these
|
||||
// tests fail expectedly, you can update the comparison files by deleting them
|
||||
// and running the tests again. Similarly, to add a new test, just write the
|
||||
// test here in the same pattern and it will automatically write the snapshot.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue