Skip to content

Commit 20ee92b

Browse files
authored
fix: change handling (#167)
* lets get into the mess... * woooorks now and its much simpler * fix: minor fixes * fix: lint --fix * format * format * pssssssht * fixes
1 parent c509dd6 commit 20ee92b

File tree

29 files changed

+583
-568
lines changed

29 files changed

+583
-568
lines changed

crates/pg_analyse/src/filter.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl<'analysis> AnalysisFilter<'analysis> {
4242
/// Return `true` if the group `G` matches this filter
4343
pub fn match_group<G: RuleGroup>(&self) -> bool {
4444
self.match_category::<G::Category>()
45-
&& self.enabled_rules.map_or(true, |enabled_rules| {
45+
&& self.enabled_rules.is_none_or(|enabled_rules| {
4646
enabled_rules.iter().any(|filter| filter.match_group::<G>())
4747
})
4848
&& !self
@@ -54,7 +54,7 @@ impl<'analysis> AnalysisFilter<'analysis> {
5454
/// Return `true` if the rule `R` matches this filter
5555
pub fn match_rule<R: Rule>(&self) -> bool {
5656
self.match_category::<<R::Group as RuleGroup>::Category>()
57-
&& self.enabled_rules.map_or(true, |enabled_rules| {
57+
&& self.enabled_rules.is_none_or(|enabled_rules| {
5858
enabled_rules.iter().any(|filter| filter.match_rule::<R>())
5959
})
6060
&& !self
@@ -94,13 +94,13 @@ impl<'a> RuleFilter<'a> {
9494
}
9595
}
9696

97-
impl<'a> Debug for RuleFilter<'a> {
97+
impl Debug for RuleFilter<'_> {
9898
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
9999
Display::fmt(self, f)
100100
}
101101
}
102102

103-
impl<'a> Display for RuleFilter<'a> {
103+
impl Display for RuleFilter<'_> {
104104
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
105105
match self {
106106
RuleFilter::Group(group) => {
@@ -113,7 +113,7 @@ impl<'a> Display for RuleFilter<'a> {
113113
}
114114
}
115115

116-
impl<'a> pg_console::fmt::Display for RuleFilter<'a> {
116+
impl pg_console::fmt::Display for RuleFilter<'_> {
117117
fn fmt(&self, fmt: &mut pg_console::fmt::Formatter) -> std::io::Result<()> {
118118
match self {
119119
RuleFilter::Group(group) => {

crates/pg_cli/src/commands/daemon.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ pub(crate) fn read_most_recent_log_file(
180180

181181
let most_recent = fs::read_dir(biome_log_path)?
182182
.flatten()
183-
.filter(|file| file.file_type().map_or(false, |ty| ty.is_file()))
183+
.filter(|file| file.file_type().is_ok_and(|ty| ty.is_file()))
184184
.filter_map(|file| {
185185
match file
186186
.file_name()

crates/pg_cli/src/commands/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl PgLspCommand {
230230

231231
pub fn is_verbose(&self) -> bool {
232232
self.cli_options()
233-
.map_or(false, |cli_options| cli_options.verbose)
233+
.is_some_and(|cli_options| cli_options.verbose)
234234
}
235235

236236
pub fn log_level(&self) -> LoggingLevel {

crates/pg_cli/src/execute/traverse.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ pub(crate) struct TraversalOptions<'ctx, 'app> {
413413
pub(crate) evaluated_paths: RwLock<BTreeSet<PgLspPath>>,
414414
}
415415

416-
impl<'ctx, 'app> TraversalOptions<'ctx, 'app> {
416+
impl TraversalOptions<'_, '_> {
417417
pub(crate) fn increment_changed(&self, path: &PgLspPath) {
418418
self.changed.fetch_add(1, Ordering::Relaxed);
419419
self.evaluated_paths
@@ -441,7 +441,7 @@ impl<'ctx, 'app> TraversalOptions<'ctx, 'app> {
441441
}
442442
}
443443

444-
impl<'ctx, 'app> TraversalContext for TraversalOptions<'ctx, 'app> {
444+
impl TraversalContext for TraversalOptions<'_, '_> {
445445
fn interner(&self) -> &PathInterner {
446446
&self.interner
447447
}

crates/pg_cli/src/reporter/github.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl Reporter for GithubReporter {
1616
}
1717
pub(crate) struct GithubReporterVisitor<'a>(pub(crate) &'a mut dyn Console);
1818

19-
impl<'a> ReporterVisitor for GithubReporterVisitor<'a> {
19+
impl ReporterVisitor for GithubReporterVisitor<'_> {
2020
fn report_summary(
2121
&mut self,
2222
_execution: &Execution,

crates/pg_cli/src/reporter/gitlab.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'a> GitLabReporterVisitor<'a> {
5757
}
5858
}
5959

60-
impl<'a> ReporterVisitor for GitLabReporterVisitor<'a> {
60+
impl ReporterVisitor for GitLabReporterVisitor<'_> {
6161
fn report_summary(&mut self, _: &Execution, _: TraversalSummary) -> std::io::Result<()> {
6262
Ok(())
6363
}
@@ -80,7 +80,7 @@ struct GitLabDiagnostics<'a>(
8080
Option<&'a Path>,
8181
);
8282

83-
impl<'a> GitLabDiagnostics<'a> {
83+
impl GitLabDiagnostics<'_> {
8484
fn attempt_to_relativize(&self, subject: &str) -> Option<PathBuf> {
8585
let Ok(resolved) = Path::new(subject).absolutize() else {
8686
return None;
@@ -116,7 +116,7 @@ impl<'a> GitLabDiagnostics<'a> {
116116
}
117117
}
118118

119-
impl<'a> Display for GitLabDiagnostics<'a> {
119+
impl Display for GitLabDiagnostics<'_> {
120120
fn fmt(&self, fmt: &mut Formatter) -> std::io::Result<()> {
121121
let mut hasher = self.1.write().unwrap();
122122
let gitlab_diagnostics: Vec<_> = self

crates/pg_cli/src/reporter/junit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct JunitDiagnostic<'a> {
2424
diagnostic: &'a Error,
2525
}
2626

27-
impl<'a> Display for JunitDiagnostic<'a> {
27+
impl Display for JunitDiagnostic<'_> {
2828
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
2929
self.diagnostic.description(f)
3030
}
@@ -39,7 +39,7 @@ impl<'a> JunitReporterVisitor<'a> {
3939
}
4040
}
4141

42-
impl<'a> ReporterVisitor for JunitReporterVisitor<'a> {
42+
impl ReporterVisitor for JunitReporterVisitor<'_> {
4343
fn report_summary(
4444
&mut self,
4545
_execution: &Execution,

crates/pg_cli/src/reporter/terminal.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct FixedPathsDiagnostic {
5353

5454
pub(crate) struct ConsoleReporterVisitor<'a>(pub(crate) &'a mut dyn Console);
5555

56-
impl<'a> ReporterVisitor for ConsoleReporterVisitor<'a> {
56+
impl ReporterVisitor for ConsoleReporterVisitor<'_> {
5757
fn report_summary(
5858
&mut self,
5959
execution: &Execution,
@@ -132,7 +132,7 @@ impl fmt::Display for Files {
132132

133133
struct SummaryDetail<'a>(pub(crate) &'a TraversalMode, usize);
134134

135-
impl<'a> fmt::Display for SummaryDetail<'a> {
135+
impl fmt::Display for SummaryDetail<'_> {
136136
fn fmt(&self, fmt: &mut Formatter) -> io::Result<()> {
137137
if self.1 > 0 {
138138
fmt.write_markup(markup! {
@@ -147,7 +147,7 @@ impl<'a> fmt::Display for SummaryDetail<'a> {
147147
}
148148
struct SummaryTotal<'a>(&'a TraversalMode, usize, &'a Duration);
149149

150-
impl<'a> fmt::Display for SummaryTotal<'a> {
150+
impl fmt::Display for SummaryTotal<'_> {
151151
fn fmt(&self, fmt: &mut Formatter) -> io::Result<()> {
152152
let files = Files(self.1);
153153
match self.0 {
@@ -165,7 +165,7 @@ pub(crate) struct ConsoleTraversalSummary<'a>(
165165
pub(crate) &'a TraversalMode,
166166
pub(crate) &'a TraversalSummary,
167167
);
168-
impl<'a> fmt::Display for ConsoleTraversalSummary<'a> {
168+
impl fmt::Display for ConsoleTraversalSummary<'_> {
169169
fn fmt(&self, fmt: &mut Formatter) -> io::Result<()> {
170170
let summary = SummaryTotal(self.0, self.1.changed + self.1.unchanged, &self.1.duration);
171171
let detail = SummaryDetail(self.0, self.1.changed);

crates/pg_completions/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ async-std = "1.12.0"
1616

1717
text-size.workspace = true
1818

19+
1920
pg_schema_cache.workspace = true
2021
pg_treesitter_queries.workspace = true
2122
serde = { workspace = true, features = ["derive"] }

crates/pg_completions/src/relevance.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(crate) enum CompletionRelevanceData<'a> {
77
Column(&'a pg_schema_cache::Column),
88
}
99

10-
impl<'a> CompletionRelevanceData<'a> {
10+
impl CompletionRelevanceData<'_> {
1111
pub fn get_score(self, ctx: &CompletionContext) -> i32 {
1212
CompletionRelevance::from(self).into_score(ctx)
1313
}
@@ -28,7 +28,7 @@ pub(crate) struct CompletionRelevance<'a> {
2828
data: CompletionRelevanceData<'a>,
2929
}
3030

31-
impl<'a> CompletionRelevance<'a> {
31+
impl CompletionRelevance<'_> {
3232
pub fn into_score(mut self, ctx: &CompletionContext) -> i32 {
3333
self.check_matches_schema(ctx);
3434
self.check_matches_query_input(ctx);

crates/pg_configuration/src/analyser/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ impl serde::Serialize for RuleSelector {
362362
impl<'de> serde::Deserialize<'de> for RuleSelector {
363363
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
364364
struct Visitor;
365-
impl<'de> serde::de::Visitor<'de> for Visitor {
365+
impl serde::de::Visitor<'_> for Visitor {
366366
type Value = RuleSelector;
367367
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
368368
formatter.write_str("<group>/<ruyle_name>")

crates/pg_flags/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ impl PgLspEnv {
2626
fn new() -> Self {
2727
Self {
2828
pglsp_log_path: PgLspEnvVariable::new(
29-
"BIOME_LOG_PATH",
29+
"PGLSP_LOG_PATH",
3030
"The directory where the Daemon logs will be saved.",
3131
),
3232
pglsp_log_prefix: PgLspEnvVariable::new(
33-
"BIOME_LOG_PREFIX_NAME",
33+
"PGLSP_LOG_PREFIX_NAME",
3434
"A prefix that's added to the name of the log. Default: `server.log.`",
3535
),
3636
pglsp_config_path: PgLspEnvVariable::new(
37-
"BIOME_CONFIG_PATH",
37+
"PGLSP_CONFIG_PATH",
3838
"A path to the configuration file",
3939
),
4040
}

crates/pg_lsp_new/src/handlers/text_document.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use pg_workspace_new::workspace::{
55
ChangeFileParams, ChangeParams, CloseFileParams, GetFileContentParams, OpenFileParams,
66
};
77
use tower_lsp::lsp_types;
8-
use tracing::{error, field, info};
8+
use tracing::{error, field};
99

1010
/// Handler for `textDocument/didOpen` LSP notification
1111
#[tracing::instrument(

crates/pg_query_ext/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ pub fn parse(sql: &str) -> Result<NodeEnum> {
2626
.nodes()
2727
.iter()
2828
.find(|n| n.1 == 1)
29-
.unwrap()
30-
.0
31-
.to_enum()
32-
})
29+
.map(|n| n.0.to_enum())
30+
.ok_or_else(|| Error::Parse("Unable to find root node".to_string()))
31+
})?
3332
}

crates/pg_statement_splitter/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ mod tests {
5656
assert_eq!(*expected, self.input[*range].to_string());
5757
}
5858

59+
assert!(
60+
self.parse.ranges.is_sorted_by_key(|r| r.start()),
61+
"Ranges are not sorted"
62+
);
63+
5964
self
6065
}
6166

crates/pg_statement_splitter/src/parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,6 @@ impl Parser {
186186
}
187187

188188
fn is_irrelevant_token(t: &Token) -> bool {
189-
return WHITESPACE_TOKENS.contains(&t.kind)
190-
&& (t.kind != SyntaxKind::Newline || t.text.chars().count() == 1);
189+
WHITESPACE_TOKENS.contains(&t.kind)
190+
&& (t.kind != SyntaxKind::Newline || t.text.chars().count() == 1)
191191
}

crates/pg_syntax/src/statement_parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ struct Ancestors<'a> {
435435
current_node: NodeIndex<DefaultIx>,
436436
}
437437

438-
impl<'a> Iterator for Ancestors<'a> {
438+
impl Iterator for Ancestors<'_> {
439439
type Item = NodeIndex<DefaultIx>;
440440

441441
fn next(&mut self) -> Option<Self::Item> {

crates/pg_type_resolver/src/types.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub fn resolve_type(node: &pg_query_ext::NodeEnum, schema_cache: &SchemaCache) -
2727
.types
2828
.iter()
2929
.filter(|t| {
30-
types.iter().any(|i| &i == &&t.name) && t.schema == "pg_catalog"
30+
types.iter().any(|i| i == &t.name) && t.schema == "pg_catalog"
3131
})
3232
.map(|t| t.id)
3333
.collect(),
@@ -63,8 +63,7 @@ pub fn resolve_type(node: &pg_query_ext::NodeEnum, schema_cache: &SchemaCache) -
6363
.types
6464
.iter()
6565
.filter(|t| {
66-
(types.iter().any(|i| &i == &&t.name)
67-
&& t.schema == "pg_catalog")
66+
(types.iter().any(|i| i == &t.name) && t.schema == "pg_catalog")
6867
|| t.enums.values.contains(&v.sval)
6968
})
7069
.map(|t| t.id)

crates/pg_workspace_new/src/dome.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,27 @@ pub struct DomeIterator<'a> {
3737

3838
impl<'a> DomeIterator<'a> {
3939
pub fn next_config(&mut self) -> Option<&'a PgLspPath> {
40-
return if let Some(path) = self.iter.peek() {
40+
if let Some(path) = self.iter.peek() {
4141
if path.is_config() {
4242
self.iter.next()
4343
} else {
4444
None
4545
}
4646
} else {
4747
None
48-
};
48+
}
4949
}
5050

5151
pub fn next_ignore(&mut self) -> Option<&'a PgLspPath> {
52-
return if let Some(path) = self.iter.peek() {
52+
if let Some(path) = self.iter.peek() {
5353
if path.is_ignore() {
5454
self.iter.next()
5555
} else {
5656
None
5757
}
5858
} else {
5959
None
60-
};
60+
}
6161
}
6262
}
6363

@@ -69,4 +69,4 @@ impl<'a> Iterator for DomeIterator<'a> {
6969
}
7070
}
7171

72-
impl<'a> FusedIterator for DomeIterator<'a> {}
72+
impl FusedIterator for DomeIterator<'_> {}

crates/pg_workspace_new/src/matcher/pattern.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl Pattern {
149149
tokens.push(AnyRecursiveSequence);
150150
} else {
151151
// A pattern is absolute if it starts with a path separator, eg. "/home" or "\\?\C:\Users"
152-
let mut is_absolute = chars.first().map_or(false, |c| path::is_separator(*c));
152+
let mut is_absolute = chars.first().is_some_and(|c| path::is_separator(*c));
153153

154154
// On windows a pattern may also be absolute if it starts with a
155155
// drive letter, a colon and a separator, eg. "c:/Users" or "G:\Users"
@@ -368,7 +368,7 @@ impl Pattern {
368368
/// `Pattern` using the default match options (i.e. `MatchOptions::new()`).
369369
pub fn matches_path(&self, path: &Path) -> bool {
370370
// FIXME (#9639): This needs to handle non-utf8 paths
371-
path.to_str().map_or(false, |s| self.matches(s))
371+
path.to_str().is_some_and(|s| self.matches(s))
372372
}
373373

374374
/// Return if the given `str` matches this `Pattern` using the specified
@@ -381,8 +381,7 @@ impl Pattern {
381381
/// `Pattern` using the specified match options.
382382
pub fn matches_path_with(&self, path: &Path, options: MatchOptions) -> bool {
383383
// FIXME (#9639): This needs to handle non-utf8 paths
384-
path.to_str()
385-
.map_or(false, |s| self.matches_with(s, options))
384+
path.to_str().is_some_and(|s| self.matches_with(s, options))
386385
}
387386

388387
/// Access the original glob pattern.
@@ -551,7 +550,7 @@ fn chars_eq(a: char, b: char, case_sensitive: bool) -> bool {
551550
true
552551
} else if !case_sensitive && a.is_ascii() && b.is_ascii() {
553552
// FIXME: work with non-ascii chars properly (issue #9084)
554-
a.to_ascii_lowercase() == b.to_ascii_lowercase()
553+
a.eq_ignore_ascii_case(&b)
555554
} else {
556555
a == b
557556
}

crates/pg_workspace_new/src/settings.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'a> SettingsHandle<'a> {
4848
}
4949
}
5050

51-
impl<'a> AsRef<Settings> for SettingsHandle<'a> {
51+
impl AsRef<Settings> for SettingsHandle<'_> {
5252
fn as_ref(&self) -> &Settings {
5353
&self.inner
5454
}
@@ -62,7 +62,7 @@ impl<'a> SettingsHandleMut<'a> {
6262
}
6363
}
6464

65-
impl<'a> AsMut<Settings> for SettingsHandleMut<'a> {
65+
impl AsMut<Settings> for SettingsHandleMut<'_> {
6666
fn as_mut(&mut self) -> &mut Settings {
6767
&mut self.inner
6868
}

crates/pg_workspace_new/src/workspace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ impl<'app, W: Workspace + ?Sized> FileGuard<'app, W> {
286286
// }
287287
}
288288

289-
impl<'app, W: Workspace + ?Sized> Drop for FileGuard<'app, W> {
289+
impl<W: Workspace + ?Sized> Drop for FileGuard<'_, W> {
290290
fn drop(&mut self) {
291291
self.workspace
292292
.close_file(CloseFileParams {

0 commit comments

Comments
 (0)