Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

Commit

Permalink
feat(rome-formatter): Comments Map
Browse files Browse the repository at this point in the history
This PR implements a multimap for storing the leading, dangling, and trailing comments for nodes.

An implementation using a general-purpose implementation would use a multimaps for the leading, trailing, and dangling comments and
 each multimap would allocate a `Vec` for every node with a comment.

 This purpose-built multimap uses a shared `Vec` to store all comments where this is possible (99.99% of comments) and only allocates
 node specific `Vec`s if necessary.

The idea behind the implementation is that comments should maintain the same order as in the source document. That means:
* All comments for a node are inserted at "the same" time (one at a time, but all together)
* It first inserts the leading, then dangling, and finally, a node's trailing comments.
  • Loading branch information
MichaReiser committed Sep 15, 2022
1 parent 7744815 commit 5fd3664
Show file tree
Hide file tree
Showing 4 changed files with 806 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/rome_formatter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ cfg-if = "1.0.0"
indexmap = "1.8.2"
schemars = { version = "0.8.10", optional = true }
rustc-hash = "1.1.0"
countme = "3.0.1"

[features]
serde = ["dep:serde", "schemars", "rome_rowan/serde"]
2 changes: 2 additions & 0 deletions crates/rome_formatter/src/comments.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
mod map;

use rome_rowan::{
Direction, Language, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxTriviaPieceComments,
WalkEvent,
Expand Down
Loading

0 comments on commit 5fd3664

Please sign in to comment.