@@ -338,7 +338,7 @@ The algorithm for building a tree of modules is to start with a crate root
338
338
declarations and recursively process child modules. This is handled by the
339
339
[ ` module_tree_query ` ] , with two slight variations.
340
340
341
- [ `module_tree_query` ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/hir /src/module_tree.rs#L116-L123
341
+ [ `module_tree_query` ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_hir /src/module_tree.rs#L115-L133
342
342
343
343
First, rust-analyzer builds a module tree for all crates in a source root
344
344
simultaneously. The main reason for this is historical (` module_tree ` predates
@@ -361,7 +361,7 @@ the same, we don't have to re-execute [`module_tree_query`]. In fact, we only
361
361
need to re-execute it when we add/remove new files or when we change mod
362
362
declarations.
363
363
364
- [ `submodules_query` ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/hir /src/module_tree.rs#L41
364
+ [ `submodules_query` ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_hir /src/module_tree.rs#L41
365
365
366
366
We store the resulting modules in a ` Vec ` -based indexed arena. The indices in
367
367
the arena becomes module IDs. And this brings us to the next topic:
@@ -389,8 +389,8 @@ integers which can "intern" a location and return an integer ID back. The salsa
389
389
database we use includes a couple of [ interners] . How to "garbage collect"
390
390
unused locations is an open question.
391
391
392
- [ `LocationInterner` ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/base_db /src/loc2id.rs#L65-L71
393
- [ interners ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/hir /src/db.rs#L22-L23
392
+ [ `LocationInterner` ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_db /src/loc2id.rs#L65-L71
393
+ [ interners ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_hir /src/db.rs#L22-L23
394
394
395
395
For example, we use ` LocationInterner ` to assign IDs to definitions of functions,
396
396
structs, enums, etc. The location, [ ` DefLoc ` ] contains two bits of information:
@@ -404,7 +404,7 @@ using offsets, text ranges or syntax trees as keys and values for queries. What
404
404
we do instead is we store "index" of the item among all of the items of a file
405
405
(so, a positional based ID, but localized to a single file).
406
406
407
- [ `DefLoc` ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/hir /src/ids.rs#L127 -L139
407
+ [ `DefLoc` ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_hir /src/ids.rs#L129 -L139
408
408
409
409
One thing we've glossed over for the time being is support for macros. We have
410
410
only proof of concept handling of macros at the moment, but they are extremely
@@ -437,7 +437,7 @@ terms of `HirFileId`! This does not recur infinitely though: any chain of
437
437
` HirFileId ` s bottoms out in ` HirFileId::FileId ` , that is, some source file
438
438
actually written by the user.
439
439
440
- [ `HirFileId` ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/hir /src/ids.rs#L18-L125
440
+ [ `HirFileId` ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_hir /src/ids.rs#L31-L93
441
441
442
442
Now that we understand how to identify a definition, in a source or in a
443
443
macro-generated file, we can discuss name resolution a bit.
@@ -451,14 +451,13 @@ each module into a position-independent representation which does not change if
451
451
we modify bodies of the items. After that we [ loop] resolving all imports until
452
452
we've reached a fixed point.
453
453
454
- [ lower ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/hir/src/nameres/lower.rs#L113-L117
455
- [ loop ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/hir/src/nameres.rs#L186-L196
456
-
454
+ [ lower ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/nameres/lower.rs#L113-L147
455
+ [ loop ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_hir/src/nameres.rs#L186-L196
457
456
And, given all our preparation with IDs and a position-independent representation,
458
457
it is satisfying to [ test] that typing inside function body does not invalidate
459
458
name resolution results.
460
459
461
- [ test ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/hir /src/nameres/tests.rs#L376
460
+ [ test ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_hir /src/nameres/tests.rs#L376
462
461
463
462
An interesting fact about name resolution is that it "erases" all of the
464
463
intermediate paths from the imports: in the end, we know which items are defined
@@ -493,10 +492,10 @@ there's an intermediate [projection query] which returns only the first
493
492
position-independent part of the lowering. The result of this query is stable.
494
493
Naturally, name resolution [ uses] this stable projection query.
495
494
496
- [ imports ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/hir /src/nameres/lower.rs#L52-L59
497
- [ `SourceMap` ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/hir /src/nameres/lower.rs#L52-L59
498
- [ projection query ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/hir /src/nameres/lower.rs#L97-L103
499
- [ uses ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/hir /src/query_definitions.rs#L49
495
+ [ imports ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_hir /src/nameres/lower.rs#L52-L59
496
+ [ `SourceMap` ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_hir /src/nameres/lower.rs#L52-L59
497
+ [ projection query ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_hir /src/nameres/lower.rs#L97-L103
498
+ [ uses ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_hir /src/query_definitions.rs#L49
500
499
501
500
## Type inference
502
501
@@ -518,10 +517,10 @@ construct a mapping from `ExprId`s to types.
518
517
519
518
[ @flodiebold ] : https://github.com/flodiebold
520
519
[ #327 ] : https://github.com/rust-lang/rust-analyzer/pull/327
521
- [ lower the AST ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/hir /src/expr.rs
522
- [ positional ID ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/hir /src/expr.rs#L13-L15
523
- [ a source map ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/hir /src/expr.rs#L41-L44
524
- [ type inference ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/hir /src/ty.rs#L1208-L1223
520
+ [ lower the AST ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_hir /src/expr.rs
521
+ [ positional ID ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_hir /src/expr.rs#L13-L15
522
+ [ a source map ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_hir /src/expr.rs#L41-L44
523
+ [ type inference ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_hir /src/ty.rs#L1208-L1223
525
524
526
525
## Tying it all together: completion
527
526
@@ -563,10 +562,11 @@ the type to completion.
563
562
[ catch ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_lsp_server/src/main_loop.rs#L436-L442
564
563
[ the handler ] : https://salsa.zulipchat.com/#narrow/stream/181542-rfcs.2Fsalsa-query-group/topic/design.20next.20steps
565
564
[ ask analysis for completion ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ide_api/src/lib.rs#L439-L444
566
- [ completion implementation ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ide_api/src/completion.rs#L46-L62
567
- [ `CompletionContext` ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ide_api/src/completion/completion_context.rs#L14-L37
568
- [ "IntelliJ Trick" ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ide_api/src/completion/completion_context.rs#L72-L75
569
- [ find an ancestor `fn` node ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ide_api/src/completion/completion_context.rs#L116-L120
570
- [ semantic model ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ide_api/src/completion/completion_context.rs#L123
571
- [ series of independent completion routines ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ide_api/src/completion.rs#L52-L59
572
- [ `complete_dot` ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ide_api/src/completion/complete_dot.rs#L6-L22
565
+ [ ask analysis for completion ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_ide_api/src/lib.rs#L439-L444
566
+ [ completion implementation ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_ide_api/src/completion.rs#L46-L62
567
+ [ `CompletionContext` ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_ide_api/src/completion/completion_context.rs#L14-L37
568
+ [ "IntelliJ Trick" ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_ide_api/src/completion/completion_context.rs#L72-L75
569
+ [ find an ancestor `fn` node ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_ide_api/src/completion/completion_context.rs#L116-L120
570
+ [ semantic model ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_ide_api/src/completion/completion_context.rs#L123
571
+ [ series of independent completion routines ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_ide_api/src/completion.rs#L52-L59
572
+ [ `complete_dot` ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_ide_api/src/completion/complete_dot.rs#L6-L22
0 commit comments