Skip to content

Commit 117f5df

Browse files
committed
refactor(formatter): remove all the todo! implementations (#15928)
Remove todo! implementations as they are not used
1 parent 776e473 commit 117f5df

File tree

7 files changed

+7
-166
lines changed

7 files changed

+7
-166
lines changed

crates/oxc_formatter/src/formatter/comments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ use oxc_ast::{
107107
use oxc_span::{GetSpan, Span};
108108

109109
use crate::{
110-
Format, FormatResult, SyntaxTriviaPieceComments,
110+
Format, FormatResult,
111111
formatter::{Formatter, SourceText},
112112
};
113113

crates/oxc_formatter/src/formatter/formatter.rs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ use oxc_ast::AstKind;
66
use crate::options::FormatOptions;
77

88
use super::{
9-
Arguments, Buffer, Comments, FormatContext, FormatState, FormatStateSnapshot, GroupId,
10-
SourceText, VecBuffer,
9+
Arguments, Buffer, Comments, FormatContext, FormatState, GroupId, SourceText, VecBuffer,
1110
buffer::BufferSnapshot,
1211
builders::{FillBuilder, JoinBuilder, JoinNodesBuilder, Line},
1312
prelude::*,
@@ -256,21 +255,6 @@ impl<'buf, 'ast> Formatter<'buf, 'ast> {
256255
}
257256
}
258257

259-
impl Formatter<'_, '_> {
260-
/// Take a snapshot of the state of the formatter
261-
#[inline]
262-
pub fn state_snapshot(&self) -> FormatterSnapshot {
263-
FormatterSnapshot { buffer: self.buffer.snapshot(), state: self.state().snapshot() }
264-
}
265-
266-
#[inline]
267-
/// Restore the state of the formatter to a previous snapshot
268-
pub fn restore_state_snapshot(&mut self, snapshot: FormatterSnapshot) {
269-
self.state_mut().restore_snapshot(snapshot.state);
270-
self.buffer.restore_snapshot(snapshot.buffer);
271-
}
272-
}
273-
274258
impl<'ast> Buffer<'ast> for Formatter<'_, 'ast> {
275259
#[inline(always)]
276260
fn write_element(&mut self, element: FormatElement<'ast>) -> FormatResult<()> {
@@ -305,14 +289,3 @@ impl<'ast> Buffer<'ast> for Formatter<'_, 'ast> {
305289
self.buffer.restore_snapshot(snapshot);
306290
}
307291
}
308-
309-
/// Snapshot of the formatter state used to handle backtracking if
310-
/// errors are encountered in the formatting process and the formatter
311-
/// has to fallback to printing raw tokens
312-
///
313-
/// In practice this only saves the set of printed tokens in debug
314-
/// mode and compiled to nothing in release mode
315-
pub struct FormatterSnapshot {
316-
buffer: BufferSnapshot,
317-
state: FormatStateSnapshot,
318-
}

crates/oxc_formatter/src/formatter/mod.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ mod state;
3636
mod syntax_element_key;
3737
mod syntax_node;
3838
mod syntax_token;
39-
mod syntax_trivia_piece_comments;
4039
mod text_len;
4140
mod text_range;
4241
mod text_size;
@@ -63,10 +62,9 @@ pub use self::{
6362
diagnostics::{ActualStart, FormatError, InvalidDocumentError, PrintError},
6463
formatter::Formatter,
6564
source_text::SourceText,
66-
state::{FormatState, FormatStateSnapshot},
65+
state::FormatState,
6766
syntax_node::SyntaxNode,
6867
syntax_token::SyntaxToken,
69-
syntax_trivia_piece_comments::SyntaxTriviaPieceComments,
7068
text_len::TextLen,
7169
text_range::TextRange,
7270
text_size::TextSize,
@@ -112,25 +110,14 @@ impl Formatted<'_> {
112110

113111
let printed = Printer::new(print_options).print(&self.document)?;
114112

115-
// let printed = match self.context.source_map() {
116-
// Some(source_map) => source_map.map_printed(printed),
117-
// None => printed,
118-
// };
119-
120113
Ok(printed)
121114
}
122115

123116
pub fn print_with_indent(&self, indent: u16) -> PrintResult<Printed> {
124-
todo!()
125-
// let print_options = self.context.options().as_print_options();
126-
// let printed = Printer::new(print_options).print_with_indent(&self.document, indent)?;
127-
128-
// let printed = match self.context.source_map() {
129-
// Some(source_map) => source_map.map_printed(printed),
130-
// None => printed,
131-
// };
117+
let print_options = self.context.options().as_print_options();
118+
let printed = Printer::new(print_options).print_with_indent(&self.document, indent)?;
132119

133-
// Ok(printed)
120+
Ok(printed)
134121
}
135122
}
136123
pub type PrintResult<T> = Result<T, PrintError>;

crates/oxc_formatter/src/formatter/state.rs

Lines changed: 0 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ pub struct FormatState<'ast> {
1616
// For the document IR printing process
1717
/// The interned elements that have been printed to this point
1818
printed_interned_elements: FxHashMap<Interned<'ast>, usize>,
19-
// This is using a RefCell as it only exists in debug mode,
20-
// the Formatter is still completely immutable in release builds
21-
// #[cfg(debug_assertions)]
22-
// pub printed_tokens: PrintedTokens,
2319
}
2420

2521
impl std::fmt::Debug for FormatState<'_> {
@@ -35,8 +31,6 @@ impl<'ast> FormatState<'ast> {
3531
context,
3632
group_id_builder: UniqueGroupIdBuilder::default(),
3733
printed_interned_elements: FxHashMap::default(),
38-
// #[cfg(debug_assertions)]
39-
// printed_tokens: Default::default(),
4034
}
4135
}
4236

@@ -65,81 +59,4 @@ impl<'ast> FormatState<'ast> {
6559
pub fn printed_interned_elements(&mut self) -> &mut FxHashMap<Interned<'ast>, usize> {
6660
&mut self.printed_interned_elements
6761
}
68-
69-
#[cfg(not(debug_assertions))]
70-
#[inline]
71-
pub fn track_token(&mut self, span: Span) {}
72-
73-
/// Tracks the given token as formatted
74-
#[cfg(debug_assertions)]
75-
#[inline]
76-
pub fn track_token(&mut self, span: Span) {
77-
// self.printed_tokens.track_token(token);
78-
}
79-
80-
#[cfg(not(debug_assertions))]
81-
#[inline]
82-
pub fn set_token_tracking_disabled(&mut self, _: bool) {}
83-
84-
/// Disables or enables token tracking for a portion of the code.
85-
///
86-
/// It can be useful to disable the token tracking when it is necessary to re-format a node with different parameters.
87-
#[cfg(debug_assertions)]
88-
pub fn set_token_tracking_disabled(&mut self, enabled: bool) {
89-
todo!()
90-
// self.printed_tokens.set_disabled(enabled)
91-
}
92-
93-
#[cfg(not(debug_assertions))]
94-
#[inline]
95-
pub fn is_token_tracking_disabled(&self) -> bool {
96-
false
97-
}
98-
99-
/// Returns `true` if token tracking is currently disabled.
100-
#[cfg(debug_assertions)]
101-
pub fn is_token_tracking_disabled(&self) -> bool {
102-
todo!()
103-
// self.printed_tokens.is_disabled()
104-
}
105-
106-
#[cfg(not(debug_assertions))]
107-
#[inline]
108-
pub fn assert_formatted_all_tokens(&self, _root: &SyntaxNode) {}
109-
110-
/// Asserts in debug builds that all tokens have been printed.
111-
#[cfg(debug_assertions)]
112-
#[inline]
113-
pub fn assert_formatted_all_tokens(&self, root: &SyntaxNode) {
114-
todo!()
115-
// self.printed_tokens.assert_all_tracked(root);
116-
}
117-
}
118-
119-
impl FormatState<'_> {
120-
pub fn snapshot(&self) -> FormatStateSnapshot {
121-
todo!()
122-
// FormatStateSnapshot {
123-
// #[cfg(debug_assertions)]
124-
// printed_tokens: self.printed_tokens.snapshot(),
125-
// }
126-
}
127-
128-
pub fn restore_snapshot(&mut self, _snapshot: FormatStateSnapshot) {
129-
todo!()
130-
// let FormatStateSnapshot {
131-
// #[cfg(debug_assertions)]
132-
// printed_tokens,
133-
// } = snapshot;
134-
135-
// cfg_if::cfg_if! {
136-
// if #[cfg(debug_assertions)] {
137-
// self.printed_tokens.restore(printed_tokens);
138-
// }
139-
// }
140-
}
14162
}
142-
143-
pub struct FormatStateSnapshot;
144-
// #[cfg(debug_assertions)]
145-
// printed_tokens: printed_tokens::PrintedTokensSnapshot,

crates/oxc_formatter/src/formatter/syntax_trivia_piece_comments.rs

Lines changed: 0 additions & 33 deletions
This file was deleted.

crates/oxc_formatter/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
clippy::inline_always,
44
clippy::missing_panics_doc,
55
clippy::needless_pass_by_ref_mut,
6-
clippy::todo,
76
clippy::unused_self,
87
clippy::enum_variant_names,
98
clippy::struct_field_names

crates/oxc_formatter/src/options.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
use std::{fmt, num::ParseIntError, str::FromStr};
22

3-
pub use crate::formatter::{
4-
Buffer, Format, FormatResult, SyntaxTriviaPieceComments, token::string::Quote,
5-
};
3+
pub use crate::formatter::{Buffer, Format, FormatResult, token::string::Quote};
64
use crate::{
75
formatter::{
86
formatter::Formatter,

0 commit comments

Comments
 (0)