L01C
L01C

Reputation: 753

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');
}

Upvotes: 3

Views: 8105

Answers (2)

texnicii
texnicii

Reputation: 171

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
  }

Upvotes: 1

Jeroen
Jeroen

Reputation: 2031

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');
}

Upvotes: 3

Related Questions