You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: swayfmt/src/utils/map/comments.rs
+76-13
Original file line number
Diff line number
Diff line change
@@ -170,8 +170,19 @@ fn add_comments(
170
170
Ok(())
171
171
}
172
172
173
-
// A CommentWithContext is the Comment and the offset before it. The offset can be between the (from) item we searched for this comment or from the last comment inside range
174
-
typeCommentWithContext = (Comment,String);
173
+
// A `CommentWithContext` is the `Comment` and the offset before and after it.
174
+
// A context is simply the chars between two points around a comment.
175
+
//
176
+
// The pre-context can be from the item we searched for this comment or from the last comment inside range.
177
+
//
178
+
// The post-context is an Option<String> that gets populated only if there is an "else" token following the `Comment`.
179
+
// It starts from end of the `Comment` and goes until the beginning of the `else` token.
180
+
// There may be other tokens we might need to look-ahead for in future.
181
+
structCommentWithContext{
182
+
pre_context:String,
183
+
comment:Comment,
184
+
post_context:Option<String>,
185
+
}
175
186
176
187
/// Returns a list of comments between given spans. For each comment returns the Context
177
188
/// Context of a comment is basically the offset (the characters between the last item/comment) to the current comment
/// Inserts after given span and returns the offset. While inserting comments this also inserts Context of the comments so that the alignment whitespaces/newlines are intact
249
+
// In certain cases where comments come in between unusual places,
250
+
// ..
251
+
// }
252
+
// // This is a comment
253
+
// else {
254
+
// ..
255
+
// We need to know the context after the comment as well.
// If we don't find anything to format in the context after, we simply
270
+
// return an empty context.
271
+
None
272
+
}
273
+
}
274
+
275
+
/// Inserts after given span and returns the offset. While inserting comments this also inserts contexts of the comments so that the alignment whitespaces/newlines are intact
0 commit comments