|
6 | 6 | --- npm install -g @tailwindcss/language-server |
7 | 7 | local util = require 'lspconfig.util' |
8 | 8 |
|
| 9 | +local function find_tailwind_global_css() |
| 10 | + local target = "@import 'tailwindcss';" |
| 11 | + |
| 12 | + -- Find project root using `.git` |
| 13 | + local buf = vim.api.nvim_get_current_buf() |
| 14 | + local root = vim.fs.root(buf, function(name) |
| 15 | + return name == '.git' |
| 16 | + end) |
| 17 | + |
| 18 | + if not root then |
| 19 | + return nil -- no project root found |
| 20 | + end |
| 21 | + |
| 22 | + -- Find stylesheet files in the project root (recursively) |
| 23 | + local files = vim.fs.find(function(name) |
| 24 | + return name:match('%.css$') or name:match('%.scss$') or name:match('%.pcss$') |
| 25 | + end, { |
| 26 | + path = root, |
| 27 | + type = 'file', |
| 28 | + limit = math.huge, -- search full tree |
| 29 | + }) |
| 30 | + |
| 31 | + for _, path in ipairs(files) do |
| 32 | + local content = vim.fn.readblob(path) |
| 33 | + |
| 34 | + if content:find(target, 1, true) then |
| 35 | + return path -- return first match |
| 36 | + end |
| 37 | + end |
| 38 | + |
| 39 | + return nil |
| 40 | +end |
| 41 | + |
9 | 42 | ---@type vim.lsp.Config |
10 | 43 | return { |
11 | 44 | cmd = { 'tailwindcss-language-server', '--stdio' }, |
@@ -113,6 +146,10 @@ return { |
113 | 146 | if not config.settings.editor.tabSize then |
114 | 147 | config.settings.editor.tabSize = vim.lsp.util.get_effective_tabstop() |
115 | 148 | end |
| 149 | + config.settings.tailwindCSS = config.settings.tailwindCSS or {} |
| 150 | + config.settings.tailwindCSS.experimental = config.settings.tailwindCSS.experimental or {} |
| 151 | + config.settings.tailwindCSS.experimental.configFile = config.settings.tailwindCSS.experimental.configFile |
| 152 | + or find_tailwind_global_css() |
116 | 153 | end, |
117 | 154 | workspace_required = true, |
118 | 155 | root_dir = function(bufnr, on_dir) |
|
0 commit comments