-
Notifications
You must be signed in to change notification settings - Fork 8
[POC][Improvement] completion handle aliases #33
base: master
Are you sure you want to change the base?
[POC][Improvement] completion handle aliases #33
Conversation
Before all I did was trying to find the most accurate name to use depending on the import table. It actually not the job of the completor but the responsibility of the user. This commit will instead resolve a class suggestion to a list of suggestions in order for the user to pick the one he wants.
I want to extract the logic in order to reuse it in DoctrineAnnotationCompletor Inheritance is not suited in this case, the only remaining options I can think of are: * Using a static method in an helper class * Injecting a new dependency I don't think injecting a dependency is a good solution here since I can't think of a different implementation I might want to inject. The helper class with a static method is a possibility but I think trait are also meant for scenarios like this one. So I kept the trait to open a new debate :)
Instead of suggesting on |
Yes, that was the first item in phpactor/phpactor#1121 |
Searching by FQN is trivial to add fortunately |
Given the above is now merged -- would it make sense to do namespace and import name completion instead of this?
Not against this - but if this can be accomplished in another way it might be redundant to have? |
For me this is two complementary features. With only the search by relative qualified name we still need to type the alias like While the improvement you've done on the indexer will indeed grant us the possibility to discover available names, which is always useful in new/large code base. I grant you the last one is really an edge case :) Bottom line I think we can keep this one, with upgrade if necessary, and create another one to complete relative qualified name. |
But that can be a separate thing -- we should add:
in the completion extension |
284cf95
to
cebd325
Compare
We want to have a dedicated completor for the resolved import suggestions. The idea is to register multiple time the same completor but with different dependencies: NameSearcherCompletor => Find names with indexer and genrate the suggestions TolerantNameSearcherCompletor => complete class names using a NameSearcherCompletor DoctrineAnnotationCompletor => complete annotations using a NameSearcherCompletor ImportedNameSearcherCompletor => complete with import table from the suggestions of a NameSearcherCompletor Completors: TolerantNameSearcherCompletor(NameSearcherCompletor) DoctrineAnnotationCompletor(NameSearcherCompletor) TolerantNameSearcherCompletor(ImportedNameSearcherCompletor) DoctrineAnnotationCompletor(ImportedNameSearcherCompletor)
I updated with the implementation we discussed earlier. PR for |
Hi,
That's an attempt to deal with aliases from the import table when completing classes (see phpactor/phpactor#1121).
I tried to not keep it as clean as possible but it still kind of a POC to see how you feel about the idea so don't hesitate: the more critics the better 😄
I decided to put it on the
ChainTolerantCompletor
because we need the parser to get the import table and I wanted it to work for all class completors without having to deal with them one by one.The new
DoctrineAnnotationCompletor
is a bit special so I had to extract the logic into a trait.As I said in the commit message I did it to because it feels a right use case but if you prefer an helper class with static methods it's also possible of course.
I've mainly used the automated test for now, just one or two manual test in a demo project to make sure it works.
I will update my work environment on Monday so that I can test it in a more realistic code base.
Todos: