Skip to content

Commit 76b3985

Browse files
473: Partial typo fix r=matklad a=marcusklaas This fixes some typos. Mostly in documentation, but also some code is affected (`defenition` was used in a few method names). Co-authored-by: Marcus Klaas de Vries <[email protected]>
2 parents c0f48f9 + 0b8fbb4 commit 76b3985

File tree

28 files changed

+171
-112
lines changed

28 files changed

+171
-112
lines changed

ARCHITECTURE.md

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Architecture
22

3-
This document describes high-level architecture of rust-analyzer.
3+
This document describes the high-level architecture of rust-analyzer.
44
If you want to familiarize yourself with the code base, you are just
55
in the right place!
66

@@ -12,10 +12,10 @@ On the highest level, rust-analyzer is a thing which accepts input source code
1212
from the client and produces a structured semantic model of the code.
1313

1414
More specifically, input data consists of a set of test files (`(PathBuf,
15-
String)` pairs) and an information about project structure, the so called
16-
`CrateGraph`. Crate graph specifies which files are crate roots, which cfg flags
17-
are specified for each crate (TODO: actually implement this) and what are
18-
dependencies between the crates. The analyzer keeps all these input data in
15+
String)` pairs) and information about project structure, captured in the so called
16+
`CrateGraph`. The crate graph specifies which files are crate roots, which cfg
17+
flags are specified for each crate (TODO: actually implement this) and what
18+
dependencies exist between the crates. The analyzer keeps all this input data in
1919
memory and never does any IO. Because the input data is source code, which
2020
typically measures in tens of megabytes at most, keeping all input data in
2121
memory is OK.
@@ -28,16 +28,16 @@ declarations, etc.
2828
The client can submit a small delta of input data (typically, a change to a
2929
single file) and get a fresh code model which accounts for changes.
3030

31-
Underlying engine makes sure that model is computed lazily (on-demand) and can
32-
be quickly updated for small modifications.
31+
The underlying engine makes sure that model is computed lazily (on-demand) and
32+
can be quickly updated for small modifications.
3333

3434

3535
## Code generation
3636

3737
Some of the components of this repository are generated through automatic
3838
processes. These are outlined below:
3939

40-
- `gen-syntax`: The kinds of tokens are reused in several places, so a generator
40+
- `gen-syntax`: The kinds of tokens that are reused in several places, so a generator
4141
is used. We use tera templates to generate the files listed below, based on
4242
the grammar described in [grammar.ron]:
4343
- [ast/generated.rs][ast generated] in `ra_syntax` based on
@@ -58,17 +58,16 @@ processes. These are outlined below:
5858
### `crates/ra_syntax`
5959

6060
Rust syntax tree structure and parser. See
61-
[RFC](https://github.com/rust-lang/rfcs/pull/2256) for some design
62-
notes.
61+
[RFC](https://github.com/rust-lang/rfcs/pull/2256) for some design notes.
6362

6463
- [rowan](https://github.com/rust-analyzer/rowan) library is used for constructing syntax trees.
65-
- `grammar` module is the actual parser. It is a hand-written recursive descent parsers, which
66-
produces a sequence of events like "start node X", "finish not Y". It works similarly to [kotlin parser](https://github.com/JetBrains/kotlin/blob/4d951de616b20feca92f3e9cc9679b2de9e65195/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java),
67-
which is a good source for inspiration for dealing with syntax errors and incomplete input. Original [libsyntax parser](https://github.com/rust-lang/rust/blob/6b99adeb11313197f409b4f7c4083c2ceca8a4fe/src/libsyntax/parse/parser.rs)
64+
- `grammar` module is the actual parser. It is a hand-written recursive descent parser, which
65+
produces a sequence of events like "start node X", "finish not Y". It works similarly to [kotlin's parser](https://github.com/JetBrains/kotlin/blob/4d951de616b20feca92f3e9cc9679b2de9e65195/compiler/frontend/src/org/jetbrains/kotlin/parsing/KotlinParsing.java),
66+
which is a good source of inspiration for dealing with syntax errors and incomplete input. Original [libsyntax parser](https://github.com/rust-lang/rust/blob/6b99adeb11313197f409b4f7c4083c2ceca8a4fe/src/libsyntax/parse/parser.rs)
6867
is what we use for the definition of the Rust language.
6968
- `parser_api/parser_impl` bridges the tree-agnostic parser from `grammar` with `rowan` trees.
7069
This is the thing that turns a flat list of events into a tree (see `EventProcessor`)
71-
- `ast` a type safe API on top of the raw `rowan` tree.
70+
- `ast` provides a type safe API on top of the raw `rowan` tree.
7271
- `grammar.ron` RON description of the grammar, which is used to
7372
generate `syntax_kinds` and `ast` modules, using `cargo gen-syntax` command.
7473
- `algo`: generic tree algorithms, including `walk` for O(1) stack
@@ -90,7 +89,7 @@ fixes a bug in the grammar.
9089
We use the [salsa](https://github.com/salsa-rs/salsa) crate for incremental and
9190
on-demand computation. Roughly, you can think of salsa as a key-value store, but
9291
it also can compute derived values using specified functions. The `ra_db` crate
93-
provides a basic infrastructure for interacting with salsa. Crucially, it
92+
provides basic infrastructure for interacting with salsa. Crucially, it
9493
defines most of the "input" queries: facts supplied by the client of the
9594
analyzer. Reading the docs of the `ra_db::input` module should be useful:
9695
everything else is strictly derived from those inputs.
@@ -102,7 +101,7 @@ HIR provides high-level "object oriented" access to Rust code.
102101
The principal difference between HIR and syntax trees is that HIR is bound to a
103102
particular crate instance. That is, it has cfg flags and features applied (in
104103
theory, in practice this is to be implemented). So, the relation between
105-
syntax and HIR is many-to-one. The `source_binder` modules is responsible for
104+
syntax and HIR is many-to-one. The `source_binder` module is responsible for
106105
guessing a HIR for a particular source position.
107106

108107
Underneath, HIR works on top of salsa, using a `HirDatabase` trait.
@@ -111,12 +110,12 @@ Underneath, HIR works on top of salsa, using a `HirDatabase` trait.
111110

112111
A stateful library for analyzing many Rust files as they change. `AnalysisHost`
113112
is a mutable entity (clojure's atom) which holds the current state, incorporates
114-
changes and handles out `Analysis` --- an immutable and consistent snapshot of
115-
world state at a point in time, which actually powers analysis.
113+
changes and hands out `Analysis` --- an immutable and consistent snapshot of
114+
the world state at a point in time, which actually powers analysis.
116115

117116
One interesting aspect of analysis is its support for cancellation. When a
118117
change is applied to `AnalysisHost`, first all currently active snapshots are
119-
cancelled. Only after all snapshots are dropped the change actually affects the
118+
canceled. Only after all snapshots are dropped the change actually affects the
120119
database.
121120

122121
APIs in this crate are IDE centric: they take text offsets as input and produce
@@ -142,7 +141,7 @@ An LSP implementation which wraps `ra_ide_api` into a langauge server protocol.
142141

143142
### `crates/ra_vfs`
144143

145-
Although `hir` and `ra_ide_api` don't do any io, we need to be able to read
144+
Although `hir` and `ra_ide_api` don't do any IO, we need to be able to read
146145
files from disk at the end of the day. This is what `ra_vfs` does. It also
147146
manages overlays: "dirty" files in the editor, whose "true" contents is
148147
different from data on disk.
@@ -175,16 +174,16 @@ VS Code plugin
175174
## Common workflows
176175

177176
To try out VS Code extensions, run `cargo install-code`. This installs both the
178-
`ra_lsp_server` binary and VS Code extension. To install only the binary, use
177+
`ra_lsp_server` binary and the VS Code extension. To install only the binary, use
179178
`cargo install --path crates/ra_lsp_server --force`
180179

181180
To see logs from the language server, set `RUST_LOG=info` env variable. To see
182181
all communication between the server and the client, use
183-
`RUST_LOG=gen_lsp_server=debug` (will print quite a bit of stuff).
182+
`RUST_LOG=gen_lsp_server=debug` (this will print quite a bit of stuff).
184183

185184
To run tests, just `cargo test`.
186185

187-
To work on VS Code extension, launch code inside `editors/code` and use `F5` to
186+
To work on the VS Code extension, launch code inside `editors/code` and use `F5` to
188187
launch/debug. To automatically apply formatter and linter suggestions, use `npm
189188
run fix`.
190189

crates/gen_lsp_server/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ pub use crate::{
7878
};
7979

8080
/// Main entry point: runs the server from initialization to shutdown.
81-
/// To attach server to standard input/output streams, use `stdio_transport`
81+
/// To attach server to standard input/output streams, use the `stdio_transport`
8282
/// function to create corresponding `sender` and `receiver` pair.
8383
///
84-
///`server` should use `handle_shutdown` function to handle the `Shutdown`
84+
/// `server` should use the `handle_shutdown` function to handle the `Shutdown`
8585
/// request.
8686
pub fn run_server(
8787
caps: ServerCapabilities,
@@ -104,7 +104,7 @@ pub fn run_server(
104104
Ok(())
105105
}
106106

107-
/// if `req` is `Shutdown`, respond to it and return `None`, otherwise return `Some(req)`
107+
/// If `req` is `Shutdown`, respond to it and return `None`, otherwise return `Some(req)`
108108
pub fn handle_shutdown(req: RawRequest, sender: &Sender<RawMessage>) -> Option<RawRequest> {
109109
match req.cast::<Shutdown>() {
110110
Ok((id, ())) => {

crates/gen_lsp_server/src/msg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub enum ErrorCode {
5454
ServerErrorEnd = -32000,
5555
ServerNotInitialized = -32002,
5656
UnknownErrorCode = -32001,
57-
RequestCancelled = -32800,
57+
RequestCanceled = -32800,
5858
ContentModified = -32801,
5959
}
6060

crates/ra_db/src/cancelation.rs renamed to crates/ra_db/src/cancellation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
//! * user types next character, while syntax highlighting *is still in
99
//! progress*.
1010
//!
11-
//! In this situation, we want to react to modification as quckly as possible.
11+
//! In this situation, we want to react to modification as quickly as possible.
1212
//! At the same time, in-progress results are not very interesting, because they
1313
//! are invalidated by the edit anyway. So, we first cancel all in-flight
14-
//! requests, and then apply modification knowing that it won't intrfere with
15-
//! any background processing (this bit is handled by salsa, see
14+
//! requests, and then apply modification knowing that it won't interfere with
15+
//! any background processing (this bit is handled by salsa, see the
1616
//! `BaseDatabase::check_canceled` method).
1717
1818
/// An "error" signifing that the operation was canceled.

crates/ra_db/src/input.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
/// This modules specifies the input to rust-analyzer. In some sense, this is
1+
/// This module specifies the input to rust-analyzer. In some sense, this is
22
/// **the** most important module, because all other fancy stuff is strictly
33
/// derived from this input.
44
///
55
/// Note that neither this module, nor any other part of the analyzer's core do
6-
/// actual IO. See `vfs` and `project_model` in `ra_lsp_server` crate for how
6+
/// actual IO. See `vfs` and `project_model` in the `ra_lsp_server` crate for how
77
/// actual IO is done and lowered to input.
88
use std::sync::Arc;
99

@@ -17,17 +17,17 @@ use rustc_hash::FxHashSet;
1717
/// `FileId` is an integer which uniquely identifies a file. File paths are
1818
/// messy and system-dependent, so most of the code should work directly with
1919
/// `FileId`, without inspecting the path. The mapping between `FileId` and path
20-
/// and `SourceRoot` is constant. File rename is represented as a pair of
20+
/// and `SourceRoot` is constant. A file rename is represented as a pair of
2121
/// deletion/creation.
2222
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
2323
pub struct FileId(pub u32);
2424

2525
/// Files are grouped into source roots. A source root is a directory on the
2626
/// file systems which is watched for changes. Typically it corresponds to a
27-
/// Cargo package. Source roots *might* be nested: in this case, file belongs to
28-
/// the nearest enclosing source root. Path to files are always relative to a
29-
/// source root, and analyzer does not know the root path of the source root at
30-
/// all. So, a file from one source root can't refere a file in another source
27+
/// Rust crate. Source roots *might* be nested: in this case, a file belongs to
28+
/// the nearest enclosing source root. Paths to files are always relative to a
29+
/// source root, and the analyzer does not know the root path of the source root at
30+
/// all. So, a file from one source root can't refer to a file in another source
3131
/// root by path.
3232
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
3333
pub struct SourceRootId(pub u32);
@@ -38,15 +38,15 @@ pub struct SourceRoot {
3838
}
3939

4040
/// `CrateGraph` is a bit of information which turns a set of text files into a
41-
/// number of Rust crates. Each Crate is the `FileId` of it's root module, the
42-
/// set of cfg flags (not yet implemented) and the set of dependencies. Note
41+
/// number of Rust crates. Each crate is defined by the `FileId` of its root module,
42+
/// the set of cfg flags (not yet implemented) and the set of dependencies. Note
4343
/// that, due to cfg's, there might be several crates for a single `FileId`! As
4444
/// in the rust-lang proper, a crate does not have a name. Instead, names are
4545
/// specified on dependency edges. That is, a crate might be known under
46-
/// different names in different dependant crates.
46+
/// different names in different dependent crates.
4747
///
4848
/// Note that `CrateGraph` is build-system agnostic: it's a concept of the Rust
49-
/// langauge proper, not a concept of the build system. In practice, we get
49+
/// language proper, not a concept of the build system. In practice, we get
5050
/// `CrateGraph` by lowering `cargo metadata` output.
5151
#[derive(Debug, Clone, Default, PartialEq, Eq)]
5252
pub struct CrateGraph {

crates/ra_db/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//! ra_db defines basic database traits. Concrete DB is defined by ra_ide_api.
2-
mod cancelation;
1+
//! ra_db defines basic database traits. The concrete DB is defined by ra_ide_api.
2+
mod cancellation;
33
mod syntax_ptr;
44
mod input;
55
mod loc2id;
@@ -8,7 +8,7 @@ pub mod mock;
88
use ra_syntax::{TextUnit, TextRange, SourceFile, TreePtr};
99

1010
pub use crate::{
11-
cancelation::{Canceled, Cancelable},
11+
cancellation::{Canceled, Cancelable},
1212
syntax_ptr::LocalSyntaxPtr,
1313
input::{
1414
FilesDatabase, FileId, CrateId, SourceRoot, SourceRootId, CrateGraph, Dependency,

crates/ra_db/src/loc2id.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ use rustc_hash::FxHashMap;
55
use ra_arena::{Arena, ArenaId};
66

77
/// There are two principle ways to refer to things:
8-
/// - by their locatinon (module in foo/bar/baz.rs at line 42)
8+
/// - by their ___location (module in foo/bar/baz.rs at line 42)
99
/// - by their numeric id (module `ModuleId(42)`)
1010
///
1111
/// The first one is more powerful (you can actually find the thing in question
1212
/// by id), but the second one is so much more compact.
1313
///
1414
/// `Loc2IdMap` allows us to have a cake an eat it as well: by maintaining a
1515
/// bidirectional mapping between positional and numeric ids, we can use compact
16-
/// representation wich still allows us to get the actual item
16+
/// representation which still allows us to get the actual item.
1717
#[derive(Debug)]
1818
struct Loc2IdMap<LOC, ID>
1919
where

crates/ra_hir/src/code_model_api.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use crate::{
1313
ty::InferenceResult,
1414
};
1515

16-
/// hir::Crate describes a single crate. It's the main inteface with which
17-
/// crate's dependencies interact. Mostly, it should be just a proxy for the
16+
/// hir::Crate describes a single crate. It's the main interface with which
17+
/// a crate's dependencies interact. Mostly, it should be just a proxy for the
1818
/// root module.
1919
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
2020
pub struct Crate {
@@ -75,9 +75,10 @@ impl Module {
7575
}
7676

7777
/// Returns a node which defines this module. That is, a file or a `mod foo {}` with items.
78-
pub fn defenition_source(&self, db: &impl HirDatabase) -> Cancelable<(FileId, ModuleSource)> {
79-
self.defenition_source_impl(db)
78+
pub fn definition_source(&self, db: &impl HirDatabase) -> Cancelable<(FileId, ModuleSource)> {
79+
self.definition_source_impl(db)
8080
}
81+
8182
/// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`.
8283
/// `None` for the crate root.
8384
pub fn declaration_source(
@@ -91,20 +92,24 @@ impl Module {
9192
pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> {
9293
self.krate_impl(db)
9394
}
95+
9496
/// Topmost parent of this module. Every module has a `crate_root`, but some
95-
/// might miss `krate`. This can happen if a module's file is not included
96-
/// into any module tree of any target from Cargo.toml.
97+
/// might be missing `krate`. This can happen if a module's file is not included
98+
/// in the module tree of any target in Cargo.toml.
9799
pub fn crate_root(&self, db: &impl HirDatabase) -> Cancelable<Module> {
98100
self.crate_root_impl(db)
99101
}
102+
100103
/// Finds a child module with the specified name.
101104
pub fn child(&self, db: &impl HirDatabase, name: &Name) -> Cancelable<Option<Module>> {
102105
self.child_impl(db, name)
103106
}
107+
104108
/// Finds a parent module.
105109
pub fn parent(&self, db: &impl HirDatabase) -> Cancelable<Option<Module>> {
106110
self.parent_impl(db)
107111
}
112+
108113
pub fn path_to_root(&self, db: &impl HirDatabase) -> Cancelable<Vec<Module>> {
109114
let mut res = vec![self.clone()];
110115
let mut curr = self.clone();
@@ -114,13 +119,16 @@ impl Module {
114119
}
115120
Ok(res)
116121
}
122+
117123
/// Returns a `ModuleScope`: a set of items, visible in this module.
118124
pub fn scope(&self, db: &impl HirDatabase) -> Cancelable<ModuleScope> {
119125
self.scope_impl(db)
120126
}
127+
121128
pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> Cancelable<PerNs<DefId>> {
122129
self.resolve_path_impl(db, path)
123130
}
131+
124132
pub fn problems(
125133
&self,
126134
db: &impl HirDatabase,
@@ -140,6 +148,7 @@ impl StructField {
140148
pub fn name(&self) -> &Name {
141149
&self.name
142150
}
151+
143152
pub fn type_ref(&self) -> &TypeRef {
144153
&self.type_ref
145154
}
@@ -160,18 +169,21 @@ impl VariantData {
160169
_ => &[],
161170
}
162171
}
172+
163173
pub fn is_struct(&self) -> bool {
164174
match self {
165175
VariantData::Struct(..) => true,
166176
_ => false,
167177
}
168178
}
179+
169180
pub fn is_tuple(&self) -> bool {
170181
match self {
171182
VariantData::Tuple(..) => true,
172183
_ => false,
173184
}
174185
}
186+
175187
pub fn is_unit(&self) -> bool {
176188
match self {
177189
VariantData::Unit => true,

crates/ra_hir/src/code_model_impl/module.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Module {
3737
Ok(Some(link.name(&module_tree).clone()))
3838
}
3939

40-
pub fn defenition_source_impl(
40+
pub fn definition_source_impl(
4141
&self,
4242
db: &impl HirDatabase,
4343
) -> Cancelable<(FileId, ModuleSource)> {

crates/ra_hir/src/db.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub trait HirDatabase: SyntaxDatabase
2626
type HirSourceFileQuery;
2727
use fn HirFileId::hir_source_file;
2828
}
29+
2930
fn expand_macro_invocation(invoc: MacroCallId) -> Option<Arc<MacroExpansion>> {
3031
type ExpandMacroCallQuery;
3132
use fn crate::macros::expand_macro_invocation;
@@ -80,10 +81,12 @@ pub trait HirDatabase: SyntaxDatabase
8081
type InputModuleItemsQuery;
8182
use fn query_definitions::input_module_items;
8283
}
84+
8385
fn item_map(source_root_id: SourceRootId) -> Cancelable<Arc<ItemMap>> {
8486
type ItemMapQuery;
8587
use fn query_definitions::item_map;
8688
}
89+
8790
fn module_tree(source_root_id: SourceRootId) -> Cancelable<Arc<ModuleTree>> {
8891
type ModuleTreeQuery;
8992
use fn crate::module_tree::ModuleTree::module_tree_query;

0 commit comments

Comments
 (0)