drupal.nvim - a little less pain for Drupal developers daring to use neovim.
- plenary.nvim (used for running drush)
- nvim-cmp (currently autocompletion requires nvim-cmp)
- cmp_luasnip (required for adding hook snippets)
- ripgrep (needs to be installed on your machine)
- drush (needs to be installed on your machine/project)
Install this plugin using your favorite plugin manager, and then call
require("drupal").setup()
.
Default configuration can be found in lua/drupal/default_config.lua
.
{
"jdrupal-dev/drupal.nvim",
dependencies = { "nvim-lua/plenary.nvim" },
config = function()
require("drupal").setup({
services_cmp_trigger_character = "@",
get_drush_executable = function(current_dir)
-- You can use current_dir if you have different ways of
-- executing drush across your Drupal projects.
return "drush"
end,
})
end
}
You need the devel
module installed for this feature to work.
The drush devel:services
command is used to get a list of all available Drupal services.
To trigger the autocompletion of services you need to input the trigger character, which by default is "@".
\Drupal::service('@entity_') // Now you should see services beginning with entity_.
A few practical snippets are provided, you can find the complete list of snippets in lua/drupal/snippets/docs.md
.
LuaSnip snippets are automatically generated for hooks when opening nvim in a Drupal project.
You can use the snippets by typing hook_
in a .module
or .theme
file.
When the snippet is used hook
will automatically get replaced with the name of the current module.
For example, typing hook_theme + Enter
in my_module.module
will generate the following code:
<?php
/**
* Implements hook_theme()
*/
function my_module_theme($existing, $type, $theme, $path) {
}