ReflectionDocBlock icon indicating copy to clipboard operation
ReflectionDocBlock copied to clipboard

Location information for tags

Open felixfbecker opened this issue 9 years ago • 7 comments

I am using this package in the open PHP language server, which provides static analysis for any IDE through the open language server protocol. One of these features is "Go to Definition". This is currently implemented for the actual PHP code through nikic's great PHPParser, where every node has a file start/end offset so I can calculate which node the user clicked. It would be nice to have this feature for types in docblock tags like @var too, but the tags don't have any start/end offset data. Would it be possible to add this?

felixfbecker avatar Nov 04 '16 19:11 felixfbecker

This should easy with PREG_OFFSET_CAPTURE

felixfbecker avatar Nov 20 '16 19:11 felixfbecker

The docblock class itself has a location. But tags do not. Since tags we don't use the location of the tags ourselfs. Beside that all other elements of our reflection component have a location. So I don't see any needs to add this at the moment.

I think you want to jump to the actual element which should be posible in combination with our reflection component.

jaapio avatar Jul 14 '17 16:07 jaapio

Of course, for the docblock itself it's trivial. The use case (as described above) is, given an offset, which tag is at that position.

Example:

/**
 * @param ClassA $a
 * @param ClassB $b
 */

The user clicks on ClassA. I can easily find out he clicked inside the docblock, but how do I find out he clicked ClassA?

felixfbecker avatar Jul 14 '17 16:07 felixfbecker

Ok, I understand your usecase.

It might work to use the position of a tag in the array returned by getTags + the number of lines in description and summary. That will give you the right position. PREG_OFFSET_CAPTURE will only give you the number of the capture group. So when a description has multiple lines this will give you an invalid offset.

From a phpdocumentor point of view we would implement this in the project itself and not in this library.

jaapio avatar Jul 14 '17 20:07 jaapio

hey, any progress on this one? It's been one year already... can we somehow contribute? thanks

razvanphp avatar Aug 09 '18 20:08 razvanphp

We will accept a pr for this issue. As I wrote before, from a phpdocumentor perspective this does not have priority.

So it won't be picked up very soon by any member of the team.

jaapio avatar Aug 09 '18 20:08 jaapio

Thinking about this request purely from the ReflectionDocBlock perspective, maybe it would be useful to have this capability in here, since locations inside the docblock are still "metadata about the docblock".

ashnazg avatar Aug 23 '18 18:08 ashnazg