-
Notifications
You must be signed in to change notification settings - Fork 645
C++: introduce "using" role to "namespace" kind #1783
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
base: master
Are you sure you want to change the base?
Conversation
|
@pragmaware, could you look at this one? |
|
While I agree that this is a different usage of a namespace, and it is certainly a reference, and the code looks perfectly fine, I'm not 100% positive with using roles here. For a couple of reasons:
Having said that... if you go for the roles, then this pr looks fine :) |
|
Thank you for comments.
About function, it is good point. I thought I would like to introduce prototype role of function kind. It could be replacement the prototype kind...At least, we can introduce the prototype role without removing the prototype kind. The prototype kind can be enabled/disabled from command line, so a user can choose 'using prototype kind and not using prototype role' or using prototype role and not using prototype kind'.
I would like to go for the roles. I would like to see what kind of application could we write on the roles. |
|
Like prototype kind, externver kind can be replaced with 'prototype' role of 'variable' kind (or 'extern' role of 'variable' kind). |
|
About 'N name' kind, we can make the same. Real kinds for 'name' in C++ are resolved if we solve #1495 :-) |
13ef94a to
6cd166f
Compare
|
"used" will be better than "using". "used" is more consistent with other languages like python. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1783 +/- ##
==========================================
+ Coverage 87.35% 87.37% +0.01%
==========================================
Files 200 200
Lines 47839 47865 +26
==========================================
+ Hits 41792 41821 +29
+ Misses 6047 6044 -3 ☔ View full report in Codecov by Sentry. |
|
I understand the suggestion about "name". Currently, ctags emits: This should be:
from X3 import Y3ctags emits: (See https://docs.ctags.io/en/latest/man/ctags-lang-python.7.html for more details.) Ideally, The role What I don't decide what I should do is We can expect |
Not sure... Well, technically it could be a solution, but it's quite a convoluted one. If many names are imported with the same namespace path then there would be a lot of repeated "fake" namespace declarations. Not ideal. It's We could probably just stick |
WARNING: This change deletes "using" kind from C++ language.
"foo" in "using namespace foo;" was captured as using kind.
However, "foo" is not defined in the statement.
"foo" is referred as a namespace defined somewhere.
Therefore, ctags should not capture "foo" as a definition tag.
Instead, ctags should capture it as a reference tag.
The original code captures "foo" as a definition tag of "using" kind.
This change captures "foo" as a reference tag of "used" role of
"namespace" kind.
$ cat /tmp/foo.hh
using namespace std::cout;
$ ./ctags -o - /tmp/foo.hh
$ ./ctags -o - --extras=+r /tmp/foo.hh
std::cout /tmp/foo.hh /^using namespace std::cout;$/;" n
$ ./ctags -o - --extras=+r --fields=+K /tmp/foo.hh
std::cout /tmp/foo.hh /^using namespace std::cout;$/;" namespace
$ ./ctags -o - --extras=+r --fields=+Kr /tmp/foo.hh
std::cout /tmp/foo.hh /^using namespace std::cout;$/;" namespace roles:used
$ ./ctags --list-roles=C++.'{namespace}'
#KIND(L/N) NAME ENABLED DESCRIPTION
n/namespace used on specified with "using namespace"
Signed-off-by: Masatake YAMATO <[email protected]>
6cd166f to
66033e6
Compare
|
@pragmaware, thank you for your comments. About tagging I implemented the other ideas. I have two remained items. If With changes, I proposed in this pull request, I'm thinking about a new field "context:" or "where:". This question is not only about namespace. Most of all reference tags are relevant. void foo(void) { }
void bar(void)
{
foo();
}In the input, how the reference tags for I have no plan to implement When making a reference tag for |
WARNING: This change extracts "bar" in "using foo::bar" as a referred tag,
not a definition tag.
"bar" in "using foo::bar" is captured as a definition tag of "name" kind.
However, "foo" is not defined in the statement.
"foo" is referred as a something defined "bar".
Therefore, ctags should not capture "bar" as a definition tag.
Instead, ctags should capture it as a reference tag.
The original code captures "bar" as a definition tag of "name" kind.
This change captures "bar" as a reference tag of "used" role of
"name" kind.
$ cat /tmp/foo.hh
using foo::bar;
$ ./ctags -o - /tmp/foo.hh
$ ./ctags -o - --extras=+r /tmp/foo.hh
bar /tmp/foo.hh /^using foo::bar;$/;" N
$ ./ctags -o - --extras=+r --fields=+K /tmp/foo.hh
bar /tmp/foo.hh /^using foo::bar;$/;" name
$ ./ctags -o - --extras=+r --fields=+Kr /tmp/foo.hh
bar /tmp/foo.hh /^using foo::bar;$/;" name roles:used
$ ./ctags --list-roles=C++.'{name}'
#KIND(L/N) NAME ENABLED DESCRIPTION
N/name used on specified with "using foo::bar"
Signed-off-by: Masatake YAMATO <[email protected]>
using A::B::C;
For the input, this change makes a tag for C like:
TODO::
* the way to handle the first "::" in 'using ::std::cout;'
* the way to handle 'namespace X { using A::B; }'
How can we represent the relationship between X and B.
Signed-off-by: Masatake YAMATO <[email protected]>
66033e6 to
75c547f
Compare
OK, now I remembered this thing better. I was wrong: The
Exactly. But The difference between the
Yes, they are similar in nature. However I think that the |
|
Thank you. The About or The latter one, About Am I correct? I would like to implement the |
Yes, both solutions can work. Your call.
Ignore it. It was my first idea of what was needed, long time ago. Now it's really
Great! |
"foo" in "using namespace foo;" was captured as using kind.
However, "foo" is not defined in the statement.
"foo" is referred as a namespace defined somewhere.
Therefore, ctags should not capture "foo" as a definition tag.
Instead, ctags should capture it as a reference tag.
The original code captures "foo" as a definition tag of "using" kind.
This change captures "foo" as a reference tag of "using" role of
"namespace" kind.
$ cat /tmp/foo.hh
using namespace std::cout;
$ ./ctags -o - /tmp/foo.hh
$ ./ctags -o - --extras=+r /tmp/foo.hh
std::cout /tmp/foo.hh /^using namespace std::cout;$/;" n
$ ./ctags -o - --extras=+r --fields=+K /tmp/foo.hh
std::cout /tmp/foo.hh /^using namespace std::cout;$/;" namespace
$ ./ctags -o - --extras=+r --fields=+Kr /tmp/foo.hh
std::cout /tmp/foo.hh /^using namespace std::cout;$/;" namespace roles:using
$ ./ctags --list-roles=C++.namespace
#KIND(L/N) NAME ENABLED DESCRIPTION
n/namespace using on specified with "using namespace"
Signed-off-by: Masatake YAMATO [email protected]