-
Notifications
You must be signed in to change notification settings - Fork 81
Use etcetera instead of directories #1108
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
Open
lu-zero
wants to merge
1
commit into
liuchengxu:master
Choose a base branch
from
lu-zero:use-etcetera
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,81 @@ | ||
| use directories::{BaseDirs, ProjectDirs}; | ||
| use std::path::PathBuf; | ||
| use etcetera::app_strategy::choose_native_strategy; | ||
| use etcetera::{choose_app_strategy, AppStrategy, AppStrategyArgs}; | ||
| use std::path::{Path, PathBuf}; | ||
| use std::sync::OnceLock; | ||
|
|
||
| pub struct Dirs; | ||
|
|
||
| pub struct DirsProject { | ||
| home_dir: PathBuf, | ||
| config_dir: PathBuf, | ||
| cache_dir: PathBuf, | ||
| data_dir: PathBuf, | ||
| } | ||
|
|
||
| impl DirsProject { | ||
| fn new(app: impl AppStrategy) -> Self { | ||
| DirsProject { | ||
| home_dir: app.home_dir().to_path_buf(), | ||
| config_dir: app.config_dir(), | ||
| cache_dir: app.cache_dir(), | ||
| data_dir: app.data_dir(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Dirs { | ||
| /// Project directory specifically for Vim Clap. | ||
| /// | ||
| /// All the files created by vim-clap are stored there. | ||
| pub fn project() -> &'static ProjectDirs { | ||
| static CELL: OnceLock<ProjectDirs> = OnceLock::new(); | ||
| fn project() -> &'static DirsProject { | ||
| static CELL: OnceLock<DirsProject> = OnceLock::new(); | ||
|
|
||
| CELL.get_or_init(|| { | ||
| ProjectDirs::from("org", "vim", "Vim Clap") | ||
| .expect("Couldn't create project directory for vim-clap") | ||
| let app = AppStrategyArgs { | ||
| top_level_domain: "org".to_string(), | ||
| author: "vim".to_owned(), | ||
| app_name: "Vim Clap".to_owned(), | ||
| }; | ||
|
|
||
| if cfg!(target_os = "macos") { | ||
| // SAFETY it does never fail | ||
| let apple = | ||
| choose_native_strategy(app.clone()).expect("Cannot find the home directory"); | ||
|
|
||
| if apple.in_config_dir("config.toml").exists() { | ||
| return DirsProject::new(apple); | ||
| } | ||
| } | ||
| let xdg = choose_app_strategy(app).expect("Cannot find the home directory"); | ||
|
|
||
| DirsProject::new(xdg) | ||
| }) | ||
| } | ||
|
|
||
| /// Provides access to the standard directories that the operating system uses. | ||
| pub fn base() -> &'static BaseDirs { | ||
| static CELL: OnceLock<BaseDirs> = OnceLock::new(); | ||
| /// Get the home directory | ||
| pub fn home_dir() -> &'static Path { | ||
| Self::project().home_dir.as_path() | ||
| } | ||
|
|
||
| /// Get the config directory | ||
| pub fn config_dir() -> &'static Path { | ||
| Self::project().config_dir.as_path() | ||
| } | ||
|
|
||
| /// Get the cache directory | ||
| pub fn cache_dir() -> &'static Path { | ||
| Self::project().cache_dir.as_path() | ||
| } | ||
|
|
||
| CELL.get_or_init(|| BaseDirs::new().expect("Failed to construct BaseDirs")) | ||
| /// Get the data directory | ||
| pub fn data_dir() -> &'static Path { | ||
| Self::project().data_dir.as_path() | ||
| } | ||
|
|
||
| /// Cache directory for Vim Clap project. | ||
| pub fn clap_cache_dir() -> std::io::Result<PathBuf> { | ||
| let cache_dir = Self::project().cache_dir(); | ||
| pub fn clap_cache_dir() -> std::io::Result<&'static Path> { | ||
| let cache_dir = Self::cache_dir(); | ||
| std::fs::create_dir_all(cache_dir)?; | ||
| Ok(cache_dir.to_path_buf()) | ||
| Ok(cache_dir) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we keep the support of
~/Library/Application\ Support/org.vim.Vim-Clap/config.tomlon macOS? This will ensure compatibility for existing macOS users, preventing any complaints about their current configuration file no longer working.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.
I can add the logic to look on both places.