Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS Code autocomplete Symfony doesn't work

I use vs code but I can't get autocomplete on a doctrine entity when I'm in a controller. For example: $user->getNa... doesn't show getName().

I tried a lot of plugins but no one worked (PHP IntelliSense, PHP Intelephense, PHP Intellisense-Crane, PHP-Autocomplete, Symfony for VSCode, Symfony Snippets).

public function nameAction(Request $request)
{
    $em = $this->getDoctrine()->getManager();
    $EntitiyRepository = $em->getRepository('AppBundle:Entitiy');
    $user = $EntitiyRepository->find(5);
    $company = $user->getcomp
    return $this->render('index.html.twig');
}
like image 203
L01C Avatar asked Aug 22 '26 16:08

L01C


2 Answers

You should probably type hint for VSCode to know which type gets returned by the find method.

public function nameAction(Request $request)
{
    $em = $this->getDoctrine()->getManager();
    $EntitiyRepository = $em->getRepository('AppBundle:Entitiy');
    /** @var User $user */
    $user = $EntitiyRepository->find(5);
    $company = $user->getcomp
    return $this->render('index.html.twig');
}
like image 148
Jeroen Avatar answered Aug 24 '26 13:08

Jeroen


you need to install this extension and add this code to your settings.json or .code-workspace file

  "editor.quickSuggestions": {
    "other": true,
    "comments": true,
    "strings": true
  }
like image 20
texnicii Avatar answered Aug 24 '26 13:08

texnicii