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
feat(tactic): command for adding tactic, command, and attribute documentation (RFC) #1963
feat(tactic): command for adding tactic, command, and attribute documentation (RFC) #1963
Conversation
There are a few annoyances:
|
Would it be possible to write it as docstring first, to get editor support. And then hit a button to convert it to a Lean string. Maybe to complicated... |
I suppose it could be set up to "inherit" the description from the doc string of an existing declaration, in roughly the same way that the description can become the doc string. I think editor support for escaping quotations in a string sounds a little clunky. Plus, you still don't get real markdown support in a comment like you do when you're editing an actual markdown file. |
Regarding the annoyance of writing markdown blocks inside of Lean strings: only five entries in One hackish alternative is, instead of using a command, actually defining objects. So your doc entry would look like /-- A tactic for doing this and that. This is the markdown content. -/
meta def doc_info.my_tac : tactic_doc_entry :=
{ name := ...,
... } This looks ugly and it forces you to name the entry (in a way that won't ever be used). So I don't like it much. Another option would be to force the entry to be inherited from the doc string for a tactic. /-- This is the doc string for linarith. It's also the linarith entry in tactics.md -/
meta def tactic.interactive.linarith : ...
add_tactic_doc {
name := "linarith",
decl_name := `tactic.interactive.linarith,
... } -- no description field But I think forcing doc page entries and doc strings to be the same is a bad idea. It also complicates the picture a bit for tactic "families" like finish/clarify/safe (this is why A third, related, option would be to do option 2, but with a delimiter in the doc string. You write the standard doc string, a bar A fourth, nuclear, option is changing the parser to make this easier. |
We can also keep the docstring as it is and only split it for the documentation. vscode doesn't have a problem with the long docstring, it only shows the beginning if it's too long (you need to scroll to see all of it). |
Would it be possible to have an option to read markdown strings from standalone markdown files? e.g. something like: add_tactic_doc
{ name := "add_tactic_doc",
category := doc_category.cmd,
decl_names := [`add_tactic_doc_command],
tags := ["documentation"],
description_file := "path/to/some_markdown_file.md" -- instead of description |
I think this is probably the most practical solution. There are still a few minor hiccups. For one, it doesn't help the "family of tactics" situation, although in practice that's not very common. We'll have to use the same scheme in core to document tactics there, since we can't overwrite their doc strings from mathlib. But this is all manageable.
One of the reasons for this change is so that the declarations and docs aren't so distributed. It would be better than the current situation, but still feels a little messy to me. |
I tried to implement Gabriel's suggestion earlier today. But a fortunate choice of test case pointed out an issue very quickly: Lean doesn't like nested comment blocks. So a tactic doc entry that contains comments, e.g. the one for One proposed solution: change the lexer to accept nested comments. @gebner suggested this might be a "medium effort" task. I don't want to do it myself, but maybe someone is interested? |
Oh, that's interesting. I believe Lean is actually fine with nested "non-doc" comment blocks, e.g.: /- this is fine:
/- nested!
/- even more nested
-/
-/
-/ so the new feature would be extending this somehow to (module) docstrings. edit: Oops, Gabriel already said more or less the same thing on Zulip. He also pointed out the key function is |
Co-Authored-By: Bryan Gin-ge Chen <bryangingechen@gmail.com>
I considered adding these as doc strings in core. But the entry for `conv` mentions mathlib-specific things.
I can help out with this later tonight if there's still work to be done. Should I work in revisions from my previous PR #1874 or should that go in a different PR? |
Thank you! I'm done for the night, so everything left is fair game. Feel free to work in your revisions if you want, or in a separate PR, your call. Also feel free to do whatever you want with the tags field. I haven't been very consistent with it so far; it will be easier to clean that up in a second pass, I think. |
I think I got the rest of the tactics, commands and hole commands. Along the way I added in most of my tweaks from #1874, added a few module docs, cleaned up some docstrings and split some long lines in the tactic files. Feel free to revert any changes I made if they seem excessive. A few notes:
|
A few more thoughts:
|
Thanks, Bryan! That's fantastic.
For sure, that's easy enough to do.
I'll investigate once #2064 lands. I think there's no point fixing it before then.
Yep, this is the plan. It will use the
I think the API docs are really the place to look for this kind of thing, e.g. tactic.core. We should eventually improve the high level tactic writing docs. |
I just noticed this PR is from a branch on my own repo. I'm going to close it and reopen it from a community branch. |
As discussed in #1874, the current setup of
tactics.md
, etc isn't ideal. The entries often repeat information found in doc strings; they're located far from the definitions, so it's easy to forget to update them; the doc generator does something hackish to parse individual entries out of the markdown file.This PR introduces a command
add_tactic_doc
that registers a "documentation entry" related to a declaration/list of declarations. It's best displayed by invoking it on itself:Happy to hear any suggestions about this!
I haven't ported the entries from
tactics.md
yet. I'd rather get feedback first, merge this, and do that in a separate PR. Of course, the doc generation tool has to be updated too before deleting the .md files.TO CONTRIBUTORS:
Make sure you have:
If this PR is related to a discussion on Zulip, please include a link in the discussion.
For reviewers: code review check list