coc-blade
Laravel Blade Templates extension for coc.nvim. Provides "formatter", "linter", "completion" and more...
Features
- Format
- by blade-formatter (An opinionated blade template formatter for Laravel that respects readability)
- Lint
- by laravel-blade-linter (A simple Blade template syntax checker for Laravel)
- Completion
- Completion of snippets data via
completionItemProvider
- Completion of snippets data via
- Definition
- Jump to template file specified by
@extends
,@include
directive, etc. - Jump to "Blade Components" file.
- [Warning] Class-based Blade Components are not supported.
- Jump to template file specified by
- Code Action
- Add a blade comment to disable the formatting.
- Hover
Install
CocInstall:
:CocInstall coc-blade
vim-plug:
Plug 'yaegassy/coc-blade', {'do': 'yarn install --frozen-lockfile'}
Recommended coc extension:
Note
Filetype related
The "filetype" must be blade
for this extension to work.
Set up autocmd BufNewFile,BufRead *.blade.php set filetype=blade
in .vimrc/init.vim
, Or install "blade" related plugin (e.g. jwalton512/vim-blade or sheerun/vim-polyglot).
Usage Topics
formatter (blade-formatter)
Run:
:call CocAction('format')
:CocCommand bladeFormatter.run
If there is a "syntax error" in the blade template, the formatting will fail.
Configuration file: .bladeformatterrc.json or .bladeformatterrc:
To configure settings per project, put .bladeformatterrc.json
or .bladeformatterrc
to your project root will blade-formatter treat it as setting files.
Configuration file will like below:
{
"indentSize": 4,
"wrapAttributues": "auto",
"wrapLineLength": 120,
"endWithNewLine": true,
"useTabs": false
}
Ignoring Files: .bladeignore:
To ignore specific file, put .bladeignore
to your repository root will blade-formatter
treat it as ignored files.
resources/views/users/index.blade.php
resources/views/products/*
resources/views/books/**/*
Disabling format in file:
In coc-blade, there is a code action feature to add a blade comment to disable the formatting.
Auto-run on save is not recommended:
blade-formatter
is slow, we do not recommend that you set it to auto-execute on save. If you set up blade-formatter
to auto-execute on save, the process may not be completed normally.
linter (laravel-blade-linter)
You will need to have laravel-blade-linter installed in your "Laravel project".
If "laravel-blade-linter" is not detected, the lint (diagnostics) feature is automatically disabled.
composer require --dev bdelespierre/laravel-blade-linter
completion (laravel-blade-snippets-vscode)
It uses snippet files from onecentlin/laravel-blade-snippets-vscode to provide completion.
You can auto-complete by typing b:
, lv:
, Blade::
, livewire::
.
If you want to disable this completion feature, set blade.completion.enable
to false
in coc-settings.json
.
{
"blade.completion.enable": false
}
Configuration options
blade.enable
: Enable coc-blade extension, default:true
blade.completion.enable
: Enable snippets completion, default:true
blade.completion.exclude
: Exclude specific prefix in snippet completion, e.g.["b:extends", "lv:url", "Blade::component"]
, default:[]
blade.bladeFormatter.enable
: Enable/Disable the formatting feature byblade-formatter
, default:true
blade.bladeFormatter.toolPath
: Absolute path to blade-formatter. If there is no setting, the built-in blade-formatter will be used, default:""
blade.bladeFormatter.optIndentSize
: Indent size (--indent-size
), valid typeinteger
ornull
, default:null
,blade.bladeFormatter.optWrapLineLength
: The length of line wrap size (--wrap-line-length
), valid typeinteger
ornull
, default:null
blade.bladeFormatter.optWrapAttributes
: The way to wrap attributes (--wrap-attributes
), valid options["auto", "force", "force-aligned", "force-expand-multiline", "aligned-multiple", "preserve", "preserve-aligned"]
, valid typestring
ornull
, default:null
blade.bladeLinter.enable
: Enable/Disable the linting feature bylaravel-blade-linter
, default:true
Commands
blade.bladeFormatter.run
: Run blade-formatter
Code Actions
Example key mapping (Code Action related):
nmap <silent> ga <Plug>(coc-codeaction-line)
nmap <silent> gA <Plug>(coc-codeaction)
Actions:
Add "blade-formatter-disable-next-line" for this line
Add "blade-formatter-disable" for this line
Add "blade-formatter-enable" for this line
Add "blade-formatter-disable" for whole file
Thanks
- shufo/blade-formatter
- shufo/vscode-blade-formatter
- bdelespierre/laravel-blade-linter
- onecentlin/laravel-blade-snippets-vscode
License
MIT
This extension is built with create-coc-extension