My nvim configuration
| 1 | ---@brief |
| 2 | --- https://github.com/tailwindlabs/tailwindcss-intellisense |
| 3 | --- |
| 4 | --- Tailwind CSS Language Server can be installed via npm: |
| 5 | --- |
| 6 | --- npm install -g @tailwindcss/language-server |
| 7 | local util = require 'lspconfig.util' |
| 8 | |
| 9 | ---@type vim.lsp.Config |
| 10 | return { |
| 11 | cmd = { 'tailwindcss-language-server', '--stdio' }, |
| 12 | -- filetypes copied and adjusted from tailwindcss-intellisense |
| 13 | filetypes = { |
| 14 | -- html |
| 15 | 'aspnetcorerazor', |
| 16 | 'astro', |
| 17 | 'astro-markdown', |
| 18 | 'blade', |
| 19 | 'clojure', |
| 20 | 'django-html', |
| 21 | 'htmldjango', |
| 22 | 'edge', |
| 23 | 'eelixir', -- vim ft |
| 24 | 'elixir', |
| 25 | 'ejs', |
| 26 | 'erb', |
| 27 | 'eruby', -- vim ft |
| 28 | 'gohtml', |
| 29 | 'gohtmltmpl', |
| 30 | 'haml', |
| 31 | 'handlebars', |
| 32 | 'hbs', |
| 33 | 'html', |
| 34 | 'htmlangular', |
| 35 | 'html-eex', |
| 36 | 'heex', |
| 37 | 'jade', |
| 38 | 'leaf', |
| 39 | 'liquid', |
| 40 | 'markdown', |
| 41 | 'mdx', |
| 42 | 'mustache', |
| 43 | 'njk', |
| 44 | 'nunjucks', |
| 45 | 'php', |
| 46 | 'razor', |
| 47 | 'slim', |
| 48 | 'twig', |
| 49 | -- css |
| 50 | 'css', |
| 51 | 'less', |
| 52 | 'postcss', |
| 53 | 'sass', |
| 54 | 'scss', |
| 55 | 'stylus', |
| 56 | 'sugarss', |
| 57 | -- js |
| 58 | 'javascript', |
| 59 | 'javascriptreact', |
| 60 | 'reason', |
| 61 | 'rescript', |
| 62 | 'typescript', |
| 63 | 'typescriptreact', |
| 64 | -- mixed |
| 65 | 'vue', |
| 66 | 'svelte', |
| 67 | 'templ', |
| 68 | }, |
| 69 | settings = { |
| 70 | tailwindCSS = { |
| 71 | validate = true, |
| 72 | lint = { |
| 73 | cssConflict = 'warning', |
| 74 | invalidApply = 'error', |
| 75 | invalidScreen = 'error', |
| 76 | invalidVariant = 'error', |
| 77 | invalidConfigPath = 'error', |
| 78 | invalidTailwindDirective = 'error', |
| 79 | recommendedVariantOrder = 'warning', |
| 80 | }, |
| 81 | classAttributes = { |
| 82 | 'class', |
| 83 | 'className', |
| 84 | 'class:list', |
| 85 | 'classList', |
| 86 | 'ngClass', |
| 87 | }, |
| 88 | includeLanguages = { |
| 89 | eelixir = 'html-eex', |
| 90 | elixir = 'phoenix-heex', |
| 91 | eruby = 'erb', |
| 92 | heex = 'phoenix-heex', |
| 93 | htmlangular = 'html', |
| 94 | templ = 'html', |
| 95 | }, |
| 96 | }, |
| 97 | }, |
| 98 | before_init = function(_, config) |
| 99 | if not config.settings then |
| 100 | config.settings = {} |
| 101 | end |
| 102 | if not config.settings.editor then |
| 103 | config.settings.editor = {} |
| 104 | end |
| 105 | if not config.settings.editor.tabSize then |
| 106 | config.settings.editor.tabSize = vim.lsp.util.get_effective_tabstop() |
| 107 | end |
| 108 | end, |
| 109 | workspace_required = true, |
| 110 | root_dir = function(bufnr, on_dir) |
| 111 | local root_files = { |
| 112 | -- Generic |
| 113 | 'tailwind.config.js', |
| 114 | 'tailwind.config.cjs', |
| 115 | 'tailwind.config.mjs', |
| 116 | 'tailwind.config.ts', |
| 117 | 'postcss.config.js', |
| 118 | 'postcss.config.cjs', |
| 119 | 'postcss.config.mjs', |
| 120 | 'postcss.config.ts', |
| 121 | -- Django |
| 122 | 'theme/static_src/tailwind.config.js', |
| 123 | 'theme/static_src/tailwind.config.cjs', |
| 124 | 'theme/static_src/tailwind.config.mjs', |
| 125 | 'theme/static_src/tailwind.config.ts', |
| 126 | 'theme/static_src/postcss.config.js', |
| 127 | -- Fallback for tailwind v4, where tailwind.config.* is not required anymore |
| 128 | '.git', |
| 129 | } |
| 130 | local fname = vim.api.nvim_buf_get_name(bufnr) |
| 131 | root_files = util.insert_package_json(root_files, 'tailwindcss', fname) |
| 132 | root_files = util.root_markers_with_field(root_files, { 'mix.lock', 'Gemfile.lock' }, 'tailwind', fname) |
| 133 | on_dir(vim.fs.dirname(vim.fs.find(root_files, { path = fname, upward = true })[1])) |
| 134 | end, |
| 135 | } |