Expose readConfigs #121
No reviewers
Labels
No Label
blocked: dependency
blocked: info-needed
bug
duplicate
enhancement
fixed in HEAD
help wanted
hs:arrows
hs:brackets
hs:classes
hs:comments
hs:do-notation
hs:guards
hs:lists
hs:operators
hs:patterns
hs:records
hs:types
invalid
language extension support
layouting
needs confirmation
priority: high
priority: low
question
revisit before next release
wontfix
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: hexagoxel/brittany#121
Loading…
Reference in New Issue
There is no content yet.
Delete Branch "PR-expose-read-configs"
Deleting a branch is permanent. Although the deleted branch may exist for a short time before cleaning up, in most cases it CANNOT be undone. Continue?
Changes
readConfigs
anddefaultConfigPaths
so that external tools can make use of them.Main.hs
to call exposedreadConfigs
withdefaultConfigPaths
(command line provided paths still take priority).ping @lspitzner
Hello Alexey!
Thanks for working on this issue!
I think the new functionality should be official and not just
Internal
, so this stuff should be also exported fromLanguage.Haskell.Brittany
.Regarding semantics, this code contains some changes that I did not anticipate and which I do not understand yet.
Most importantly, it diverts from what was discussed in the HIE issue[1] by having
defaultConfigPaths
depend on the current working directory. Perhaps my suggestion over there was still a bit too short, because we may indeed also want a way to discover per-project configs from HIE; that is an aspect I had not considered and it is good that you point it out. But it still seems to me that exposing a method that depends onCWD
is of no use to HIE. Please correct me if this is wrong or if you have a different usecase for which this makes sense.Further, the semantics seem to have changed slightly:
brittany.yaml
, we now consider and merge allbrittany.yaml
s in cwd and its parents;I am not sure which of these changes you intended (you certainly did not mention any of them in the PR or the commit-messages). From my point of view, 2 and 3 seem to be mistakes; and I am open about 1, but "if it aint broke dont fix it" so I wonder: which users want to have multiple (cascaded) per-project configs?
[1] https://github.com/haskell/haskell-ide-engine/issues/346
Hi Lennart!
Sorry, I have missed the exports.
As for CWD etc, I envisioned it to be a responsibility for an external tool to provide the config file.
HIE
(or other tools) could either usedefaultConfigPaths
or it could find a per-project file and pass it toreadConfigs
instead, or it can add it to thedefault
list with a priority it thinks it is necessary, or it can takedefaultConfigPaths
and do any additions/filtering necessary.I thought that it shouldn't be
brittany
dictating this to the tools, so I decided to try widening a bit your suggestion and allow this to be decided by the tools.Changes in semantics:
It was intentional. It is how configs usually work and how GHCi works (or at least as it is supposed to work because there is currently a bug where "global"
.ghci
always overrides "local" settings).We can change it if we don't want this behaviour in Brittany. Don't we?
I don't believe so, but I'll double check. My intention was for
defaultConfigPaths
to return "highest priority first", and then there is this line I inherited from the existing code:It reverses the list so local files configs will be at the end of the list overriding more global ones.
But as I said, I will double check.
I can change it. My intention was like "found something I can work with therefore don't change anything". But I think there is no harm in always writing a default config in case if it doesn't exist.
So I will:
Can we discuss merging files in a bit more details? Why don't we want the default config, which is automatically written and could be adjusted by user) to take effect for the settings that are not specified in a local config? I thought it would be just logical?
For the last question: Yes, we certainly want to merge the different configs. I was talking about the case where there are multiple potential "per-project" configs, i.e. we are at
/a/b/c/
and there is abrittany.yaml
at both/a/b/
and at/a/b/c
. Previously we considered only the closest one, this PR merges them (in some order i am not sure about, really.)GHCi is not applicable as a reference for that aspect, because it only considers one "per-project" file:
./.ghci
. (See https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ghci.html#the-ghci-files)The
reverse
indeed makes things confusing. Perhaps we should just remove it; it may not even be the expected thing to do when passing paths on the commandline, as later args normally to override earlier ones, but they don't with thereverse
. And if you also refactor the create-if-missing logic to somewhere else,readConfigs
could become short and neat.Regarding
CWD
: You could not even use the currentdefaultConfigPaths
for HIE. Because when it callsgetCurrentDirectory
, it asks where hie was started, which could be some random folder that contains no relevantbrittany.yaml
(in the best case). I am mildly certain that nothing callinggetCurrentDirectory
should be exposed, as it would only serve to confuse the user/the API.That sounds great! I'd prioritize some in-source comments containing examples over a test though; such system tests are annoying to write anyways.
Lennart,
Please have a look at the updated PR and let me know if it is closer to what you have envisioned.
In this version it will:
config.yaml
. If there is none, the default one is created.brittany.yaml
is found). No more merges for "higher-level" configs.brittany
will still merge the "local" config file with the "user-level" one. Let me know if you don't want that, but I think it is a sensible way of overriding user's defaults.readConfigs
andreadConfigsWithUserConfig
. Only the second one performs the merge I described above.@AlexeyRaga looks perfect! User and local config should indeed be merged in exactly this fashion (and if I am not mistaken it matches the previous behaviour).
Thanks!
I plan to include this in a new release in the next days.