Skip to content
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

Creating New Abbreviations #86

Open
Tokazama opened this issue Apr 22, 2020 · 2 comments
Open

Creating New Abbreviations #86

Tokazama opened this issue Apr 22, 2020 · 2 comments

Comments

@Tokazama
Copy link

Is it possible to create a new Abbreviation type in a separate package? After implementing a format method I only see the proper print out when I run the docstring through Docs.formatdoc. It doesn't seem to process it for the actual docstring (i.e., @doc) or in documenter markdown.

@Tokazama
Copy link
Author

I have an update on this that seems to be working but is also pretty hacky. I realized that the problem I was having was that the docstring for my type occurred before the data necessary for the abbreviation was available. In other words the following example wouldn't be able to grab info from get_doc (what I'm doing is a lot more complex but this is the closest to a MWE I could get).

"""
MyType
$(MYABBREVIATION)
"""
struct MyType end

get_doc(::MyType) = "some documentation")

What I do later is similar to

d = @doc MyType
first(d.meta[:results]).object = nothing

I think the reason this works is because when parsedoc is called it doesn't actually parse the docstring unless docstring.object === nothing. So this forces it to parse the docstring again.

This seems like a pretty unsafe solution though and it would be cool if there was a way to work around this safely.

@mortenpi
Copy link
Member

We don't have any publicly defined API for this purpose, but if you or someone else would like to take a stab at designing and implementing it, I think it would be a good addition to the package.

I think the reason this works is because when parsedoc is called it doesn't actually parse the docstring unless docstring.object === nothing. So this forces it to parse the docstring again.

This is correct -- the parsed docstring gets cached. However, the caching only happens when you try do look up the docstring, e.g. in the REPL. So if your custom abbreviation is registered before that happens, like during the parsing of your package/module, it should work.

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

No branches or pull requests

2 participants