【问题标题】:PHP Intellisense in Visual Studio CodePHP IntelliSense在Visual Studio代码中
【发布时间】:2018-08-25 03:19:27
【问题描述】:

我正在使用 Visual Studio Code 在 PHP 中进行开发,但在获取 Code 以提供正确的智能感知结果时遇到了一些麻烦。例如,这个新创建的 Codeception 单元测试:

<?php

class MyTest extends \Codeception\Test\Unit
{
    /**
     * @var \UnitTester
     */
    protected $tester;

    protected function _before()
    {
    }

    protected function _after()
    {
    }

    // tests
    public function testSomeFeature()
    {
        $this->assertFalse(false);
    }
}

当我输入$this-&gt; 时,我希望看到assertFalseassertTrue 以及\Codeception\Test\Unit 提供的所有其他方法。但我得到的基本上是当前文件中存在的任何项目,仅此而已。

我该怎么做才能让Unit 类中的所有方法都显示出来?我已经安装了 PHP IntelliSense 扩展 v2.3.4。

【问题讨论】:

  • Visual Studio Code 默认不包含 PHP 语言服务器。您需要安装第三方扩展。我推荐 PHP Intelephense
  • @ÁlvaroGonzález 谢谢你的建议。您是否建议在添加 PHP IntelliSense 扩展之前删除它?
  • 哦,我不知道你已经有了 PHP 扩展。你当然不应该同时拥有两者,因为你会到处得到重复的东西。
  • @ÁlvaroGonzález 只是想让您知道 PHP Intelephense 的工作方式与我希望的完全一样。不知道为什么 PHP IntelliSense 插件不起作用。也许您的评论可以作为这个问题的答案?

标签: visual-studio-code vscode-settings


【解决方案1】:

Visual Studio Code 核心不包括高级 PHP 功能,只要您安装了 PHP 二进制文件,它就只包含语法突出显示、简单的代码完成和代码检查。简而言之,您可以使用这些指令配置的功能:

// Controls whether the built-in PHP language suggestions are enabled. The support suggests PHP globals and variables.
"php.suggest.basic": true,

// Enable/disable built-in PHP validation.
"php.validate.enable": true,

// Points to the PHP executable.
"php.validate.executablePath": null,

// Whether the linter is run on save or on type.
"php.validate.run": "onSave"

对于其他任何你需要安装第三方扩展。

我个人的选择是PHP Intelephense。特别是,它支持 docblock 注释,包括魔法属性:

/**
 * @property string $foo
 */
class Bar
{
}

...和内联类型:

/** @var \Database $db */
$db->connect();

【讨论】:

  • 我相信它目前正在积极维护。
  • @DenisPshenov 你是对的。它最近收到了一些重要的更新。
  • PHP Intelephense 很棒
  • php inteliphense 是部分免费的,让您为 refarcorting 等基本功能付费。最好等到 MS 赶上来。截至 2021 年,还没有发生
  • 除了 Intelephense 有没有好的免费替代品?
猜你喜欢
  • 2010-09-10
  • 2022-01-14
  • 1970-01-01
  • 2016-07-29
  • 2016-09-23
  • 2017-05-08
  • 1970-01-01
  • 2011-02-27
  • 1970-01-01
相关资源
最近更新 更多