-
-
Notifications
You must be signed in to change notification settings - Fork 73
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
[#333] Use key-value map for extra files #369
Conversation
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.
There is no place for me here... I will choose the truth I like.
790f95b
to
6f8bf23
Compare
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.
This is great work, thanks @chshersh ❤️
@@ -7,7 +7,6 @@ packages: | |||
extra-deps: | |||
- base-noprelude-4.13.0.0 | |||
- brick-0.50 | |||
- relude-0.6.0.0 |
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.
🎉 we are in the nightly!
@@ -6,6 +6,7 @@ packages: | |||
|
|||
extra-deps: | |||
- optparse-applicative-0.15.0.0 | |||
- relude-0.6.0.0 |
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 left 0.5.0 intentionally here, so we check with both versions, as our boundaries are including it, do you think that it is not important? Should we then update the boundaries in the cabal
file?
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've updated the boundaries in the .cabal
file. I decided to bump up the lower bound because I'm using mapMaybeM
function from a new version (it's very helpful 🎉) and summon
simply won't compile with relude-0.5.0
😞 In general I don't mind supporting both versions but here I had to increase lower bound...
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.
Oh, now I see!
You can put "Resolves #360 " then 🙂
{- | This function fetches contents of extra file sources. | ||
-} | ||
fetchSources :: Bool -> Map FilePath Source -> IO [TreeFs] | ||
fetchSources isOffline = mapMaybeM sourceToTree . Map.toList |
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.
🎇 mapMaybeM
🎇
fetchSource isOffline source >>= \case | ||
Nothing -> do | ||
errorMessage $ "Error fetching: " <> toText path | ||
pure Nothing |
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.
Is this correct, that in case of download (or just file getting) failure the process of the project generation will still continue without those files?
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.
@vrom911 I'm not sure, but implementing different logic is quite complicated. For example, if isOffile
is True
then all Url
will fail. But maybe this is intentional and maybe I don't want things like CONTRIBUTING.md
while developing locally 🤔
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.
Yes, makes sense. By the way, where the mentioned case is handled?
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's handled here:
summoner/summoner-cli/src/Summoner/Source.hs
Lines 65 to 67 in 38d1fce
Url url -> if isOffline | |
then Nothing <$ infoMessage ("Ignoring fetching from URL in offline mode from source: " <> url) | |
else fetchUrl url `catch` urlError url |
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.
Oh, right! Thank you 🍷
(File _ _, Dir _ _) -> x : insertTree node xs | ||
(File nodePath _, File curPath _) | ||
| nodePath == curPath -> node : xs | ||
| otherwise -> x : insertTree node xs |
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 don't quite get this case. When this file is already in the tree, it inserts it, but if it's not, it somehow continues inserting on the next layer? How so?
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.
Right, the implementation is not obvious, but I tried to do my best. This function always inserts node
to the list, at least when it reaches the empty list at the end:
insertTree node [] = [node]
In this case, if this function finds two File
s with the same path, it will replace current x
with node
that why it's node : xs
. This is done if people want to override default files like .travis.yml
or Prelude.hs
with their files. If file paths are not equal, then we keep x
, and we will try to insert node
into xs
. Eventually, we either reach the end of the list, and we will add node
unconditionally, or we will find a File
that has the same name and will replace it.
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.
Hmm, but are other nodes placed unconditionally? I thought there is some kind of hierarchy so no need to go till the end of the list each time.
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.
Well, this list is not sorted at this stage. It could be [File "foo" x, File "bar" y]
or [File "bar" x, File "foo" y]
. I checked the implementation, and it looks like we sort this list only when printing to terminal or in TUI.
Now, after you told this, I started to think that probably there's a better way to implement TreeFs
. At least TreeFs
shouldn't have duplicate filepaths but since we're using lists, it's possible to have a bug in the implementation and introduce duplicate fields.
Maybe instead of
data TreeFs
= Dir FilePath [TreeFs]
| File FilePath Text
we should have
data TreeFs
= Dir (Map FilePath TreeFs)
| File Text
The latter representation won't allow having duplicate filepaths. But I believe that the current algorithm is also correct, even if the logic is not straightforward... And changing this type is a big rewrite...
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.
Thank you for the clarification, Dmitrii! Yeah, I don't think that rewrite is the right step right now, and we could keep this function as it is for this PR. But let's think more about this sorting before option and create the issue if we will decide that it could work better and would become easier to maintain.
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've created the issue:
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.
Great! Thanks a lot 👏
Now, let the testing period begin!
Resolves #333
Resolves #360
It actually works! I tested with the file from
org
repo. And the tree displays perfectly! Also,Summoner.Shell
module turned out to be redundant...