allow for explicit exports in generating tags#3205
Conversation
|
Another note regarding tests: now that tags use the same intermediate machinery as the other documentation formats, the tests for those formats cover tags as well. We could make tests that are even more "end to end" by testing the string output of the entire tagging workflow, but I feel that the improvements here probably offer a good bang-for-buck compromise. |
|
Moving the tag generation code into the library sounds good to me 👍 |
Okay, I'll take a look at this possibility soon. |
| import Language.PureScript.Docs.Types | ||
|
|
||
| tags :: Module -> [(String, Int)] | ||
| tags = map (first T.unpack) . concatMap dtags . modDeclarations |
There was a problem hiding this comment.
this looks like a nice and pure function, what do you think about adding a few tests to make sure tag generation continues to work as we change the compiler?
There was a problem hiding this comment.
I think it's a great idea :). Actually, it's the main reason I proposed moving this code in the first place.
| case fmt of | ||
| Etags -> dumpTags input dumpEtags | ||
| Ctags -> dumpTags input dumpCtags | ||
| Etags -> mapM_ putStrLn $ dumpEtags $ zip input ms |
There was a problem hiding this comment.
I don’t think it’s safe to assume that the modules come out in the same order that they went in. We might need to modify parseAndConvert (instead of doing a zip here) so that it gives you the file path associated with each module.
There was a problem hiding this comment.
I'll take a look at this, thanks.
| tagLines = map tagLine $ tags mdl | ||
| tagLine (name, line) = "\x7f" ++ name ++ "\x01" ++ show line ++ "," | ||
|
|
||
| dumpCtags :: [(String, Module)] -> [String] |
There was a problem hiding this comment.
This isn’t a big deal but if you know why this one sorts but etags doesn’t, it might be useful to leave a comment.
|
This is ready for review. @i-am-tom I recall you being eager to use this functionality. Would you mind trying to run this branch, if you have a moment? |
kritzcreek
left a comment
There was a problem hiding this comment.
Code looks good to me, I'll approve but let's wait for positive feedback from Tom before merging.
| let moduleNameToFileMap = | ||
| M.fromList $ swap . fmap P.getModuleName <$> modules | ||
| getModuleFile docModule = | ||
| fromJust $ M.lookup (D.modName docModule) moduleNameToFileMap |
There was a problem hiding this comment.
I’m not hugely keen on this. I guess this is to reassociate each file path with the relevant module after sending the modules through convertModulesInPackage? Is it worth considering changing convertModulesInPackage so that the output from parseFilesInPackages can just be passed straight in?
There was a problem hiding this comment.
I also find it a bit hackish and ugly. Happy to look at your proposal, and see if other options are better as well. Just a clarification: beyond the hackishness of this, is there anything else that you find unpleasant about it that I should be aware of?
There was a problem hiding this comment.
(and yes, your guess as to why this is done is correct)
There was a problem hiding this comment.
It's mainly the use of the partial function fromJust, but also I think it might be a bit neater to have convertModulesInPackage take responsibility for keeping modules and file paths properly associated with each other so that users of the API exposed by Language.PureScript.Docs don't have to. You already changed parseFilesInPackages in a similar way in this PR and I think it makes sense to have the output of that able to be passed directly in to convertModulesInPackage - currently you can pass the output of the former straight in to the latter.
There was a problem hiding this comment.
Makes sense. Thanks for the clarification.
|
@hdgarrood I've made a new commit to address your concerns. It is probably not exactly what you were hoping for, but I think it's a reasonable compromise. My reasoning here:
|
hdgarrood
left a comment
There was a problem hiding this comment.
I suspected that we might end up with something like this, yeah. I agree; the only decent alternative I can think of is your point 1, which would indeed be very disruptive. I think this is a good compromise. Thanks!
|
@kritzcreek I did the tags and the things happen and everything seems to be great :D |
|
@i-am-tom I'm curious, are you using ctags or etags? Are you using any kind of tagbar plugin, or just doing "jump to definition" type stuff? |
|
ctags and just jump-to-type stuff. I am an ever-closer-to-vanilla Vim fellow :) |
|
Just rebased to make merge easier. |
|
Hmm, something is killing build on the rebase. My apologies. Will try to fix. |
fixes purescript#3204 Reuses other formats' (HTML, Markdown) machinery for converting PS modules to a friendlier doc module format before generating tags. This eliminates some error-prone ad-hoc logic for converting declarations directly to tags.
this makes tag generation more testable
For all tags, use a Map to ensure that filenames and modules correspond correctly. For ctags, add a comment explaining why we sort on tag name. For etags, ensure that they are sorted by module.
Move the logic for maintaining a map between module paths and data from Command.Docs to Language.PureScript.Docs.Convert, allowing other callers to reuse the functionality.
|
Okay, this is rebased on the newly fixed |
|
I’ll just go ahead and merge this, since the Linux and Windows CI builds have all passed already. |
|
Thanks very much! |
fixes #3204
Reuses other formats' (HTML, Markdown) machinery for converting PS modules to a friendlier doc module format before generating tags. This eliminates some error-prone, ad-hoc logic for converting declarations directly to tags.
I haven't added any tests onto this branch. I believe that doing so would be made easier if we moved some of the tag generation code from
appintoLanguage.Purescript. If people find that appropriate, I'll be happy to add the commits for that onto this branch.