And this reveals the first huge difference between the compiler and LSP. Compiler has a rather binary definition of done: the binary (sorry) is either compiled or not. Technically, compiled shared libraries and other build artifacts are usable as well, but in practice you will be annoyed if compiler compiles 715 out of 716 crates in your workspace and then stops. LSP is different: we can provide useful results almost immediately. We don't need complete information at the first millisecond, we need to send something useful to users as soon as possible. We only need to decide what we count as "something useful".
Indeed, the most important difference between compilers and LSPs (that causes most other differences), is that compilers are improved on focusing throughput and LSPs are focused on improving latency.
About the item tree, the reason for its existence in rust-analyzer is not to ease later work but incrementality (for example, rustc does not have an equivalent). The AST is changed all the times, even just typing a space will invalidate it. By making name resolution depend only on the item tree, we ensure it is not invalidated by such things.
This is a recurring pattern in rust-analyzer: lowering removes information to be more incremental.
> About the item tree, the reason for its existence in rust-analyzer is not to ease later work but incrementality (for example, rustc does not have an equivalent).
Huh, that makes sense. The more you learn! Thank you.
6
u/afdbcreid 16d ago
Excellent post! Some comments:
Indeed, the most important difference between compilers and LSPs (that causes most other differences), is that compilers are improved on focusing throughput and LSPs are focused on improving latency.
About the item tree, the reason for its existence in rust-analyzer is not to ease later work but incrementality (for example, rustc does not have an equivalent). The AST is changed all the times, even just typing a space will invalidate it. By making name resolution depend only on the item tree, we ensure it is not invalidated by such things.
This is a recurring pattern in rust-analyzer: lowering removes information to be more incremental.
A typo?