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

Add a way to get current namespace and class in C++ domain #2070

Closed
Rapptz opened this issue Oct 8, 2015 · 6 comments
Closed

Add a way to get current namespace and class in C++ domain #2070

Rapptz opened this issue Oct 8, 2015 · 6 comments
Labels
domains:cpp type:enhancement enhance or introduce a new feature

Comments

@Rapptz
Copy link
Contributor

Rapptz commented Oct 8, 2015

Hello.

The python domain has a way to get the current module and current class to help facilitate with the autodoc extension. It would be nice if the C++ domain had something similar to help facilitate similar tools.

I believe the implementation for it should be fairly straightforward (just store it under domaindata) but I am not sure if it's a desirable feature. I would appreciate it since I'm working on an autodoc tool for C++ so there is some personal bias on my part.

@jakobandersen jakobandersen added type:enhancement enhance or introduce a new feature domains:cpp labels Oct 10, 2015
@jakobandersen
Copy link
Contributor

The current scope is already tracked, but in which way do you plan to use the information?

@Rapptz
Copy link
Contributor Author

Rapptz commented Oct 11, 2015

I must have missed the current scope. Under what key in domaindata is it in?

I'm using the information to have some better context-sensitive autodoc (e.g. taking into consideration the current namespace).

@jakobandersen
Copy link
Contributor

It is stored in env.ref_context['cpp:parentSymbol'], though if it doesn't exist then the current scope is global scope, which is obtained as env.domaindata['cpp']['rootSymbol']. A scope is actually represented by it's corresponding symbol in the global symbol tree that the domain creates.
I can not guarantee that this may not change, so for the sake of maintainability I think it would be best if you define what kind of API you need, instead of relying on the current implementation details.

@Rapptz
Copy link
Contributor Author

Rapptz commented Oct 14, 2015

Well at the bare minimum it'd be nice to have something like the python domain has (e.g. py:domain and py:class).

So in C++'s case we would have cpp:namespace to point to the current namespace stack (e.g. ns::some_nested_ns::other_ns) and cpp:class to point to the most recent class specified.

e.g. .https://github.com/sphinx-doc/sphinx/blob/master/sphinx/domains/python.py#L313

@jakobandersen
Copy link
Contributor

From the cpp:parentSymbol it is possible to get all that information. Though it can quickly become complicated when you want to use it.

  • A scope is not just an identifer, but potentially also a template parameter list and a template argument list. For example, the scope in the description of .. cpp:class:: template<typename T> SomeClass<T*>.
  • Some scopes don't even have a "normal" identifier, but instead one of the operators. E.g., .. cpp:func:: T &operator*().
  • The cast operators have a type as an "identifier". E.g., .. cpp:func:: operator std::function<bool(HugeTypeExpression&)>() const.

@jakobandersen
Copy link
Contributor

Closing for now as the functionality essentially is there, but may be a bit complicated to use. Please reopen if it becomes relevant to access it.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
domains:cpp type:enhancement enhance or introduce a new feature
Projects
None yet
Development

No branches or pull requests

2 participants