-- ~/.config/nvim/lua/plugins/drupal.lua -- LazyVim plugin configuration for Drupal 10 frontend / theming development -- Covers: PHP, Twig, SCSS/CSS, JS/TS, HTML, YAML, JSON return { -- ----------------------------------------------------------------------- -- 1. TREESITTER — syntax highlighting for all Drupal-relevant file types -- ----------------------------------------------------------------------- { "nvim-treesitter/nvim-treesitter", opts = function(_, opts) vim.list_extend(opts.ensure_installed, { "php", "twig", "html", "css", "scss", "javascript", "typescript", "json", "yaml", "bash", "lua", }) end, }, -- ----------------------------------------------------------------------- -- 2. LSP — language servers for PHP, CSS, HTML, JS, Emmet, YAML -- ----------------------------------------------------------------------- { "neovim/nvim-lspconfig", opts = { servers = { -- PHP: best LSP for Drupal (hooks, classes, autocompletion) -- Install via Mason: :MasonInstall intelephense intelephense = { settings = { intelephense = { stubs = { -- Include common Drupal-related PHP extensions "apache", "bcmath", "bz2", "calendar", "com_dotnet", "Core", "ctype", "curl", "date", "dba", "dom", "enchant", "exif", "fileinfo", "filter", "fpm", "ftp", "gd", "hash", "iconv", "imap", "intl", "json", "ldap", "libxml", "mbstring", "mcrypt", "meta", "mhash", "mysql", "mysqli", "oci8", "odbc", "openssl", "pcntl", "pcre", "PDO", "pdo_ibm", "pdo_mysql", "pdo_pgsql", "pdo_sqlite", "pgsql", "Phar", "posix", "pspell", "readline", "recode", "Reflection", "regex", "session", "shmop", "SimpleXML", "snmp", "soap", "sockets", "sodium", "SPL", "sqlite3", "standard", "superglobals", "sysvmsg", "sysvsem", "sysvshm", "tidy", "tokenizer", "wddx", "xml", "xmlreader", "xmlrpc", "xmlwriter", "Zend OPcache", "zip", "zlib", }, environment = { phpVersion = "8.2", -- adjust to your Drupal 10 PHP version }, files = { maxSize = 5000000, }, }, }, -- Uncomment and add your licence key if you have Intelephense Premium -- init_options = { -- licenceKey = "YOUR_LICENCE_KEY_HERE", -- }, }, -- CSS & SCSS -- Install via Mason: :MasonInstall css-lsp cssls = {}, -- HTML (also helps in Twig files) -- Install via Mason: :MasonInstall html-lsp html = { filetypes = { "html", "twig", "htmldjango" }, }, -- Emmet: expand abbreviations in HTML/Twig/SCSS -- Install via Mason: :MasonInstall emmet-ls emmet_ls = { filetypes = { "html", "twig", "css", "scss", "javascript", "typescript", "php", }, init_options = { html = { options = { ["bem.enabled"] = true, }, }, }, }, -- JavaScript / TypeScript -- Install via Mason: :MasonInstall typescript-language-server ts_ls = {}, -- YAML: Drupal config files (.yml) -- Install via Mason: :MasonInstall yaml-language-server yamlls = { settings = { yaml = { schemas = { -- Point at Drupal schema if you have it locally, or leave empty }, format = { enable = true }, validate = true, }, }, }, -- JSON -- Install via Mason: :MasonInstall json-lsp jsonls = {}, }, }, }, -- ----------------------------------------------------------------------- -- 3. MASON — ensure all servers & tools are auto-installed -- ----------------------------------------------------------------------- { "mason-org/mason.nvim", opts = function(_, opts) vim.list_extend(opts.ensure_installed, { "intelephense", -- PHP "css-lsp", -- CSS/SCSS "html-lsp", -- HTML "emmet-ls", -- Emmet "typescript-language-server", -- JS/TS "yaml-language-server", -- YAML "json-lsp", -- JSON "prettier", -- Formatter: JS, CSS, SCSS, JSON, YAML, HTML "stylelint", -- Linter: CSS/SCSS "eslint-lsp", -- Linter: JS/TS "php-cs-fixer", -- Formatter: PHP (optional) }) end, }, -- ----------------------------------------------------------------------- -- 4. FORMATTING — Prettier for web files, php-cs-fixer for PHP -- ----------------------------------------------------------------------- { "stevearc/conform.nvim", opts = { formatters_by_ft = { javascript = { "prettier" }, typescript = { "prettier" }, css = { "prettier" }, scss = { "prettier" }, html = { "prettier" }, json = { "prettier" }, yaml = { "prettier" }, twig = { "prettier" }, -- requires prettier-plugin-twig php = { "php_cs_fixer" }, }, }, }, -- ----------------------------------------------------------------------- -- 5. LINTING — ESLint for JS/TS, Stylelint for CSS/SCSS -- ----------------------------------------------------------------------- { "mfussenegger/nvim-lint", opts = { linters_by_ft = { javascript = { "eslint" }, typescript = { "eslint" }, css = { "stylelint" }, scss = { "stylelint" }, }, }, }, -- ----------------------------------------------------------------------- -- 6. FILETYPE DETECTION — teach Neovim about Twig & Drupal file types -- ----------------------------------------------------------------------- { "nvim-treesitter/nvim-treesitter", init = function() vim.filetype.add({ extension = { twig = "twig", theme = "php", -- Drupal .theme files are PHP inc = "php", -- .inc files are PHP module = "php", -- .module files are PHP install = "php", -- .install files are PHP }, filename = { [".eslintrc"] = "json", [".stylelintrc"] = "json", }, }) end, }, -- ----------------------------------------------------------------------- -- 7. TELESCOPE — fuzzy finding tuned for Drupal project structure -- ----------------------------------------------------------------------- { "nvim-telescope/telescope.nvim", opts = { defaults = { -- Ignore common Drupal/Node dirs from search results file_ignore_patterns = { "node_modules/", "vendor/", ".git/", "web/core/", -- ignore Drupal core, focus on custom "web/modules/contrib/", -- ignore contrib modules "web/themes/contrib/", -- ignore contrib themes "%.lock", }, }, }, }, -- ----------------------------------------------------------------------- -- 8. OPTIONAL: Colorscheme well-suited to web development -- (remove/swap if you already have a preference) -- ----------------------------------------------------------------------- -- { -- "LazyVim/LazyVim", -- opts = { -- colorscheme = "tokyonight-night", -- }, -- }, }