phpDocumentor / ReflectionDocBlock

MIT License
9.35k stars 118 forks source link

Location information for tags #87

Open felixfbecker opened 7 years ago

felixfbecker commented 7 years ago

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 commented 7 years ago

This should easy with PREG_OFFSET_CAPTURE

jaapio commented 7 years ago

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.

felixfbecker commented 7 years ago

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?

jaapio commented 7 years ago

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.

razvanphp commented 6 years ago

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

jaapio commented 6 years ago

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.

ashnazg commented 6 years ago

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".