mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-01-23 14:00:05 +08:00
Add post for php layer (#2798)
Change phpcd to phpcomplete, as phpcd does not work in windows
This commit is contained in:
parent
101097bf8b
commit
64708d7856
@ -23,6 +23,8 @@
|
||||
"docs/_posts/2019-02-12-use-vim-as-a-perl-ide.md": {"alternate": "docs/_posts/2019-02-11-use-vim-as-a-perl-ide.md"},
|
||||
"docs/_posts/2019-02-17-use-vim-as-a-ruby-ide.md": {"alternate": "docs/_posts/2019-02-18-use-vim-as-a-ruby-ide.md"},
|
||||
"docs/_posts/2019-02-18-use-vim-as-a-ruby-ide.md": {"alternate": "docs/_posts/2019-02-17-use-vim-as-a-ruby-ide.md"},
|
||||
"docs/_posts/2019-05-08-use-vim-as-a-php-ide.md": {"alternate": "docs/_posts/2019-05-09-use-vim-as-a-php-ide.md"},
|
||||
"docs/_posts/2019-05-09-use-vim-as-a-php-ide.md": {"alternate": "docs/_posts/2019-05-08-use-vim-as-a-php-ide.md"},
|
||||
"docs/_posts/2018-09-27-use-vim-as-ide.md": {"alternate": "docs/_posts/2018-09-28-use-vim-as-ide.md"},
|
||||
"docs/_posts/2018-01-23-grep-on-the-fly-in-spacevim.md": {"alternate": "docs/_posts/2018-01-31-grep-on-the-fly-in-spacevim.md"},
|
||||
"docs/_posts/2018-01-31-grep-on-the-fly-in-spacevim.md": {"alternate": "docs/_posts/2018-01-23-grep-on-the-fly-in-spacevim.md"},
|
||||
|
@ -12,15 +12,6 @@
|
||||
" @parentsection layers
|
||||
" This layer is for PHP development. It proides code completion, syntax
|
||||
" checking, and jump to definition.
|
||||
"
|
||||
" Requirements:
|
||||
" >
|
||||
" PHP 5.3+
|
||||
" PCNTL Extension
|
||||
" Msgpack 0.5.7+(for NeoVim)Extension: https://github.com/msgpack/msgpack-php
|
||||
" JSON(for Vim 7.4+)Extension
|
||||
" Composer Project
|
||||
" <
|
||||
|
||||
|
||||
|
||||
@ -32,9 +23,8 @@ function! SpaceVim#layers#lang#php#plugins() abort
|
||||
if SpaceVim#layers#lsp#check_filetype('php')
|
||||
call add(plugins, ['felixfbecker/php-language-server', {'on_ft' : 'php', 'build' : 'composer install && composer run-script parse-stubs'}])
|
||||
else
|
||||
call add(plugins, ['php-vim/phpcd.vim', { 'on_ft' : 'php', 'build' : ['composer', 'install']}])
|
||||
call add(plugins, ['shawncplus/phpcomplete.vim', { 'on_ft' : 'php'}])
|
||||
endif
|
||||
call add(plugins, ['lvht/phpfold.vim', { 'on_ft' : 'php', 'build' : ['composer', 'install']}])
|
||||
return plugins
|
||||
endfunction
|
||||
|
||||
@ -46,6 +36,7 @@ endfunction
|
||||
|
||||
function! SpaceVim#layers#lang#php#config() abort
|
||||
call SpaceVim#plugins#runner#reg_runner('php', 'php %s')
|
||||
call SpaceVim#plugins#repl#reg('php', ['php', '-a'])
|
||||
call SpaceVim#mapping#space#regesit_lang_mappings('php',
|
||||
\ function('s:on_ft'))
|
||||
if SpaceVim#layers#lsp#check_filetype('php')
|
||||
@ -67,6 +58,17 @@ function! SpaceVim#layers#lang#php#config() abort
|
||||
augroup END
|
||||
endif
|
||||
|
||||
" let g:neomake_php_php_maker = {
|
||||
" \ 'args': ['-l', '-d', 'error_reporting=E_ALL', '-d', 'display_errors=1', '-d', 'log_errors=0'],
|
||||
" \ 'errorformat':
|
||||
" \ '%-GNo syntax errors detected in%.%#,'.
|
||||
" \ '%EParse error: syntax error\, %m in %f on line %l,'.
|
||||
" \ '%EParse error: %m in %f on line %l,'.
|
||||
" \ '%EFatal error: %m in %f on line %l,'.
|
||||
" \ '%-G\s%#,'.
|
||||
" \ '%-GErrors parsing %.%#',
|
||||
" \ 'output_stream': 'stderr',
|
||||
" \ }
|
||||
endfunction
|
||||
|
||||
function! s:on_ft() abort
|
||||
@ -81,6 +83,20 @@ function! s:on_ft() abort
|
||||
call SpaceVim#mapping#space#langSPC('nmap', ['l','r'],
|
||||
\ 'call SpaceVim#plugins#runner#open()',
|
||||
\ 'execute current file', 1)
|
||||
|
||||
let g:_spacevim_mappings_space.l.s = {'name' : '+Send'}
|
||||
call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 'i'],
|
||||
\ 'call SpaceVim#plugins#repl#start("php")',
|
||||
\ 'start REPL process', 1)
|
||||
call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 'l'],
|
||||
\ 'call SpaceVim#plugins#repl#send("line")',
|
||||
\ 'send line and keep code buffer focused', 1)
|
||||
call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 'b'],
|
||||
\ 'call SpaceVim#plugins#repl#send("buffer")',
|
||||
\ 'send buffer and keep code buffer focused', 1)
|
||||
call SpaceVim#mapping#space#langSPC('nmap', ['l','s', 's'],
|
||||
\ 'call SpaceVim#plugins#repl#send("selection")',
|
||||
\ 'send selection and keep code buffer focused', 1)
|
||||
endfunction
|
||||
|
||||
function! s:phpBeautify() abort
|
||||
|
@ -1271,15 +1271,6 @@ LANG#PHP *SpaceVim-layer-lang-php*
|
||||
This layer is for PHP development. It proides code completion, syntax
|
||||
checking, and jump to definition.
|
||||
|
||||
Requirements:
|
||||
>
|
||||
PHP 5.3+
|
||||
PCNTL Extension
|
||||
Msgpack 0.5.7+(for NeoVim)Extension: https://github.com/msgpack/msgpack-php
|
||||
JSON(for Vim 7.4+)Extension
|
||||
Composer Project
|
||||
<
|
||||
|
||||
==============================================================================
|
||||
LANG#PONY *SpaceVim-layer-lang-pony*
|
||||
|
||||
|
99
docs/_posts/2019-05-08-use-vim-as-a-php-ide.md
Normal file
99
docs/_posts/2019-05-08-use-vim-as-a-php-ide.md
Normal file
@ -0,0 +1,99 @@
|
||||
---
|
||||
title: "Use Vim as a PHP IDE"
|
||||
categories: [tutorials, blog]
|
||||
image: https://user-images.githubusercontent.com/13142418/57497567-c6948480-730a-11e9-95ec-e44bf6e79984.png
|
||||
excerpt: "A general guide for using SpaceVim as PHP IDE, including layer configuration, requiems installation and usage."
|
||||
type: BlogPosting
|
||||
comments: true
|
||||
commentsID: "Use Vim as a PHP IDE"
|
||||
---
|
||||
|
||||
# [Blogs](../blog/) >> Use Vim as a PHP IDE
|
||||
|
||||
This is a general guide for using SpaceVim as a PHP IDE, including layer configuration and usage.
|
||||
Each of the following sections will be covered:
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [Enable language layer](#enable-language-layer)
|
||||
- [Code completion](#code-completion)
|
||||
- [Syntax linting](#syntax-linting)
|
||||
- [Jump to test file](#jump-to-test-file)
|
||||
- [running code](#running-code)
|
||||
- [Code formatting](#code-formatting)
|
||||
- [REPL support](#repl-support)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
### Enable language layer
|
||||
|
||||
To add PHP language support in SpaceVim, you need to enable the `lang#php` layer. Press `SPC f v d` to open
|
||||
SpaceVim configuration file, and add the following snippet:
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = "lang#php"
|
||||
```
|
||||
|
||||
For more info, you can read the [lang#php](../layers/lang/php/) layer documentation.
|
||||
|
||||
### Code completion
|
||||
|
||||
`lang#php` layer will load the PHP plugin automatically, unless it's overriden in your `init.toml`.
|
||||
The completion menu will be opened as you type.
|
||||
|
||||
![phpide](https://user-images.githubusercontent.com/13142418/57497567-c6948480-730a-11e9-95ec-e44bf6e79984.png)
|
||||
|
||||
### Syntax linting
|
||||
|
||||
The checkers layer is enabled by default. This layer provides asynchronous syntax linting via [neomake](https://github.com/neomake/neomake).
|
||||
It will run [psalm](https://github.com/vimeo/psalm) asynchronously.
|
||||
|
||||
To install psalm, you may need to run:
|
||||
|
||||
```sh
|
||||
composer require --dev vimeo/psalm
|
||||
```
|
||||
|
||||
### Jump to test file
|
||||
|
||||
To manage the alternate file for a project, you may need to create a `.project_alt.json` file in the root of your
|
||||
project.
|
||||
|
||||
for exmaple, add following content into the `.project_alt.json` file:
|
||||
|
||||
```json
|
||||
{
|
||||
"src/*.php": {"alternate": "test/{}.php"},
|
||||
"test/*.php": {"alternate": "src/{}.php"}
|
||||
}
|
||||
```
|
||||
|
||||
with this configuration, you can jump between the source code and test file via command `:A`
|
||||
|
||||
### running code
|
||||
|
||||
To run current script, you can press `SPC l r`, and a split window
|
||||
will be openen, the output of the script will be shown in this window.
|
||||
It is running asynchronously, and will not block your Vim.
|
||||
|
||||
![phpcoderunner](https://user-images.githubusercontent.com/13142418/57496602-79aeaf00-7306-11e9-8c18-32f00bd28307.gif)
|
||||
|
||||
### Code formatting
|
||||
|
||||
The format layer is also enabled by default. With this layer you can use key binding `SPC b f` to format current buffer.
|
||||
Before using this feature, please install php_beautifier:
|
||||
|
||||
```sh
|
||||
pear install PHP_Beautifier
|
||||
```
|
||||
|
||||
### REPL support
|
||||
|
||||
Start a `php -a` inferior REPL process with `SPC l s i`. After the REPL process being started, you can
|
||||
send code to inferior process. All key bindings prefix with `SPC l s`, including sending line, sending selection or even
|
||||
send whole buffer.
|
||||
|
||||
![phprepl](https://user-images.githubusercontent.com/13142418/57497156-0ce8e400-7309-11e9-8628-da42d6f8432e.gif)
|
||||
|
||||
|
121
docs/_posts/2019-05-09-use-vim-as-a-php-ide.md
Normal file
121
docs/_posts/2019-05-09-use-vim-as-a-php-ide.md
Normal file
@ -0,0 +1,121 @@
|
||||
---
|
||||
title: "使用 Vim 搭建 PHP 开发环境"
|
||||
categories: [tutorials_cn, blog_cn]
|
||||
image: https://user-images.githubusercontent.com/13142418/57497567-c6948480-730a-11e9-95ec-e44bf6e79984.png
|
||||
excerpt: "这篇文章主要介绍如何使用 SpaceVim 搭建 PHP 的开发环境,简介 lang#php 模块所支持的功能特性以及使用技巧"
|
||||
permalink: /cn/:title/
|
||||
lang: cn
|
||||
type: BlogPosting
|
||||
comments: true
|
||||
commentsID: "使用 Vim 搭建 PHP 开发环境"
|
||||
---
|
||||
|
||||
# [Blogs](../blog/) >> 使用 Vim 搭建 PHP 开发环境
|
||||
|
||||
![phpide](https://user-images.githubusercontent.com/13142418/57497567-c6948480-730a-11e9-95ec-e44bf6e79984.png)
|
||||
|
||||
SpaceVim 是一个模块化的 Vim IDE,针对 PHP 这一语言的支持主要依靠 `lang#php` 模块以及与之相关的其它模块。
|
||||
的这篇文章主要介绍如何使用 SpaceVim 搭建 PHP 的开发环境,侧重介绍跟 PHP 开发相关使用技巧。
|
||||
在阅读这篇文章之前,可以先阅读《[使用 Vim 搭建基础的开发环境](../use-vim-as-ide/)》,对语言相关以外的功能有一个大致的了解。
|
||||
|
||||
<!-- vim-markdown-toc GFM -->
|
||||
|
||||
- [安装模块](#安装模块)
|
||||
- [代码自动补全](#代码自动补全)
|
||||
- [语法检查](#语法检查)
|
||||
- [工程文件跳转](#工程文件跳转)
|
||||
- [代码格式化](#代码格式化)
|
||||
- [快速运行](#快速运行)
|
||||
- [交互式编程](#交互式编程)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
### 安装模块
|
||||
|
||||
SpaceVim 初次安装时默认并未启用相关语言模块。首先需要启用
|
||||
`lang#php` 模块,通过快捷键 `SPC f v d` 打开配置文件,添加如下片断:
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = "lang#php"
|
||||
```
|
||||
|
||||
启用 `lang#php` 模块后,在打开 PHP 文件时,就可以使用语言专属快捷键,这些快捷键都是以 `SPC l` 为前缀的。
|
||||
|
||||
### 代码自动补全
|
||||
|
||||
`autocomplete` 模块为 SpaceVim 提供了自动补全功能,目前针对 PHP 而言,比较好的补全方案是配合使用 lsp 模块:
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = "lsp"
|
||||
```
|
||||
|
||||
lsp 模块默认使用 `php-language-server` 作为 PHP 的语言服务器后台命令。
|
||||
|
||||
在配置文件中添加如下内容即可为 PHP 启用语言服务器:
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = "lsp"
|
||||
filetypes = [
|
||||
"php"
|
||||
]
|
||||
[layers.override_cmd]
|
||||
php = ["php-language-server"]
|
||||
```
|
||||
|
||||
### 语法检查
|
||||
|
||||
`checkers` 模块为 SpaceVim 提供了语法检查的功能,该模块默认已经载入。该模块默认使用 [neomake](https://github.com/neomake/neomake)
|
||||
这一异步语法检查工具。对于 PHP 的支持,是通过异步调用 [psalm](https://github.com/vimeo/psalm) 命令来完成的。
|
||||
|
||||
使用 composer 安装 paslm 命令:
|
||||
|
||||
```sh
|
||||
composer require --dev vimeo/psalm
|
||||
```
|
||||
|
||||
### 工程文件跳转
|
||||
|
||||
SpaceVim 自带工程管理插件,可以识别项目根目录,自动跳转 alternate 文件。需要在项目根目录添加工程文件 `.project_alt.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"src/*.php": {"alternate": "test/{}.php"},
|
||||
"test/*.php": {"alternate": "src/{}.php"}
|
||||
}
|
||||
```
|
||||
|
||||
通过以上的配置,就可以使用命令 `:A` 在源文件和测试文件之间进行跳转。
|
||||
|
||||
|
||||
### 代码格式化
|
||||
|
||||
PHP 代码格式化,主要依赖 `format` 模块,同时需要安装相关的后台命令 php_beautifier,默认快捷键为 `SPC b f` :
|
||||
|
||||
```toml
|
||||
[[layers]]
|
||||
name = "format"
|
||||
```
|
||||
|
||||
使用 pear 安装 PHP_Beautifier:
|
||||
|
||||
```sh
|
||||
pear install PHP_Beautifier
|
||||
```
|
||||
|
||||
|
||||
### 快速运行
|
||||
|
||||
在编辑 PHP 文件时,可以快速运行当前文件,默认的快捷键是 `SPC l r` 。按下后,
|
||||
会在屏幕下方打开一个插件窗口,运行的结果会被展示在窗口内。于此同时,光标并不会跳到该插件窗口,避免影响编辑。在这里需要说明下,
|
||||
|
||||
![phpcoderunner](https://user-images.githubusercontent.com/13142418/57496602-79aeaf00-7306-11e9-8c18-32f00bd28307.gif)
|
||||
|
||||
### 交互式编程
|
||||
|
||||
在编辑 PHP 文件时,可通过快捷键 `SPC l s i` 启动 `php -a` 交互窗口,
|
||||
之后使用快捷键将代码发送至解释器。默认快捷键都以 `SPC l s` 为前缀。
|
||||
|
||||
![phprepl](https://user-images.githubusercontent.com/13142418/57497156-0ce8e400-7309-11e9-8628-da42d6f8432e.gif)
|
@ -1,6 +1,6 @@
|
||||
---
|
||||
title: "SpaceVim lang#php layer"
|
||||
description: "This layer adds PHP language support to SpaceVim"
|
||||
description: "PHP language support, including code completion, syntax lint and code runner"
|
||||
---
|
||||
|
||||
# [Available Layers](../../) >> lang#php
|
||||
@ -10,7 +10,9 @@ description: "This layer adds PHP language support to SpaceVim"
|
||||
- [Description](#description)
|
||||
- [Features](#features)
|
||||
- [Install](#install)
|
||||
- [Requirement](#requirement)
|
||||
- [Key bindings](#key-bindings)
|
||||
- [Jump to definition](#jump-to-definition)
|
||||
- [Running current script](#running-current-script)
|
||||
|
||||
<!-- vim-markdown-toc -->
|
||||
|
||||
@ -35,10 +37,15 @@ To use this configuration layer, update custom configuration file with:
|
||||
name = "lang#php"
|
||||
```
|
||||
|
||||
### Requirement
|
||||
## Key bindings
|
||||
|
||||
1. [PHP 5.3+](http://php.net/)
|
||||
2. [PCNTL](http://php.net/manual/en/book.pcntl.php) Extension
|
||||
3. [Msgpack 0.5.7+(for NeoVim)](https://github.com/msgpack/msgpack-php) Extension or [JSON(for Vim 7.4+)](http://php.net/manual/en/intro.json.php) Extension
|
||||
4. [Composer](https://getcomposer.org/) Project
|
||||
### Jump to definition
|
||||
|
||||
| Mode | Key Bindings | Description |
|
||||
| ------ | ------------ | ------------------------------------------------ |
|
||||
| normal | `g d` | Jump to the definition position of cursor symbol |
|
||||
|
||||
### Running current script
|
||||
|
||||
To running a php script, you can press `SPC l r` to run current file without loss focus,
|
||||
and the result will be shown in a runner buffer.
|
||||
|
Loading…
Reference in New Issue
Block a user