Peekmo / atom-autocomplete-php

Autocomplete for PHP in atom editor
MIT License
136 stars 34 forks source link

[Feature Request] Show classes from the parent namespaces above vendor ones. #217

Open cabloo opened 8 years ago

cabloo commented 8 years ago

If I type Request from a file in app/, I would expect App\Http\Requests\Request (and any other classes in the Requests namespace) to show above Illuminate\Http\Request but this isn't always the case.

Peekmo commented 8 years ago

I think that it's because the "fuzzy" search is done on the whole namespace and not only class names. Perhaps a search on class name only could be interesting.

I don't know..

cabloo commented 8 years ago

@Peekmo in this case, Request is in both class names, so that wouldn't help this situation. That being said, I think that'd be a good feature since usually you wouldn't type the namespace when trying to autocomplete the class name.

Specifically, the problem for me is that when I'm editing files in the App namespace, I would expect other files in the App namespace to show up as a priority over those in other namespaces.

Peekmo commented 8 years ago

If the fuzzy search was only on class name, you will only have classes with the name you type. So it will help. Today with a whole namespace search, it often happens in fact, that the class name you type is not returned.

For your second demand, it will be really hard (and perhaps impossible without an UGLY thing)

cabloo commented 8 years ago

@Peekmo I see, you're saying there will be less results and thus it will be easier to find what you're looking for.

For me the ideal situation is that the first result is right almost every time, so I can just hit enter and it works. So what about a simple sort by string difference, which would compare the current file namespace and the file namespace of each recommended class that comes up in the list. E.g. Levenshtein distance algorithm - JS implementation. It's not ideal but better than nothing.

A more simplistic approach would be to just compare the first "word" (so to speak) of the namespace. Any items matching the root namespace (in my case App would show up first).

I would offer to attempt implementing this but am really busy for the next couple weeks.

Peekmo commented 8 years ago

Yep exactly, less results, so more chance to have the one that you want in the list.

It's possible to sort by namespace, but if your class is not in the top 10 results returned by the fuzzy search, your class will not be shown at all. But in most cases, it will work.

The big problem is that the search will be different from atom's one with this (atom use fuzzy on full path when you use "find file" command). And it's not that hard to find something that match the class that you want first. For example, when I want to import Symfony\Component\HttpFoundation\Request I only type "SyRequ" and it's the first result. It's a bit tricky but you can import everything easily when you have the trick^^. If I put current namespace's classes first, it will not be possible to have vendor classes first anymore and that's sad ^^

I really don't know what to do.. Perhaps an option in plugin configuration to choose ?

cabloo commented 8 years ago

What do you mean by only the top 10 results returned by fuzzy search show? for me there are sometimes 25+ results.

I don't see what would be so complex about a simple sort on the list atom returns from the fuzzy search. (of course - you have a much better understanding of what that would entail, but it seems simple to me).

cabloo commented 8 years ago

I'm thinking the sort would be either here or here

Does that make sense?