Skip to content

allow for explicit exports in generating tags#3205

Merged
hdgarrood merged 5 commits into
purescript:masterfrom
matthewleon:fixtags
Jan 23, 2018
Merged

allow for explicit exports in generating tags#3205
hdgarrood merged 5 commits into
purescript:masterfrom
matthewleon:fixtags

Conversation

@matthewleon

Copy link
Copy Markdown
Contributor

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 app into Language.Purescript. If people find that appropriate, I'll be happy to add the commits for that onto this branch.

@matthewleon

Copy link
Copy Markdown
Contributor Author

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.

@hdgarrood

Copy link
Copy Markdown
Contributor

Moving the tag generation code into the library sounds good to me 👍

@matthewleon

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a great idea :). Actually, it's the main reason I proposed moving this code in the first place.

Comment thread app/Command/Docs.hs Outdated
case fmt of
Etags -> dumpTags input dumpEtags
Ctags -> dumpTags input dumpCtags
Etags -> mapM_ putStrLn $ dumpEtags $ zip input ms

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@matthewleon

Copy link
Copy Markdown
Contributor Author

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 kritzcreek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good to me, I'll approve but let's wait for positive feedback from Tom before merging.

Comment thread app/Command/Docs.hs Outdated
let moduleNameToFileMap =
M.fromList $ swap . fmap P.getModuleName <$> modules
getModuleFile docModule =
fromJust $ M.lookup (D.modName docModule) moduleNameToFileMap

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and yes, your guess as to why this is done is correct)

@hdgarrood hdgarrood Jan 21, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Thanks for the clarification.

@matthewleon

Copy link
Copy Markdown
Contributor Author

@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:

  1. Actually changing convertModulesInPackage to maintain (path, module) tuples without a Map would involve stringing that change through a large series of functions, some of which are called from multiple sites. It seems to me that it would be a pretty disruptive change.

  2. So instead I've made a new function that uses the same kind of Map-based logic as before, but placed it in the src tree rather than app. This addresses your second concern more than your first; the logic is now easier to reuse.

  3. As for your first concern, regarding the use of fromJust, I've replaced that with use of MonadError's throwError. Admittedly, this still feels a little bit hackish, and might lead to a surprising error message if tag generation ever explodes there. I don't see an obvious better way to do this, though. Please let me know if you can think of something more elegant.

@hdgarrood hdgarrood left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!

@i-am-tom

Copy link
Copy Markdown

@kritzcreek I did the tags and the things happen and everything seems to be great :D

@matthewleon

Copy link
Copy Markdown
Contributor Author

@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?

@i-am-tom

Copy link
Copy Markdown

ctags and just jump-to-type stuff. I am an ever-closer-to-vanilla Vim fellow :)

@matthewleon

Copy link
Copy Markdown
Contributor Author

Just rebased to make merge easier.

@matthewleon

Copy link
Copy Markdown
Contributor Author

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.
@matthewleon

Copy link
Copy Markdown
Contributor Author

Okay, this is rebased on the newly fixed master.

@hdgarrood

Copy link
Copy Markdown
Contributor

I’ll just go ahead and merge this, since the Linux and Windows CI builds have all passed already.

@hdgarrood hdgarrood merged commit 0798e33 into purescript:master Jan 23, 2018
@hdgarrood

Copy link
Copy Markdown
Contributor

Thanks very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ctags and etags generation foiled by explicit exports

5 participants