shawncplus/phpcomplete.vim

return types in interfaces

Closed this issue · 8 comments

My use case code can be found here: https://gist.github.com/koenhoeymans/8e25a2ac01a20621cddb

When typing $this->bar()-> within the testAutocomplete' method I would expect autocomplete to suggest bar and test. It doesn't suggest anything. I've also tried with @inherit, @inheritDoc and {@inheritDoc}.

With extended classes things work as expected.

While there's no explicit support for @inhertiDoc or such tags, it do seem to work with normal subclasses. This is because contents of an implemented interface is not considered at all since (this was my reasoning) you should have all the methods already implemented in some class in the hierarchy. I'm afraid I've never thought about docbocks in them.

Thank you for reporting this, I'll look into it.

There seems to be no consensus about what tag should be used. My personal opinion is that no tag should be necessary (unless you would want to add/document implementation specifics) but for generating documentation it can be nice to have one to create a direct link to the interface.

I've pushed a commit which should fix your issue by grabbing the contents of implemented interfaces with the docblocks in them as it do for classes (no built-in interface support though). Please check it out.

Works perfect. Thank you. The built-in @return interface support would be very nice also. I'll open another ticket for that.

In a subsequent commit i've pushed a change to GenerateBuiltinClassStub() so it can create "source code" for the built-in interfaces so the plugin can pick it up as it were a user created one.
This means if you have a class that implements say DateTimeInterFace, you should get the methods of that interface when complete for an instance of that class.

Here's an example of what I meant, and has a more complex implementation:

https://github.com/koenhoeymans/Fjor/blob/master/src/FjorDsl.php

Suppose I create a new method in this class and start typing $this->given()-> I would expect thenUse, constructWith and andMethod to show as suggestions.

Oh, i see. That's because i was pretty shortsighted when did the extends keyword implementation and to frankly forgot about that interfaces can extend each other as well. The good news is that it's easily fixable (-:

I've pushed a new commit that seem to make your example work as expected.

It works indeed as expected. Thank you.