@@ -338,7 +338,7 @@ The algorithm for building a tree of modules is to start with a crate root
338338declarations and recursively process child modules. This is handled by the
339339[ ` module_tree_query ` ] , with two slight variations.
340340
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
342342
343343First, rust-analyzer builds a module tree for all crates in a source root
344344simultaneously. 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
361361need to re-execute it when we add/remove new files or when we change mod
362362declarations.
363363
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
365365
366366We store the resulting modules in a ` Vec ` -based indexed arena. The indices in
367367the 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
389389database we use includes a couple of [ interners] . How to "garbage collect"
390390unused locations is an open question.
391391
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
394394
395395For example, we use ` LocationInterner ` to assign IDs to definitions of functions,
396396structs, 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
404404we do instead is we store "index" of the item among all of the items of a file
405405(so, a positional based ID, but localized to a single file).
406406
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
408408
409409One thing we've glossed over for the time being is support for macros. We have
410410only 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
437437` HirFileId ` s bottoms out in ` HirFileId::FileId ` , that is, some source file
438438actually written by the user.
439439
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
441441
442442Now that we understand how to identify a definition, in a source or in a
443443macro-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
451451we modify bodies of the items. After that we [ loop] resolving all imports until
452452we've reached a fixed point.
453453
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
457456And, given all our preparation with IDs and a position-independent representation,
458457it is satisfying to [ test] that typing inside function body does not invalidate
459458name resolution results.
460459
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
462461
463462An interesting fact about name resolution is that it "erases" all of the
464463intermediate 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
493492position-independent part of the lowering. The result of this query is stable.
494493Naturally, name resolution [ uses] this stable projection query.
495494
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
500499
501500## Type inference
502501
@@ -518,10 +517,10 @@ construct a mapping from `ExprId`s to types.
518517
519518[ @flodiebold ] : https://github.com/flodiebold
520519[ #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
525524
526525## Tying it all together: completion
527526
@@ -563,10 +562,11 @@ the type to completion.
563562[ catch ] : https://github.com/rust-lang/rust-analyzer/blob/guide-2019-01/crates/ra_lsp_server/src/main_loop.rs#L436-L442
564563[ the handler ] : https://salsa.zulipchat.com/#narrow/stream/181542-rfcs.2Fsalsa-query-group/topic/design.20next.20steps
565564[ 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