有没有办法使Visual Studio代码识别PHP文件中的HTML语法

时间:2017-08-29 20:39:36

标签: php html autocomplete visual-studio-code

我在Mac上使用Visual Studio Code来处理WordPress应用程序。

有没有办法让Visual Studio代码识别HTML并在PHP文件中使用它的功能(主要是自动完成)?

之前我已经搜索过这个答案,但只是被告知转到Visual Studio代码设置:File >> Preferences >> User Settings

// Place your settings in this file to overwrite the default settings
{                
// Configure file associations to languages (e.g. "*.extension": "html"). These have precedence over the default associations of the languages installed.
     "files.associations": {"*.php": "html"}     
 }

但这样做会让您失去所有PHP支持和自动完成功能。

我希望Microsoft能够意识到PHP开发人员在创建应用程序/网站时通常会同时使用PHP和HTML。如果可能的话,我很乐意使用VS Code而不是华丽但昂贵的PHP风暴。

3 个答案:

答案 0 :(得分:2)

据我所知,确实如此。看看我用VS Code创建的此php文件(无扩展名),文件中带有HTML,并突出显示了两种语言的语法。 enter image description here

在屏幕的右下角有一个按钮(应该说PHP这个词),您可以将语法高亮和自动完成功能切换为另一种语言,尽管这确实会暂时关闭PHP语法,但它将允许您可以更轻松地用HTML编写代码。

答案 1 :(得分:2)

您可以通过在 settings.json 文件中添加以下内容来启用任何语言的 html 支持:

"emmet.includeLanguages": {
    "your-language": "html",
    "rust": "html",
    "php": "html",
    "javascript": "html",
}

答案 2 :(得分:0)

你可以安装这个插件 intellisense-plugin