Skip to content

fix: change handling #167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions crates/pg_analyse/src/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl<'analysis> AnalysisFilter<'analysis> {
/// Return `true` if the group `G` matches this filter
pub fn match_group<G: RuleGroup>(&self) -> bool {
self.match_category::<G::Category>()
&& self.enabled_rules.map_or(true, |enabled_rules| {
&& self.enabled_rules.is_none_or(|enabled_rules| {
enabled_rules.iter().any(|filter| filter.match_group::<G>())
})
&& !self
Expand All @@ -54,7 +54,7 @@ impl<'analysis> AnalysisFilter<'analysis> {
/// Return `true` if the rule `R` matches this filter
pub fn match_rule<R: Rule>(&self) -> bool {
self.match_category::<<R::Group as RuleGroup>::Category>()
&& self.enabled_rules.map_or(true, |enabled_rules| {
&& self.enabled_rules.is_none_or(|enabled_rules| {
enabled_rules.iter().any(|filter| filter.match_rule::<R>())
})
&& !self
Expand Down Expand Up @@ -94,13 +94,13 @@ impl<'a> RuleFilter<'a> {
}
}

impl<'a> Debug for RuleFilter<'a> {
impl Debug for RuleFilter<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Display::fmt(self, f)
}
}

impl<'a> Display for RuleFilter<'a> {
impl Display for RuleFilter<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
RuleFilter::Group(group) => {
Expand All @@ -113,7 +113,7 @@ impl<'a> Display for RuleFilter<'a> {
}
}

impl<'a> pg_console::fmt::Display for RuleFilter<'a> {
impl pg_console::fmt::Display for RuleFilter<'_> {
fn fmt(&self, fmt: &mut pg_console::fmt::Formatter) -> std::io::Result<()> {
match self {
RuleFilter::Group(group) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/pg_cli/src/commands/daemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub(crate) fn read_most_recent_log_file(

let most_recent = fs::read_dir(biome_log_path)?
.flatten()
.filter(|file| file.file_type().map_or(false, |ty| ty.is_file()))
.filter(|file| file.file_type().is_ok_and(|ty| ty.is_file()))
.filter_map(|file| {
match file
.file_name()
Expand Down
2 changes: 1 addition & 1 deletion crates/pg_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ impl PgLspCommand {

pub fn is_verbose(&self) -> bool {
self.cli_options()
.map_or(false, |cli_options| cli_options.verbose)
.is_some_and(|cli_options| cli_options.verbose)
}

pub fn log_level(&self) -> LoggingLevel {
Expand Down
4 changes: 2 additions & 2 deletions crates/pg_cli/src/execute/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ pub(crate) struct TraversalOptions<'ctx, 'app> {
pub(crate) evaluated_paths: RwLock<BTreeSet<PgLspPath>>,
}

impl<'ctx, 'app> TraversalOptions<'ctx, 'app> {
impl TraversalOptions<'_, '_> {
pub(crate) fn increment_changed(&self, path: &PgLspPath) {
self.changed.fetch_add(1, Ordering::Relaxed);
self.evaluated_paths
Expand Down Expand Up @@ -441,7 +441,7 @@ impl<'ctx, 'app> TraversalOptions<'ctx, 'app> {
}
}

impl<'ctx, 'app> TraversalContext for TraversalOptions<'ctx, 'app> {
impl TraversalContext for TraversalOptions<'_, '_> {
fn interner(&self) -> &PathInterner {
&self.interner
}
Expand Down
2 changes: 1 addition & 1 deletion crates/pg_cli/src/reporter/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl Reporter for GithubReporter {
}
pub(crate) struct GithubReporterVisitor<'a>(pub(crate) &'a mut dyn Console);

impl<'a> ReporterVisitor for GithubReporterVisitor<'a> {
impl ReporterVisitor for GithubReporterVisitor<'_> {
fn report_summary(
&mut self,
_execution: &Execution,
Expand Down
6 changes: 3 additions & 3 deletions crates/pg_cli/src/reporter/gitlab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<'a> GitLabReporterVisitor<'a> {
}
}

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

impl<'a> GitLabDiagnostics<'a> {
impl GitLabDiagnostics<'_> {
fn attempt_to_relativize(&self, subject: &str) -> Option<PathBuf> {
let Ok(resolved) = Path::new(subject).absolutize() else {
return None;
Expand Down Expand Up @@ -116,7 +116,7 @@ impl<'a> GitLabDiagnostics<'a> {
}
}

impl<'a> Display for GitLabDiagnostics<'a> {
impl Display for GitLabDiagnostics<'_> {
fn fmt(&self, fmt: &mut Formatter) -> std::io::Result<()> {
let mut hasher = self.1.write().unwrap();
let gitlab_diagnostics: Vec<_> = self
Expand Down
4 changes: 2 additions & 2 deletions crates/pg_cli/src/reporter/junit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct JunitDiagnostic<'a> {
diagnostic: &'a Error,
}

impl<'a> Display for JunitDiagnostic<'a> {
impl Display for JunitDiagnostic<'_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
self.diagnostic.description(f)
}
Expand All @@ -39,7 +39,7 @@ impl<'a> JunitReporterVisitor<'a> {
}
}

impl<'a> ReporterVisitor for JunitReporterVisitor<'a> {
impl ReporterVisitor for JunitReporterVisitor<'_> {
fn report_summary(
&mut self,
_execution: &Execution,
Expand Down
8 changes: 4 additions & 4 deletions crates/pg_cli/src/reporter/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct FixedPathsDiagnostic {

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

impl<'a> ReporterVisitor for ConsoleReporterVisitor<'a> {
impl ReporterVisitor for ConsoleReporterVisitor<'_> {
fn report_summary(
&mut self,
execution: &Execution,
Expand Down Expand Up @@ -132,7 +132,7 @@ impl fmt::Display for Files {

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

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

impl<'a> fmt::Display for SummaryTotal<'a> {
impl fmt::Display for SummaryTotal<'_> {
fn fmt(&self, fmt: &mut Formatter) -> io::Result<()> {
let files = Files(self.1);
match self.0 {
Expand All @@ -165,7 +165,7 @@ pub(crate) struct ConsoleTraversalSummary<'a>(
pub(crate) &'a TraversalMode,
pub(crate) &'a TraversalSummary,
);
impl<'a> fmt::Display for ConsoleTraversalSummary<'a> {
impl fmt::Display for ConsoleTraversalSummary<'_> {
fn fmt(&self, fmt: &mut Formatter) -> io::Result<()> {
let summary = SummaryTotal(self.0, self.1.changed + self.1.unchanged, &self.1.duration);
let detail = SummaryDetail(self.0, self.1.changed);
Expand Down
1 change: 1 addition & 0 deletions crates/pg_completions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ async-std = "1.12.0"

text-size.workspace = true


pg_schema_cache.workspace = true
pg_treesitter_queries.workspace = true
serde = { workspace = true, features = ["derive"] }
Expand Down
4 changes: 2 additions & 2 deletions crates/pg_completions/src/relevance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub(crate) enum CompletionRelevanceData<'a> {
Column(&'a pg_schema_cache::Column),
}

impl<'a> CompletionRelevanceData<'a> {
impl CompletionRelevanceData<'_> {
pub fn get_score(self, ctx: &CompletionContext) -> i32 {
CompletionRelevance::from(self).into_score(ctx)
}
Expand All @@ -28,7 +28,7 @@ pub(crate) struct CompletionRelevance<'a> {
data: CompletionRelevanceData<'a>,
}

impl<'a> CompletionRelevance<'a> {
impl CompletionRelevance<'_> {
pub fn into_score(mut self, ctx: &CompletionContext) -> i32 {
self.check_matches_schema(ctx);
self.check_matches_query_input(ctx);
Expand Down
2 changes: 1 addition & 1 deletion crates/pg_configuration/src/analyser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ impl serde::Serialize for RuleSelector {
impl<'de> serde::Deserialize<'de> for RuleSelector {
fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
struct Visitor;
impl<'de> serde::de::Visitor<'de> for Visitor {
impl serde::de::Visitor<'_> for Visitor {
type Value = RuleSelector;
fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
formatter.write_str("<group>/<ruyle_name>")
Expand Down
6 changes: 3 additions & 3 deletions crates/pg_flags/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ impl PgLspEnv {
fn new() -> Self {
Self {
pglsp_log_path: PgLspEnvVariable::new(
"BIOME_LOG_PATH",
"PGLSP_LOG_PATH",
"The directory where the Daemon logs will be saved.",
),
pglsp_log_prefix: PgLspEnvVariable::new(
"BIOME_LOG_PREFIX_NAME",
"PGLSP_LOG_PREFIX_NAME",
"A prefix that's added to the name of the log. Default: `server.log.`",
),
pglsp_config_path: PgLspEnvVariable::new(
"BIOME_CONFIG_PATH",
"PGLSP_CONFIG_PATH",
"A path to the configuration file",
),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/pg_lsp_new/src/handlers/text_document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use pg_workspace_new::workspace::{
ChangeFileParams, ChangeParams, CloseFileParams, GetFileContentParams, OpenFileParams,
};
use tower_lsp::lsp_types;
use tracing::{error, field, info};
use tracing::{error, field};

/// Handler for `textDocument/didOpen` LSP notification
#[tracing::instrument(
Expand Down
7 changes: 3 additions & 4 deletions crates/pg_query_ext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ pub fn parse(sql: &str) -> Result<NodeEnum> {
.nodes()
.iter()
.find(|n| n.1 == 1)
.unwrap()
.0
.to_enum()
})
.map(|n| n.0.to_enum())
.ok_or_else(|| Error::Parse("Unable to find root node".to_string()))
Comment on lines +29 to +30
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I am not even sure why this is an issue. my assumption was that if pg_query parses something it always has at least one node, but that does not seem to be the case.)

})?
}
5 changes: 5 additions & 0 deletions crates/pg_statement_splitter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ mod tests {
assert_eq!(*expected, self.input[*range].to_string());
}

assert!(
self.parse.ranges.is_sorted_by_key(|r| r.start()),
"Ranges are not sorted"
);

self
}

Expand Down
4 changes: 2 additions & 2 deletions crates/pg_statement_splitter/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,6 @@ impl Parser {
}

fn is_irrelevant_token(t: &Token) -> bool {
return WHITESPACE_TOKENS.contains(&t.kind)
&& (t.kind != SyntaxKind::Newline || t.text.chars().count() == 1);
WHITESPACE_TOKENS.contains(&t.kind)
&& (t.kind != SyntaxKind::Newline || t.text.chars().count() == 1)
}
2 changes: 1 addition & 1 deletion crates/pg_syntax/src/statement_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ struct Ancestors<'a> {
current_node: NodeIndex<DefaultIx>,
}

impl<'a> Iterator for Ancestors<'a> {
impl Iterator for Ancestors<'_> {
type Item = NodeIndex<DefaultIx>;

fn next(&mut self) -> Option<Self::Item> {
Expand Down
5 changes: 2 additions & 3 deletions crates/pg_type_resolver/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn resolve_type(node: &pg_query_ext::NodeEnum, schema_cache: &SchemaCache) -
.types
.iter()
.filter(|t| {
types.iter().any(|i| &i == &&t.name) && t.schema == "pg_catalog"
types.iter().any(|i| i == &t.name) && t.schema == "pg_catalog"
})
.map(|t| t.id)
.collect(),
Expand Down Expand Up @@ -63,8 +63,7 @@ pub fn resolve_type(node: &pg_query_ext::NodeEnum, schema_cache: &SchemaCache) -
.types
.iter()
.filter(|t| {
(types.iter().any(|i| &i == &&t.name)
&& t.schema == "pg_catalog")
(types.iter().any(|i| i == &t.name) && t.schema == "pg_catalog")
|| t.enums.values.contains(&v.sval)
})
.map(|t| t.id)
Expand Down
10 changes: 5 additions & 5 deletions crates/pg_workspace_new/src/dome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,27 @@ pub struct DomeIterator<'a> {

impl<'a> DomeIterator<'a> {
pub fn next_config(&mut self) -> Option<&'a PgLspPath> {
return if let Some(path) = self.iter.peek() {
if let Some(path) = self.iter.peek() {
if path.is_config() {
self.iter.next()
} else {
None
}
} else {
None
};
}
}

pub fn next_ignore(&mut self) -> Option<&'a PgLspPath> {
return if let Some(path) = self.iter.peek() {
if let Some(path) = self.iter.peek() {
if path.is_ignore() {
self.iter.next()
} else {
None
}
} else {
None
};
}
}
}

Expand All @@ -69,4 +69,4 @@ impl<'a> Iterator for DomeIterator<'a> {
}
}

impl<'a> FusedIterator for DomeIterator<'a> {}
impl FusedIterator for DomeIterator<'_> {}
9 changes: 4 additions & 5 deletions crates/pg_workspace_new/src/matcher/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl Pattern {
tokens.push(AnyRecursiveSequence);
} else {
// A pattern is absolute if it starts with a path separator, eg. "/home" or "\\?\C:\Users"
let mut is_absolute = chars.first().map_or(false, |c| path::is_separator(*c));
let mut is_absolute = chars.first().is_some_and(|c| path::is_separator(*c));

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes come from the lint in the justfile, right? awesome!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! I don't know why they weren't already reported in a prev pr though.

}

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

/// Access the original glob pattern.
Expand Down Expand Up @@ -551,7 +550,7 @@ fn chars_eq(a: char, b: char, case_sensitive: bool) -> bool {
true
} else if !case_sensitive && a.is_ascii() && b.is_ascii() {
// FIXME: work with non-ascii chars properly (issue #9084)
a.to_ascii_lowercase() == b.to_ascii_lowercase()
a.eq_ignore_ascii_case(&b)
} else {
a == b
}
Expand Down
4 changes: 2 additions & 2 deletions crates/pg_workspace_new/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<'a> SettingsHandle<'a> {
}
}

impl<'a> AsRef<Settings> for SettingsHandle<'a> {
impl AsRef<Settings> for SettingsHandle<'_> {
fn as_ref(&self) -> &Settings {
&self.inner
}
Expand All @@ -62,7 +62,7 @@ impl<'a> SettingsHandleMut<'a> {
}
}

impl<'a> AsMut<Settings> for SettingsHandleMut<'a> {
impl AsMut<Settings> for SettingsHandleMut<'_> {
fn as_mut(&mut self) -> &mut Settings {
&mut self.inner
}
Expand Down
2 changes: 1 addition & 1 deletion crates/pg_workspace_new/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl<'app, W: Workspace + ?Sized> FileGuard<'app, W> {
// }
}

impl<'app, W: Workspace + ?Sized> Drop for FileGuard<'app, W> {
impl<W: Workspace + ?Sized> Drop for FileGuard<'_, W> {
fn drop(&mut self) {
self.workspace
.close_file(CloseFileParams {
Expand Down
Loading
Loading