Open vuon9 opened 11 months ago
Have you seen this feature somewhere? It would be very helpful, but IMHO very difficult to solve. It is not uncommon for imports to be ambiguous, which makes it difficult to automate this. Either the AI can do it itself (apparently it can't) or the dev must decide which import is the correct one. Just an example: It doesn't help if auto-import imports App\Http\Controllers\Controller
but Illuminate\Routing\Controller
would be the right choice. A lot of introspection would be necessary, to determine the correct import.
I think maybe the problem just only about format on save. The AI generation just about the thing in my context.
I don't have an example for another PHP LSP. But Go with gopls
is working with auto imports when saving Go file https://github.com/golang/tools/tree/master/gopls. It works really well on VSCode.
I think for the case that would have over 1 suggestion like Controller
you said, I'm fine with one of below options:
Continue to check if the class would be used for importing also contain the method. For example:
$httpClient = new HttpClient(); // it could be A\HttpClient, B\HttpClient
$httpClient->get(); // it could be a HttpClient contains the method.
This is how it is showing today
Just skip auto-import for that missing package if there is a potential confusion.
I agree that would be a lot of scenarios that need to think about.
Marginally related, it would be nice to be able to import/use all missing classes from the current file, instead of clicking on Quick Fix for each error.
Here is how it looks on DART language:
I'm not sure if this is a feature or a thing that I don't know, but how can I have auto import and additionally remove unused imports with "editor.formatOnSave"?
When using Github Copilot, it would be helpful if auto-import could assist me after I choose a suggestion and save it.