使用 vscode 开发 php 技巧和扩展

扩展推荐

  • bmewburn.vscode-intelephense-client php-lsp 语言服务器 官网

# 功能
Code completion. Fast camel/underscore case context aware suggestions with automatic addition of use declarations.
Signature help. View detailed parameter hints for call expressions.
Go to definition. Quickly navigate to symbol definitions.
Find all references. Quickly find symbol references within the workspace.
Symbol search. Fast camel/underscore text search for workspace and document symbol definitions.
Diagnostics. Error tolerant parser and powerful static analysis engine report problems as you type.
Formatting. PSR12 compatible full document and range formatting.
Embedded language support. Includes HTML/JS/CSS code intelligence too.
Hover. Detailed hover information with links to official PHP documentation.
Highlight. Smart highlighting of references and keywords.
# 购买授权版本,获得更多功能
starRename.star Easily rename symbols with automatic file/folder renaming too.
starCode folding.star Accurate folding of definitions, blocks, use declarations, heredoc, comments, and custom regions.
starFind all implementations.star Quickly find implementations of interfaces, abstract classes and associated methods.
starGo to type definition.star Quickly navigate to variables and parameter type definitions.
starGo to declaration.star Quickly navigate to interface or abstract method declarations.
starSmart select.star Intelligently expand/shrink text selection based on parse tree.
starCode actions.star Import symbols, add (template configurable) PHPDoc, and implement all abstract methods.
  • neilbrayfield.php-docblocker 注释生成

# 快捷键是 /** 即可出现提示
/**
* 金币抽奖
*
* @param array $value
* @return void
* @copyright lxx
* @author lxx
*/
public function gold_luck_draw($value = [])
{}
  • felixfbecker.php-debug DEBUG 用

# 不多解释,php开发者必会使用
  • rifi2k.format-html-in-php 格式化 html-in-php

# 偶尔使用
  • mhutchie.git-graph git记录查看

# 方便查看commit log
  • sonarsource.sonarlint-vscode 语法提示和矫正 官网

# 支持多种语言
  • usernamehw.errorlens 配合 sonarlint 在编辑器中提供优雅的提示

  • humao.rest-client api模拟请求,非常好用

api调试.http

### 请求登录数据
POST http://api.qq.com/app/ HTTP/1.1
content-type: application/json

{
  "param": {
    "info": "
  },
  "platform": "wechat_app",
  "version": "1.1",
  "hid": 1
}

php内置扩展的智能跳转

  • 安装 bmewburn.vscode-intelephense-client 之后,php的函数会出现智能提示,但是使用 内置扩展如: redis,pdo-mysql,curl,gd等等内置函数的时候,扩展不全免,下面来解决这个问题.以下方法是非侵入式的,侵入式请直接用composer直接安装到项目即可

# 下载 phpstorm-stubs
https://github.com/JetBrains/phpstorm-stubs/releases
# 解压到 当前项目: .vscode\ 文件夹里面
ls
phpstorm-stubs-2019.3
pax_global_header

# 重启编辑器,之后即可
  • 函数提示

Bbb9tH.png

  • 参数提示

BbbVnf.png

快捷键
终极奥义:VSCode左下角 “管理 / Manage” -> “键盘快捷方式 / Keyboard Shortcuts” -> 搜索 “前进 / Go Forward 或 后退 / Go Back”

  • 配置

// 本地文件记录历史数量,0=不记录本地文件
"workbench.localHistory.maxFileEntries": 3