rust-lang/rust-analyzer

rust-analyzer reader-mode

Open

#8,696 创建于 2021年4月30日

在 GitHub 查看
 (37 评论) (16 反应) (0 负责人)Rust (14,924 star) (1,726 fork)batch import
E-hardS-actionablefungood first issue

描述

TL;DR: https://github.com/rust-dev-tools/cargo-src, but on top of rust-analyzer

Add a command, rust-analyzer reader-mode path/to/Cargo.toml, which produces a directory with a bunch of html files, which contain source for the project, a-la rustdoc output, but also have goto definition, hover, etc.

Interface Constraints:

  • Static site
  • Assume modern desktop browser
  • No external CSS, or CSS pre-processors, minimal hand-written CSS to get the job done.
  • No or minimal JavaScript
  • No build-in HTTP serever (but it's OK to try to auto-discover python3 -m http.server and such on usres' machine)
  • (Maybe) an option to compress everything down to a single html file which you can just open in the browser.

Implementation Constraints:

  • Implementatin lives in ide-reader-mode and is exposed via ide crate.
  • There's a transparent intermediate representation. The result of reader mode is not directly an HTML string, but something else. That something else is a set of annotated files, struct ReaderView. This view is independent of the hir or ide types, and is just a large chunk of data. The data includes two things, a list of files and a list of defs. Each file is a text plus a number of auxilary maps that describe ranges in the file. There should be a map for syntax hightlighting, a map for references and definitons, maybe a map for folding ranges (fold method bodies would be useful feature to have). Spans in files refer to defs by ID. Defs are untyped, and store their defining spans and a list of refs. Not sure if we need a separate ref list or just spans would be enough.
  • ReaderView might want to live in a separate crate, just to make sure it doesn't depend on rust-analyzer types
  • ReaderView has fn to_html(&self) -> HashMap<PathBuf, String> method, which renders it as a directory with htmls and csses. This should be completely independent of the rust-analyzer.

贡献者指南