Answers.Body: <p>Old question I know, but for the sake of having an answer here when people come here from Google...</p>
  <p>You need the Intelephense plugin for VS Code. I'd also recommend looking at this question on Github in order to get autocomplete working: <a href="https://github.com/craftcms/cms/issues/10109" rel="nofollow noreferrer">https://github.com/craftcms/cms/issues/10109</a></p>
  <p>In a nutshell:</p>
  <p>Add a file called <code>vscode_fix.sh</code> to the root of your craft cms repo. Add the execute permission to it <code>chmod +x vscode_fix.sh</code>. Add the following to it:</p>
  <pre class="lang-bash prettyprint-override"><code>#!/bin/bash
  
  # Because vscode.
  # https://github.com/craftcms/cms/issues/10109
  
  if ! grep -qF '@property \craft\web\Application|\craft\console\Application $app' vendor/craftcms/cms/src/Craft.php; then
    sed -i.bak 's/ \* @mixin CraftTrait/ \* @mixin CraftTrait\n \* @property \\craft\\web\\Application|\\craft\\console\\Application \$app/' vendor/craftcms/cms/src/Craft.php &amp;&amp; rm vendor/craftcms/cms/src/Craft.php.bak
  fi
  </code></pre>
  <p>Then, add the following script to your <code>composer.json</code>:</p>
  <pre class="lang-json prettyprint-override"><code>&quot;post-autoload-dump&quot;: [
      &quot;./vscode_fix.sh&quot;
  ]
  </code></pre>
  <p>After running <code>composer update</code> the autoload will be generated and code completion should work.</p>
  <p>This is, just as the above github link says, quite hacky. However since I'm not a fan of phpstorm I chose this route instead of learning to like a new IDE (that I have tried to like many times...)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-01-11T13:10:31.100Z
Answers.LastActivityDate: 2023-01-11T13:10:31.100Z
Answers.UserDisplayName: InanisAtheos
Body: <p>How to achieve autocompletion for Craft 3 for PHP inside Visual Studio Code?
  I mean, what is required (like installing PHP locally, folder structure etc.) if at all possible?</p>
  
  <p>I assume many people who develop PHP are using PHPStorm for this. Also as I recall there are even instructions on how to get autocompletion for Craft 3 inside PHPStorm here: <a href="https://nystudio107.com/blog/so-you-wanna-make-a-craft-3-plugin" rel="noreferrer">link</a>.
  As I'm trying to build some plugins I would prefer setting up an environment that works for me with autocompletion without having to look up everything and playing the guessing game. Out of preference I would like to use Visual Studio Code for this, so currently I'm somewhat stuck as I don't know if it is possible to get a similar kind of autocompletion like in PHPStorm inside Visual Studio Code for Craft 3 and also how to achieve it.
  If someone could point me in a direction, I would be more than happy!</p>
  
Tags: <plugin-development><craft3><php>
Title: Autocomplete for Visual Studio Code for plugin development
ThreadText: # Autocomplete for Visual Studio Code for plugin development
  
  (Asked by: username_0 on 2018-07-04)
  
  How to achieve autocompletion for Craft 3 for PHP inside Visual Studio Code?
  I mean, what is required (like installing PHP locally, folder structure etc.) if at all possible?
  
  I assume many people who develop PHP are using PHPStorm for this. Also as I recall there are even instructions on how to get autocompletion for Craft 3 inside PHPStorm here: [link](https://nystudio107.com/blog/so-you-wanna-make-a-craft-3-plugin).
  As I'm trying to build some plugins I would prefer setting up an environment that works for me with autocompletion without having to look up everything and playing the guessing game. Out of preference I would like to use Visual Studio Code for this, so currently I'm somewhat stuck as I don't know if it is possible to get a similar kind of autocompletion like in PHPStorm inside Visual Studio Code for Craft 3 and also how to achieve it.
  If someone could point me in a direction, I would be more than happy!
  
  **Tags:** plugin-development, craft3, php
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-01-11. Score: 2 | Accepted answer
  
  Old question I know, but for the sake of having an answer here when people come here from Google...
  
  You need the Intelephense plugin for VS Code. I'd also recommend looking at this question on Github in order to get autocomplete working: <https://github.com/craftcms/cms/issues/10109>
  
  In a nutshell:
  
  Add a file called `vscode_fix.sh` to the root of your craft cms repo. Add the execute permission to it `chmod +x vscode_fix.sh`. Add the following to it:
  
  ```bash
  #!/bin/bash
  
  # Because vscode.
  # https://github.com/craftcms/cms/issues/10109
  
  if ! grep -qF '@property \craft\web\Application|\craft\console\Application $app' vendor/craftcms/cms/src/Craft.php; then
    sed -i.bak 's/ \* @mixin CraftTrait/ \* @mixin CraftTrait\n \* @property \\craft\\web\\Application|\\craft\\console\\Application \$app/' vendor/craftcms/cms/src/Craft.php && rm vendor/craftcms/cms/src/Craft.php.bak
  fi
  
  ```
  
  Then, add the following script to your `composer.json`:
  
  ```json
  "post-autoload-dump": [
      "./vscode_fix.sh"
  ]
  
  ```
  
  After running `composer update` the autoload will be generated and code completion should work.
  
  This is, just as the above github link says, quite hacky. However since I'm not a fan of phpstorm I chose this route instead of learning to like a new IDE (that I have tried to like many times...)
  
  
  ---
  
  