-
Notifications
You must be signed in to change notification settings - Fork 619
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
PHP parser: include fully qualified class name #787
Comments
Thank you for reporting this. You are not only the person who wants this. See #524. I would like to know all combination of FQCN. You told me the combination of two classes uses Could you tell me all the combinations of kinds which can be part of a FQCN and I' have been trying to under stand the critical difference between FQCN and scope.
(This discussion is applicable to Ruby parser and Python parser.) |
Forgot to mention that this is probably useful only for vim (and possibly for other editors which can only use a tag name and not the rest of the fields) FQCN (fully qualified class name) consists of full namespace + a class name. FQCN is somewhat similar to an absolute file path on a file system. Namespaces can be nested as well. Here are some examples of fqcn's:
Namespace separator is actually one backslash (
I'd imagine a scope is an equivalent of a namespace - thus it differs from FQCN in missing a class name.
Isn't it ok to have a language-specific additional tag entry?
I'm afraid that wouldn't work so well in practice. I've also did a mistake in the original posting - the correct FQCN should start with a backlash - thus it should be Thanks |
Backslashes ( Internally the U-CTags PHP parser never uses I see several possibilities here, but all are more or less problematic IMO:
In most cases, it would be probably useful for U-Ctags to be able to report the separator(s) used in QNs for a particular parser, so a tool could use that for splitting. Alternatively a more large scale and powerful solution could be a new format for reporting the scope that would allow for non ambiguous QNs, e.g. with each element prefixed with its type or something. In practice, "all" it would require (if the scope was already using the correct separators, which is a little trickier) is doing something like that: static void makeExtraTagEntry (tagEntryInfo *const info)
{
if (isXtagEnabled (XTAG_QUALIFIED_TAGS))
{
vString *fqn = vStringNewInit ("\\");
if (info->extensionFields.scopeName)
{
vStringCatS (fqn, info->extensionFields.scopeName);
if (info->extensionFields.scopeKind == &(PhpKinds[K_NAMESPACE]))
vStringCatS (fqn, "\\");
else
vStringCatS (fqn, "::");
}
vStringCatS (fqn, info->name);
info->name = vStringValue (fqn);
info->extensionFields.scopeKind = NULL;
info->extensionFields.scopeName = NULL;
makeTagEntry (info);
vStringDelete (fqn);
}
} All of which is generic but choosing the separator and prefixing the string with it (if not all languages have the concept of a "named" root scope (empty)). Anyway, that's a lot of blabbing, but I don't really care for this either way myself. I'd just like not to see more and more specific code when it could be generic :) Esp. this (qualified tags), that merely are just concatenating two already existing info (which in itself, IMO, makes it quite useless in itself though). |
BTW, using the cork scope feature plus a table of kind->separator could probably work for any parser that can use cork (any parse that only reference existing tags in the scope, instead of mere names IIRC). |
Well it seems then it would be more appropriate to just do a custom post-processing with awk/etc and add additional tag - at the end overcoming limitations of specific editor shouldn't involve that much effort.
though your ctags fork - https://github.com/b4n/ctags/tree/better-php-parser - produces tags with one backslash (which is also what phpcomplete.vim relies upon) |
@b4n, thank you for great comments I have been a developer of u-ctags. However, I have not been its user. I have used TAGS output of u-ctags on emacs. As such background, I had the same option of @b4n wrote
However, these days I have to read source code written in Java. Many methods are massively overridden and overloaded. About scope: field representation, the array approach is ideal. However, I cannot implement it now. First I would like to "correct" approach. Then I would like to add code for keeping compatibility. Here is my offering.
After implementing/merging above items, The finally I would like to clear my question: relation ship between scope and qn. fq is alike syntax sugar. The real tool can work without it. However, carefully generated fq tags entry are useful. |
Originally written by @b4n at universal-ctags#787. (universal-ctags#787 (comment)) Changes: integrate this with scopeSeparatorFor(), temporary remove "root separator", don't clear the scope information of a qualified tag, and reuse vString object
I merged @b4n's makeExtraTagEntry to my branch. For php, following code may be needed.
|
I need a bit more complex example. Could you show me more nested input and its expected tags. |
@masatake It's relatively simple actually: always use In practice, nothing can be below a namespace, so you won't ever see something like The only "subtlety" is that PHP considers there is a namespace with an empty name containing everything else. So, in practice just prepend
and so on.
Not really, but again, that doesn't really matter either :) |
@b4n, thank you. my The separator table definition:
What I got:
TODO:
|
I'm not sure |
(I guess the root separator should be put in php.c side.) |
Adding the root separator to full qualified tags is o.k.::
Should we add the root separator to the scope informatoin, too?
or
Which is better? @b4n, do you have any idea? As we wrote full qualified tags are just sugar tags in meaning of syntax sugar in programming languages; serious higher level tool developers can be alive without it. However, scope information is essential. Ideally it should be well formalized. In other word, I wonder higher tool developers want the root separator in scope information. I can add the information about root separator to tags file via pseudo tag. However, I am not sure Comments are welcome. |
Experimental pseudo tag for separators is added:
I will not include code implementing fq or fullQufalified extra tags in my next pull request. The pull request will become too large if I include it. |
…scope info For closing universal-ctags#787. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
For closing universal-ctags#787. Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Tried with #806 although I'm not sure what is the change I should be looking at? The only thing changed is different delimiter (\ vs ::) in "class" attribute for a tag entry. Also, is it strictly neccessarily to escape backslash in tag name (for namespaces) - https://github.com/b4n/ctags/tree/better-php-parser ctags don't have them escaped: |
How about other things ?
This is what I have done in the pull request. You may think the result is very small but I took much time to introduce the change consistent way. How about function under a namespace? |
That's totally understandable and appreciated, I just wanted to confirm I didn't miss any other changes.
Yep, it has a valid "namespace" attribute as well.
Speaking of php, I don't think it's possible to have \t in a name anyway. |
Internally, with my new code, parser developers can declare separators used in scope and full qualified tags declarative way. In addition all separators can be printed as pseudo tags. Php parser is the first parser using this new facility. As far as I can remember this new facility solve the issues of Ruby and python, too. (So I took much time for the small change.)
Thank you for verifying. |
That seem to work as desired (i.e. --extra+q produces extra tag entries with fqcn). I'll have a closer look later today and will let know if I have any more questions. Thank you.
Yes. I'm ok with having it dealt with in a separate issue. |
@sserbin, thank you. |
Hi! I have an issue with PHP using Yii2 framework. e.g: |
@compleatguru, do you want to capture WebController of use line? |
@masatake, yes. I hope that the ctag can recognize WebController is referring to yii\web\Controller. As of now, without the namespace alias, |
I read php.c and I found the current parser doesn't handle the use statement. Here is a workaround.
You can put the regex option to your .ctags. (Don't forget remove the single quotes when putting the option to .ctags.) |
Thanks! will open a new issue. |
@sserbin, @b4n, I have a question about the root separator. I read Quote from the page:
It seems that a full qualified namespace with root separator is not recommended. |
Continuing the quote from php.net:
I'm for it. (you might even notice the code sample from the first comment doesn't include a root separator). Besides, @b4n ctags branch also doesn't include it. Edit: actually, it seems it would be even more approriate to leave out root |
@masatake I have no real opinion on the matter, and nothing more to add to what @sserbin said. FQN more or less have it to make it an "absolute" FQN, and a relative FQN is kind of weird, but I don't have a real opinion on this as I'm not quite sure what the real use case is for this. And yeah, the leading Anyway, as PHP syntax is not really consistent on that matter (as you see yourself), either way goes IMO.
That's not really an interesting point, as mine didn't support FQN tags at all, so it's already different. |
Thank you for comments. I will remove it. |
Would it be possible to include FQCN in addition to a class name (or instead) in a tags file?
Test case:
Current output:
What I'm looking for:
This would allow you to search/jump to a class definition with both
:ts bar
and:ts foo\\bar
The text was updated successfully, but these errors were encountered: