Skip to content

Commit 9ca81ed

Browse files
Merge #9703
9703: docs: Fix several typos and grammar mistakes r=matklad a=alexfertel I took some time to clean up the dev docs a bit since I spent the whole week reading them. I am not a native speaker, so if you find something wrong please tell me and I'll fix it 😁 Co-authored-by: Alexander Gonzalez <alexfertel97@gmail.com>
2 parents 3a59b56 + c865b56 commit 9ca81ed

File tree

4 files changed

+28
-30
lines changed

4 files changed

+28
-30
lines changed

docs/dev/guide.md

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ group of files which are assumed to rarely change. It's mostly an optimization
7979
and does not change the fundamental picture.
8080

8181
The `set_crate_graph` method allows us to control how the input files are partitioned
82-
into compilation unites -- crates. It also controls (in theory, not implemented
82+
into compilation units -- crates. It also controls (in theory, not implemented
8383
yet) `cfg` flags. `CrateGraph` is a directed acyclic graph of crates. Each crate
8484
has a root `FileId`, a set of active `cfg` flags and a set of dependencies. Each
8585
dependency is a pair of a crate and a name. It is possible to have two crates
@@ -95,7 +95,6 @@ function, and will be inserted into the crate graph just like dependencies.
9595
Soon we'll talk how we build an LSP server on top of `Analysis`, but first,
9696
let's deal with that paths issue.
9797

98-
9998
## Source roots (a.k.a. "Filesystems are horrible")
10099

101100
This is a non-essential section, feel free to skip.
@@ -104,18 +103,18 @@ The previous section said that the filesystem path is an attribute of a file,
104103
but this is not the whole truth. Making it an absolute `PathBuf` will be bad for
105104
several reasons. First, filesystems are full of (platform-dependent) edge cases:
106105

107-
* it's hard (requires a syscall) to decide if two paths are equivalent
108-
* some filesystems are case-sensitive (e.g. on macOS)
109-
* paths are not necessary UTF-8
110-
* symlinks can form cycles
106+
* It's hard (requires a syscall) to decide if two paths are equivalent.
107+
* Some filesystems are case-sensitive (e.g. macOS).
108+
* Paths are not necessarily UTF-8.
109+
* Symlinks can form cycles.
111110

112-
Second, this might hurt reproducibility and hermeticity of builds. In theory,
111+
Second, this might hurt the reproducibility and hermeticity of builds. In theory,
113112
moving a project from `/foo/bar/my-project` to `/spam/eggs/my-project` should
114113
not change a bit in the output. However, if the absolute path is a part of the
115114
input, it is at least in theory observable, and *could* affect the output.
116115

117116
Yet another problem is that we really *really* want to avoid doing I/O, but with
118-
Rust the set of "input" files is not necessary known up-front. In theory, you
117+
Rust the set of "input" files is not necessarily known up-front. In theory, you
119118
can have `#[path="/dev/random"] mod foo;`.
120119

121120
To solve (or explicitly refuse to solve) these problems rust-analyzer uses the
@@ -205,7 +204,7 @@ fact that most of the changes are small, and that analysis results are unlikely
205204
to change significantly between invocations.
206205

207206
To do this we use [salsa]: a framework for incremental on-demand computation.
208-
You can skip the rest of the section if you are familiar with rustc's red-green
207+
You can skip the rest of the section if you are familiar with `rustc`'s red-green
209208
algorithm (which is used for incremental compilation).
210209

211210
[salsa]: https://github.com/salsa-rs/salsa
@@ -220,12 +219,11 @@ of type `V`. Queries come in two basic varieties:
220219
like.
221220

222221
* **Functions**: pure functions (no side effects) that transform your inputs
223-
into other values. The results of queries is memoized to avoid recomputing
222+
into other values. The results of queries are memoized to avoid recomputing
224223
them a lot. When you make changes to the inputs, we'll figure out (fairly
225224
intelligently) when we can re-use these memoized values and when we have to
226225
recompute them.
227226

228-
229227
For further discussion, its important to understand one bit of "fairly
230228
intelligently". Suppose we have two functions, `f1` and `f2`, and one input,
231229
`z`. We call `f1(X)` which in turn calls `f2(Y)` which inspects `i(Z)`. `i(Z)`
@@ -267,13 +265,13 @@ The bulk of the rust-analyzer is transforming input text into a semantic model o
267265
Rust code: a web of entities like modules, structs, functions and traits.
268266

269267
An important fact to realize is that (unlike most other languages like C# or
270-
Java) there isn't a one-to-one mapping between source code and the semantic model. A
268+
Java) there is not a one-to-one mapping between the source code and the semantic model. A
271269
single function definition in the source code might result in several semantic
272-
functions: for example, the same source file might be included as a module into
273-
several crate, or a single "crate" might be present in the compilation DAG
270+
functions: for example, the same source file might get included as a module in
271+
several crates or a single crate might be present in the compilation DAG
274272
several times, with different sets of `cfg`s enabled. The IDE-specific task of
275-
mapping source code position into a semantic model is inherently imprecise for
276-
this reason, and is handled by the [`source_binder`].
273+
mapping source code into a semantic model is inherently imprecise for
274+
this reason and gets handled by the [`source_binder`].
277275

278276
[`source_binder`]: https://github.com/rust-analyzer/rust-analyzer/blob/guide-2019-01/crates/hir/src/source_binder.rs
279277

@@ -533,18 +531,18 @@ To conclude the overview of the rust-analyzer, let's trace the request for
533531

534532
We start by [receiving a message] from the language client. We decode the
535533
message as a request for completion and [schedule it on the threadpool]. This is
536-
the also place where we [catch] canceled errors if, immediately after completion, the
534+
the place where we [catch] canceled errors if, immediately after completion, the
537535
client sends some modification.
538536

539-
In [the handler] we a deserialize LSP request into the rust-analyzer specific data
537+
In [the handler], we deserialize LSP requests into rust-analyzer specific data
540538
types (by converting a file url into a numeric `FileId`), [ask analysis for
541-
completion] and serializer results to LSP.
539+
completion] and serialize results into the LSP.
542540

543541
The [completion implementation] is finally the place where we start doing the actual
544542
work. The first step is to collect the `CompletionContext` -- a struct which
545543
describes the cursor position in terms of Rust syntax and semantics. For
546544
example, `function_syntax: Option<&'a ast::FnDef>` stores a reference to
547-
enclosing function *syntax*, while `function: Option<hir::Function>` is the
545+
the enclosing function *syntax*, while `function: Option<hir::Function>` is the
548546
`Def` for this function.
549547

550548
To construct the context, we first do an ["IntelliJ Trick"]: we insert a dummy

docs/dev/lsp-extensions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ interface TestInfo {
656656
}
657657
```
658658

659-
## Hover Actions
659+
## Move Item
660660

661661
**Issue:** https://github.com/rust-analyzer/rust-analyzer/issues/6823
662662

docs/dev/style.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ More than one mark per test / code branch doesn't add significantly to understan
170170
Do not use `#[should_panic]` tests.
171171
Instead, explicitly check for `None`, `Err`, etc.
172172

173-
**Rationale:** `#[should_panic]` is a tool for library authors, to makes sure that API does not fail silently, when misused.
173+
**Rationale:** `#[should_panic]` is a tool for library authors to make sure that the API does not fail silently when misused.
174174
`rust-analyzer` is not a library, we don't need to test for API misuse, and we have to handle any user input without panics.
175175
Panic messages in the logs from the `#[should_panic]` tests are confusing.
176176

@@ -333,7 +333,7 @@ impl Foo {
333333
}
334334
```
335335

336-
Prefer `Default` even it has to be implemented manually.
336+
Prefer `Default` even if it has to be implemented manually.
337337

338338
**Rationale:** less typing in the common case, uniformity.
339339

@@ -343,7 +343,7 @@ Use `Vec::new` rather than `vec![]`.
343343

344344
Avoid using "dummy" states to implement a `Default`.
345345
If a type doesn't have a sensible default, empty value, don't hide it.
346-
Let the caller explicitly decide what's the right initial state is.
346+
Let the caller explicitly decide what the right initial state is.
347347

348348
## Functions Over Objects
349349

@@ -526,7 +526,7 @@ if words.len() != 2 {
526526
}
527527
```
528528

529-
**Rationale:** not allocating is almost often faster.
529+
**Rationale:** not allocating is almost always faster.
530530

531531
## Push Allocations to the Call Site
532532

@@ -998,9 +998,9 @@ match output.status.code() {
998998
};
999999
```
10001000

1001-
**Rationale:** like blocks, single-use variables are a cognitively cheap abstraction, as they have access to all the context.
1001+
**Rationale:** Like blocks, single-use variables are a cognitively cheap abstraction, as they have access to all the context.
10021002
Extra variables help during debugging, they make it easy to print/view important intermediate results.
1003-
Giving a name to a condition in `if` expression often improves clarity and leads to a nicer formatted code.
1003+
Giving a name to a condition inside an `if` expression often improves clarity and leads to nicely formatted code.
10041004

10051005
## Token names
10061006

docs/dev/syntax.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This guide describes the current state of syntax trees and parsing in rust-analy
66

77
## Source Code
88

9-
The things described are implemented in two places
9+
The things described are implemented in three places
1010

1111
* [rowan](https://github.com/rust-analyzer/rowan/tree/v0.9.0) -- a generic library for rowan syntax trees.
1212
* [ra_syntax](https://github.com/rust-analyzer/rust-analyzer/tree/cf5bdf464cad7ceb9a67e07985a3f4d3799ec0b6/crates/ra_syntax) crate inside rust-analyzer which wraps `rowan` into rust-analyzer specific API.
@@ -15,9 +15,9 @@ The things described are implemented in two places
1515

1616
## Design Goals
1717

18-
* Syntax trees are lossless, or full fidelity. All comments and whitespace are preserved.
18+
* Syntax trees are lossless, or full fidelity. All comments and whitespace get preserved.
1919
* Syntax trees are semantic-less. They describe *strictly* the structure of a sequence of characters, they don't have hygiene, name resolution or type information attached.
20-
* Syntax trees are simple value type. It is possible to create trees for a syntax without any external context.
20+
* Syntax trees are simple value types. It is possible to create trees for a syntax without any external context.
2121
* Syntax trees have intuitive traversal API (parent, children, siblings, etc).
2222
* Parsing is lossless (even if the input is invalid, the tree produced by the parser represents it exactly).
2323
* Parsing is resilient (even if the input is invalid, parser tries to see as much syntax tree fragments in the input as it can).

0 commit comments

Comments
 (0)