-
Notifications
You must be signed in to change notification settings - Fork 228
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
Search for configuration in config directories (dotfiles, etc) #749
base: main
Are you sure you want to change the base?
Conversation
Searches for: - ~/Library/Application Support/swift-format/config.json - $XDG_CONFIG_HOME/swift-format/config.json - ~/.config/swift-format/config.json
- `~/Library/Application Support/swift-format/config.json` | ||
- `$XDG_CONFIG_HOME/swift-format/config.json` | ||
- `~/.config/swift-format/config.json` |
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'd love to see $XDG_CONFIG_HOME / ~/.config first here. What's the thinking behind looking first in ~/Library/Application Support?
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.
It is the default path for configuration files on MacOS
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.
Thanks for the PR, @calebhearth. I think adding an ability to have a global .swift-format
configuration without putting .swift-format
in /
will be useful.
A couple comments regarding the search locations:
- I think we should also support
XDG_CONFIG_DIRS
for a system-wide configuration file isntead of just a user-wide configuration file. - We should also offer default search locations on Windows, the Build Server Protocol uses
%LOCALAPPDATA%\bsp\
and%PROGRAMDATA%\bsp\
and I think we could do the same here. - The search path discovery for BSP servers is implemented in SourceKit-LSP at https://github.com/swiftlang/sourcekit-lsp/blob/4ca25836226a2b28868a42df3a3336fcc481e1c5/Sources/BuildSystemIntegration/ExternalBuildSystemAdapter.swift#L195-L220. I think you should be able to steal a lot of that (especially note that there are methods in Foundation to get the path for the
Application Support
directories). Also, I think it makes sense to follow that precedent for ranking the XDG-dirs vsApplication Support
.
@WuerfelDev opened the PR, but I second the thanks! |
Oh, whoops, sorry. @WuerfelDev thank you for opening the PR 🙏🏽 |
I will make the changes within the next week. However I am unable to test on windows Thanks for the SourceKit link, I'll get some "inspiration" from there |
That’s fine. Just try and do the best you can think of, leaving FIXMEs for things that you know need covering and I can do the rest. |
Searches for configuration files (
swift-format/config.json
) in the config directories (~/Library/Application Support
,$XDG_CONFIG_HOME
,.config
).That enables a "global" (userwide) configuration that is stored eg in the dotfiles.
The configuration file is only used when no other configuration file was found