From 23c05a3caa077105ed981947f8a5446a2ac1d006 Mon Sep 17 00:00:00 2001 From: Wang Shidong Date: Sat, 24 Apr 2021 16:47:59 +0800 Subject: [PATCH] Update lang#php layer (#4226) --- autoload/SpaceVim/layers/lang/php.vim | 46 +++++++++++++++++-- doc/SpaceVim.txt | 37 ++++++++++++++- .../_posts/2019-05-08-use-vim-as-a-php-ide.md | 21 ++++++++- docs/layers/lang/php.md | 33 ++++++++++--- 4 files changed, 123 insertions(+), 14 deletions(-) diff --git a/autoload/SpaceVim/layers/lang/php.vim b/autoload/SpaceVim/layers/lang/php.vim index 261dbd769..7ce497f7d 100644 --- a/autoload/SpaceVim/layers/lang/php.vim +++ b/autoload/SpaceVim/layers/lang/php.vim @@ -10,8 +10,45 @@ "" " @section lang#php, layer-lang-php " @parentsection layers -" This layer is for PHP development. It proides code completion, syntax -" checking, and jump to definition. +" This layer is for php development, disabled by default, to enable this +" layer, add following snippet to your SpaceVim configuration file. +" > +" [[layers]] +" name = 'lang#php' +" < +" +" @subsection layer options +" +" 1. `php_interpreter`: Set the PHP interpreter, by default, it is `php` +" > +" [[layers]] +" name = 'lang#php' +" php_interpreter = 'path/to/php' +" < +" +" @subsection Key bindings +" > +" Mode Key Function +" --------------------------------------------- +" normal SPC l r run current file +" < +" +" This layer also provides REPL support for php, the key bindings are: +" > +" Key Function +" --------------------------------------------- +" SPC l s i Start a inferior REPL process +" SPC l s b send whole buffer +" SPC l s l send current line +" SPC l s s send selection text +" < +" + +if exists('s:php_interpreter') + finish +endif + +let s:php_interpreter = 'php' @@ -31,11 +68,12 @@ let s:auto_fix = 0 function! SpaceVim#layers#lang#php#set_variable(var) abort let s:auto_fix = get(a:var, 'auto_fix', 0) + let s:php_interpreter = get(a:var, 'php_interpreter', s:php_interpreter) 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#plugins#runner#reg_runner('php', s:php_interpreter . ' %s') + call SpaceVim#plugins#repl#reg('php', [s:php_interpreter, '-a']) call SpaceVim#mapping#space#regesit_lang_mappings('php', \ function('s:on_ft')) if SpaceVim#layers#lsp#check_filetype('php') diff --git a/doc/SpaceVim.txt b/doc/SpaceVim.txt index 365ab3f2d..8550b63c1 100644 --- a/doc/SpaceVim.txt +++ b/doc/SpaceVim.txt @@ -2806,8 +2806,41 @@ This layer also provides REPL support for pact, the key bindings are: ============================================================================== LANG#PHP *SpaceVim-layer-lang-php* -This layer is for PHP development. It proides code completion, syntax -checking, and jump to definition. +This layer is for php development, disabled by default, to enable this layer, +add following snippet to your SpaceVim configuration file. +> + [[layers]] + name = 'lang#php' +< + +LAYER OPTIONS + + 1. `php_interpreter`: Set the PHP interpreter, by default, it is `php` + +> + [[layers]] + name = 'lang#php' + php_interpreter = 'path/to/php' +< + +KEY BINDINGS + +> + Mode Key Function + --------------------------------------------- + normal SPC l r run current file +< + +This layer also provides REPL support for php, the key bindings are: +> + Key Function + --------------------------------------------- + SPC l s i Start a inferior REPL process + SPC l s b send whole buffer + SPC l s l send current line + SPC l s s send selection text +< + ============================================================================== LANG#PONY *SpaceVim-layer-lang-pony* diff --git a/docs/_posts/2019-05-08-use-vim-as-a-php-ide.md b/docs/_posts/2019-05-08-use-vim-as-a-php-ide.md index 6c3ae453c..5e81dca2d 100644 --- a/docs/_posts/2019-05-08-use-vim-as-a-php-ide.md +++ b/docs/_posts/2019-05-08-use-vim-as-a-php-ide.md @@ -18,6 +18,7 @@ Each of the following sections will be covered: - [Enable language layer](#enable-language-layer) - [Code completion](#code-completion) - [Syntax linting](#syntax-linting) +- [Ctags integration](#ctags-integration) - [Jump to test file](#jump-to-test-file) - [running code](#running-code) - [Code formatting](#code-formatting) @@ -55,6 +56,21 @@ To install psalm, you may need to run: composer require --dev vimeo/psalm ``` +### Ctags integration + +The `gtags` layer provides `ctags` integration for your project. It will create the index file for +each of your project. To enable `gtags` layer: + +```toml +[[layers]] + name = 'gtags' +``` + +With this layer, you can jump to method and class definitions easily (using `ctrl + ]` by default). +Read [gtags](../layers/gtags/) layer for more info. + + + ### 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 @@ -81,8 +97,9 @@ It is running asynchronously, and will not block your Vim. ### 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: +The [format](../layers/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](http://phpbeautifier.com/): ```sh pear install PHP_Beautifier diff --git a/docs/layers/lang/php.md b/docs/layers/lang/php.md index 4aab0ba6d..11e194360 100644 --- a/docs/layers/lang/php.md +++ b/docs/layers/lang/php.md @@ -10,33 +10,41 @@ description: "PHP language support, including code completion, syntax lint and c - [Description](#description) - [Features](#features) - [Install](#install) +- [Layer options](#layer-options) - [Key bindings](#key-bindings) - [Jump to definition](#jump-to-definition) - [Running current script](#running-current-script) + - [Inferior REPL process](#inferior-repl-process) ## Description -This layer adds PHP language support to SpaceVim. +`lang#php` layer provides PHP language support in SpaceVim. ## Features -- auto-completion -- syntax checking +- code completion (`autocomplete` layer) +- code formatting (`format` layer) +- syntax checking (`checkers` layer) - goto definition -- reference finder -- lsp support (require [lsp](https://spacevim.org/layers/language-server-protocol/) layer) +- reference finder (`gtags` layer) +- language server protocol support (`lsp` layer) ## Install -To use this configuration layer, update custom configuration file with: +This layer is not enabled by default. To use this layer, you need to add following +snippet into SpaceVim configuration file: ```toml [[layers]] name = "lang#php" ``` +## Layer options + +- `php_interpreter`: Set the PHP interpreter, by default, it is `php`. + ## Key bindings ### Jump to definition @@ -49,3 +57,16 @@ To use this configuration layer, update custom configuration file with: 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. + +### Inferior REPL process + +Start a `php` inferior REPL process with `SPC l s i`. + +Send code to inferior process commands: + +| Key Bindings | Descriptions | +| ------------ | ------------------------------------------------ | +| `SPC l s b` | send buffer and keep code buffer focused | +| `SPC l s l` | send line and keep code buffer focused | +| `SPC l s s` | send selection text and keep code buffer focused | +