- Notifications
You must be signed in to change notification settings - Fork 107
cli ergonomics #172
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
cli ergonomics #172
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,3 @@ | ||
| use std::str::FromStr; | ||
| | ||
| use biome_deserialize_macros::{Merge, Partial}; | ||
| use bpaf::Bpaf; | ||
| use serde::{Deserialize, Serialize}; | ||
| | @@ -10,30 +8,10 @@ use serde::{Deserialize, Serialize}; | |
| #[partial(serde(rename_all = "snake_case", default, deny_unknown_fields))] | ||
| pub struct MigrationsConfiguration { | ||
| /// The directory where the migration files are stored | ||
| #[partial(bpaf(hide))] | ||
| pub migration_dir: Option<String>, | ||
| | ||
| /// The pattern used to store migration files | ||
| #[partial(bpaf(hide))] | ||
| pub migration_pattern: Option<MigrationPattern>, | ||
| } | ||
| | ||
| #[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize, Merge)] | ||
| pub enum MigrationPattern { | ||
| /// The migration files are stored in the root of the migration directory | ||
| Root, | ||
| /// The migration files are stored in a subdirectory of the migration directory | ||
| Subdirectory, | ||
| } | ||
| | ||
| impl FromStr for MigrationPattern { | ||
| type Err = String; | ||
| #[partial(bpaf(long("migrations-dir")))] | ||
| pub migrations_dir: String, | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know if we use bpaf-derive, but if we do, we could also parse into a Examples of that were hard to find, so maybe that's not the recommended way – I'm not sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that would be preferred, but | ||
| | ||
| fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
| match s { | ||
| "root" => Ok(Self::Root), | ||
| "subdirectory" => Ok(Self::Subdirectory), | ||
| _ => Err(format!("Invalid migration pattern: {}", s)), | ||
| } | ||
| } | ||
| /// Ignore any migrations before this timestamp | ||
| #[partial(bpaf(long("after")))] | ||
| pub after: u64, | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,10 @@ | ||
| use std::{fs, future::Future, panic::RefUnwindSafe, path::Path, sync::RwLock}; | ||
| use std::{ | ||
| fs, | ||
| future::Future, | ||
| panic::RefUnwindSafe, | ||
| path::{Path, PathBuf}, | ||
| sync::RwLock, | ||
| }; | ||
| | ||
| use analyser::AnalyserVisitorBuilder; | ||
| use change::StatementChange; | ||
| | @@ -33,6 +39,7 @@ use super::{ | |
| mod analyser; | ||
| mod change; | ||
| mod document; | ||
| mod migration; | ||
| mod pg_query; | ||
| mod tree_sitter; | ||
| | ||
| | @@ -150,13 +157,31 @@ impl WorkspaceServer { | |
| Ok(()) | ||
| } | ||
| | ||
| fn is_ignored_by_migration_config(&self, path: &Path) -> bool { | ||
| let set = self.settings(); | ||
| set.as_ref() | ||
| .migrations | ||
| .as_ref() | ||
| .and_then(|migration_settings| { | ||
| tracing::info!("Checking migration settings: {:?}", migration_settings); | ||
| let ignore_before = migration_settings.after.as_ref()?; | ||
| tracing::info!("Checking migration settings: {:?}", ignore_before); | ||
| let migrations_dir = migration_settings.path.as_ref()?; | ||
| tracing::info!("Checking migration settings: {:?}", migrations_dir); | ||
| let migration = migration::get_migration(path, migrations_dir)?; | ||
| | ||
| Some(&migration.timestamp <= ignore_before) | ||
| }) | ||
| .unwrap_or(false) | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if we pass a migrations_dir but no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, and we do not want to ignore any migration file if no | ||
| } | ||
| | ||
| /// Check whether a file is ignored in the top-level config `files.ignore`/`files.include` | ||
| fn is_ignored(&self, path: &Path) -> bool { | ||
| let file_name = path.file_name().and_then(|s| s.to_str()); | ||
| // Never ignore PGLSP's config file regardless `include`/`ignore` | ||
| (file_name != Some(ConfigName::pglsp_toml())) && | ||
| // Apply top-level `include`/`ignore | ||
| (self.is_ignored_by_top_level_config(path)) | ||
| (self.is_ignored_by_top_level_config(path) || self.is_ignored_by_migration_config(path)) | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. very sweet! | ||
| } | ||
| | ||
| /// Check whether a file is ignored in the top-level config `files.ignore`/`files.include` | ||
| | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here is the relevant part in
can_handle