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

Commit 6274662

Browse files
committed
chore: remove FileId from the codebase
1 parent 59a2f8c commit 6274662

File tree

372 files changed

+634
-1117
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

372 files changed

+634
-1117
lines changed

crates/rome_analyze/src/diagnostics.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rome_console::MarkupBuf;
22
use rome_diagnostics::{
33
advice::CodeSuggestionAdvice, category, Advices, Category, Diagnostic, DiagnosticExt,
4-
DiagnosticTags, Error, FileId, Location, Severity, Visit,
4+
DiagnosticTags, Error, Location, Severity, Visit,
55
};
66
use rome_rowan::TextRange;
77
use std::fmt::{Debug, Display, Formatter};
@@ -141,8 +141,6 @@ pub(crate) struct SuppressionDiagnostic {
141141
category: &'static Category,
142142
#[location(span)]
143143
range: TextRange,
144-
#[location(resource)]
145-
file_id: FileId,
146144
#[message]
147145
#[description]
148146
message: String,
@@ -152,13 +150,11 @@ pub(crate) struct SuppressionDiagnostic {
152150

153151
impl SuppressionDiagnostic {
154152
pub(crate) fn new(
155-
file_id: FileId,
156153
category: &'static Category,
157154
range: TextRange,
158155
message: impl Display,
159156
) -> Self {
160157
Self {
161-
file_id,
162158
category,
163159
range,
164160
message: message.to_string(),

crates/rome_analyze/src/lib.rs

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ pub use crate::visitor::{NodeVisitor, Visitor, VisitorContext, VisitorFinishCont
4545
pub use rule::DeserializableRuleOptions;
4646

4747
use rome_console::markup;
48-
use rome_diagnostics::{
49-
category, Applicability, Diagnostic, DiagnosticExt, DiagnosticTags, FileId,
50-
};
48+
use rome_diagnostics::{category, Applicability, Diagnostic, DiagnosticExt, DiagnosticTags};
5149
use rome_rowan::{
5250
AstNode, BatchMutation, Direction, Language, SyntaxElement, SyntaxToken, TextRange, TextSize,
5351
TokenAtOffset, TriviaPieceKind, WalkEvent,
@@ -75,7 +73,6 @@ pub struct Analyzer<'analyzer, L: Language, Matcher, Break, Diag> {
7573
}
7674

7775
pub struct AnalyzerContext<'a, L: Language> {
78-
pub file_id: FileId,
7976
pub root: LanguageRoot<L>,
8077
pub services: ServiceBag,
8178
pub range: Option<TextRange>,
@@ -140,7 +137,6 @@ where
140137
line_index: &mut line_index,
141138
line_suppressions: &mut line_suppressions,
142139
emit_signal: &mut emit_signal,
143-
file_id: ctx.file_id,
144140
root: &ctx.root,
145141
services: &ctx.services,
146142
range: ctx.range,
@@ -178,7 +174,6 @@ where
178174

179175
let signal = DiagnosticSignal::new(|| {
180176
SuppressionDiagnostic::new(
181-
ctx.file_id,
182177
category!("suppressions/unused"),
183178
suppression.comment_span,
184179
"Suppression comment is not being used",
@@ -216,8 +211,6 @@ struct PhaseRunner<'analyzer, 'phase, L: Language, Matcher, Break, Diag> {
216211
line_suppressions: &'phase mut Vec<LineSuppression>,
217212
/// Handles analyzer signals emitted by individual rules
218213
emit_signal: &'phase mut SignalHandler<'analyzer, L, Break>,
219-
/// ID if the file being analyzed
220-
file_id: FileId,
221214
/// Root node of the file being analyzed
222215
root: &'phase L::Root,
223216
/// Service bag handle for this phase
@@ -263,7 +256,7 @@ where
263256

264257
// If this is a token enter event, process its text content
265258
WalkEvent::Enter(SyntaxElement::Token(token)) => {
266-
self.handle_token(self.file_id, token)?;
259+
self.handle_token(token)?;
267260

268261
continue;
269262
}
@@ -276,7 +269,6 @@ where
276269
for visitor in self.visitors.iter_mut() {
277270
let ctx = VisitorContext {
278271
phase: self.phase,
279-
file_id: self.file_id,
280272
root: self.root,
281273
services: self.services,
282274
range: self.range,
@@ -301,7 +293,6 @@ where
301293
for visitor in self.visitors.iter_mut() {
302294
let ctx = VisitorContext {
303295
phase: self.phase,
304-
file_id: self.file_id,
305296
root: self.root,
306297
services: self.services,
307298
range: self.range,
@@ -323,7 +314,7 @@ where
323314
/// Process the text for a single token, parsing suppression comments and
324315
/// handling line breaks, then flush all pending query signals in the queue
325316
/// whose position is less then the end of the token within the file
326-
fn handle_token(&mut self, file_id: FileId, token: SyntaxToken<L>) -> ControlFlow<Break> {
317+
fn handle_token(&mut self, token: SyntaxToken<L>) -> ControlFlow<Break> {
327318
// Process the content of the token for comments and newline
328319
for (index, piece) in token.leading_trivia().pieces().enumerate() {
329320
if matches!(
@@ -336,14 +327,7 @@ where
336327
}
337328

338329
if let Some(comment) = piece.as_comments() {
339-
self.handle_comment(
340-
file_id,
341-
&token,
342-
true,
343-
index,
344-
comment.text(),
345-
piece.text_range(),
346-
)?;
330+
self.handle_comment(&token, true, index, comment.text(), piece.text_range())?;
347331
}
348332
}
349333

@@ -360,14 +344,7 @@ where
360344
}
361345

362346
if let Some(comment) = piece.as_comments() {
363-
self.handle_comment(
364-
file_id,
365-
&token,
366-
false,
367-
index,
368-
comment.text(),
369-
piece.text_range(),
370-
)?;
347+
self.handle_comment(&token, false, index, comment.text(), piece.text_range())?;
371348
}
372349
}
373350

@@ -445,7 +422,6 @@ where
445422
/// comments, and create line suppression entries accordingly
446423
fn handle_comment(
447424
&mut self,
448-
file_id: FileId,
449425
token: &SyntaxToken<L>,
450426
is_leading: bool,
451427
index: usize,
@@ -464,7 +440,7 @@ where
464440
let signal = DiagnosticSignal::new(move || {
465441
let location = diag.location();
466442
let span = location.span.map_or(range, |span| span + range.start());
467-
diag.clone().with_file_path(file_id).with_file_span(span)
443+
diag.clone().with_file_span(span)
468444
});
469445

470446
(self.emit_signal)(&signal)?;
@@ -498,14 +474,12 @@ where
498474
// Emit a warning for the unknown rule
499475
let signal = DiagnosticSignal::new(move || match group_rule {
500476
Some((group, rule)) => SuppressionDiagnostic::new(
501-
file_id,
502477
category!("suppressions/unknownRule"),
503478
range,
504479
format_args!("Unknown lint rule {group}/{rule} in suppression comment"),
505480
),
506481

507482
None => SuppressionDiagnostic::new(
508-
file_id,
509483
category!("suppressions/unknownGroup"),
510484
range,
511485
format_args!("Unknown lint rule group {rule} in suppression comment"),
@@ -527,17 +501,15 @@ where
527501
if has_legacy && range_match(self.range, range) {
528502
let signal = DiagnosticSignal::new(move || {
529503
SuppressionDiagnostic::new(
530-
file_id,
531504
category!("suppressions/deprecatedSyntax"),
532505
range,
533506
"Suppression is using a deprecated syntax",
534507
)
535508
.with_tags(DiagnosticTags::DEPRECATED_CODE)
536509
});
537510

538-
let signal = signal.with_action(|| {
539-
update_suppression(file_id, self.root, token, is_leading, index, text)
540-
});
511+
let signal = signal
512+
.with_action(|| update_suppression(self.root, token, is_leading, index, text));
541513

542514
(self.emit_signal)(&signal)?;
543515
}
@@ -642,7 +614,6 @@ pub enum SuppressionKind<'a> {
642614
}
643615

644616
fn update_suppression<L: Language>(
645-
file_id: FileId,
646617
root: &L::Root,
647618
token: &SyntaxToken<L>,
648619
is_leading: bool,
@@ -687,7 +658,6 @@ fn update_suppression<L: Language>(
687658

688659
Some(AnalyzerAction {
689660
rule_name: None,
690-
file_id,
691661
category: ActionCategory::QuickFix,
692662
applicability: Applicability::Always,
693663
message: markup! {

crates/rome_analyze/src/matcher.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::{
22
AnalyzerSignal, Phases, QueryMatch, Rule, RuleFilter, RuleGroup, ServiceBag,
33
SuppressionCommentEmitter,
44
};
5-
use rome_diagnostics::FileId;
65
use rome_rowan::{Language, TextRange};
76
use std::{
87
any::{Any, TypeId},
@@ -22,7 +21,6 @@ pub trait QueryMatcher<L: Language> {
2221
/// Parameters provided to [QueryMatcher::match_query] and require to run lint rules
2322
pub struct MatchQueryParams<'phase, 'query, L: Language> {
2423
pub phase: Phases,
25-
pub file_id: FileId,
2624
pub root: &'phase L::Root,
2725
pub query: Query,
2826
pub services: &'phase ServiceBag,
@@ -199,7 +197,7 @@ where
199197
mod tests {
200198
use std::convert::Infallible;
201199

202-
use rome_diagnostics::{category, location::FileId, DiagnosticExt};
200+
use rome_diagnostics::{category, DiagnosticExt};
203201
use rome_diagnostics::{Diagnostic, Severity};
204202
use rome_rowan::{
205203
raw_language::{RawLanguage, RawLanguageKind, RawLanguageRoot, RawSyntaxTreeBuilder},
@@ -220,8 +218,6 @@ mod tests {
220218
#[derive(Debug, Diagnostic)]
221219
#[diagnostic(category = "args/fileNotFound", message = "test_suppression")]
222220
struct TestDiagnostic {
223-
#[location(resource)]
224-
location: FileId,
225221
#[location(span)]
226222
span: TextRange,
227223
}
@@ -237,10 +233,7 @@ mod tests {
237233

238234
let span = node.text_trimmed_range();
239235
params.signal_queue.push(SignalEntry {
240-
signal: Box::new(DiagnosticSignal::new(move || TestDiagnostic {
241-
span,
242-
location: FileId::zero(),
243-
})),
236+
signal: Box::new(DiagnosticSignal::new(move || TestDiagnostic { span })),
244237
rule: RuleKey::new("group", "rule"),
245238
text_range: span,
246239
});
@@ -383,7 +376,6 @@ mod tests {
383376
analyzer.add_visitor(Phases::Syntax, Box::<SyntaxVisitor<RawLanguage>>::default());
384377

385378
let ctx: AnalyzerContext<RawLanguage> = AnalyzerContext {
386-
file_id: FileId::zero(),
387379
root,
388380
range: None,
389381
services: ServiceBag::default(),

crates/rome_analyze/src/registry.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,6 @@ impl<L: Language + Default> RegistryRule<L> {
441441
R::suppressed_nodes(&ctx, &result, &mut state.suppressions);
442442

443443
let signal = Box::new(RuleSignal::<R>::new(
444-
params.file_id,
445444
params.root,
446445
query_result.clone(),
447446
result,

crates/rome_analyze/src/signals.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
};
99
use rome_console::MarkupBuf;
1010
use rome_diagnostics::{
11-
advice::CodeSuggestionAdvice, location::FileId, Applicability, CodeSuggestion, Error, FileSpan,
11+
advice::CodeSuggestionAdvice, Applicability, CodeSuggestion, Error, FileSpan,
1212
};
1313
use rome_rowan::{BatchMutation, Language};
1414
use std::borrow::Cow;
@@ -89,7 +89,6 @@ where
8989
#[derive(Debug, Clone)]
9090
pub struct AnalyzerAction<L: Language> {
9191
pub rule_name: Option<(&'static str, &'static str)>,
92-
pub file_id: FileId,
9392
pub category: ActionCategory,
9493
pub applicability: Applicability,
9594
pub message: MarkupBuf,
@@ -133,10 +132,7 @@ impl<L: Language> From<AnalyzerAction<L>> for CodeSuggestionItem {
133132
rule_name: action.rule_name,
134133
category: action.category,
135134
suggestion: CodeSuggestion {
136-
span: FileSpan {
137-
file: action.file_id,
138-
range,
139-
},
135+
span: FileSpan { range },
140136
applicability: action.applicability,
141137
msg: action.message,
142138
suggestion,
@@ -243,7 +239,6 @@ impl<L: Language> AnalyzerActionIter<L> {
243239

244240
/// Analyzer-internal implementation of [AnalyzerSignal] for a specific [Rule](crate::registry::Rule)
245241
pub(crate) struct RuleSignal<'phase, R: Rule> {
246-
file_id: FileId,
247242
root: &'phase RuleRoot<R>,
248243
query_result: <<R as Rule>::Query as Queryable>::Output,
249244
state: R::State,
@@ -257,7 +252,6 @@ where
257252
R: Rule + 'static,
258253
{
259254
pub(crate) fn new(
260-
file_id: FileId,
261255
root: &'phase RuleRoot<R>,
262256
query_result: <<R as Rule>::Query as Queryable>::Output,
263257
state: R::State,
@@ -267,7 +261,6 @@ where
267261
>,
268262
) -> Self {
269263
Self {
270-
file_id,
271264
root,
272265
query_result,
273266
state,
@@ -294,7 +287,6 @@ where
294287
if let Some(action) = R::action(&ctx, &self.state) {
295288
actions.push(AnalyzerAction {
296289
rule_name: Some((<R::Group as RuleGroup>::NAME, R::METADATA.name)),
297-
file_id: self.file_id,
298290
category: action.category,
299291
applicability: action.applicability,
300292
mutation: action.mutation,
@@ -307,7 +299,6 @@ where
307299
{
308300
let action = AnalyzerAction {
309301
rule_name: Some((<R::Group as RuleGroup>::NAME, R::METADATA.name)),
310-
file_id: self.file_id,
311302
category: ActionCategory::Other(Cow::Borrowed(SUPPRESSION_ACTION_CATEGORY)),
312303
applicability: Applicability::Always,
313304
mutation: suppression_action.mutation,

crates/rome_analyze/src/syntax.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,11 @@ impl<L: Language + 'static> Visitor for SyntaxVisitor<L> {
9393
#[cfg(test)]
9494
mod tests {
9595

96-
use std::convert::Infallible;
97-
98-
use rome_diagnostics::location::FileId;
9996
use rome_rowan::{
10097
raw_language::{RawLanguage, RawLanguageKind, RawLanguageRoot, RawSyntaxTreeBuilder},
10198
AstNode, SyntaxNode,
10299
};
100+
use std::convert::Infallible;
103101

104102
use crate::{
105103
matcher::MatchQueryParams, registry::Phases, Analyzer, AnalyzerContext, AnalyzerOptions,
@@ -164,7 +162,6 @@ mod tests {
164162
analyzer.add_visitor(Phases::Syntax, Box::<SyntaxVisitor<RawLanguage>>::default());
165163

166164
let ctx: AnalyzerContext<RawLanguage> = AnalyzerContext {
167-
file_id: FileId::zero(),
168165
root,
169166
range: None,
170167
services: ServiceBag::default(),

crates/rome_analyze/src/visitor.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::collections::BinaryHeap;
22

3-
use rome_diagnostics::location::FileId;
43
use rome_rowan::{AstNode, Language, SyntaxNode, TextRange, WalkEvent};
54

65
use crate::{
@@ -12,7 +11,6 @@ use crate::{
1211
/// Mutable context objects shared by all visitors
1312
pub struct VisitorContext<'phase, 'query, L: Language> {
1413
pub phase: Phases,
15-
pub file_id: FileId,
1614
pub root: &'phase LanguageRoot<L>,
1715
pub services: &'phase ServiceBag,
1816
pub range: Option<TextRange>,
@@ -25,7 +23,6 @@ impl<'phase, 'query, L: Language> VisitorContext<'phase, 'query, L> {
2523
pub fn match_query<T: QueryMatch>(&mut self, query: T) {
2624
self.query_matcher.match_query(MatchQueryParams {
2725
phase: self.phase,
28-
file_id: self.file_id,
2926
root: self.root,
3027
query: Query::new(query),
3128
services: self.services,

0 commit comments

Comments
 (0)