Skip to content

Commit 7cd34a0

Browse files
committed
Add support for custom CSS class hover information
- Enhanced the hover provider to return CSS rules for custom classes when hovered over. - Implemented functionality to scan project directories for CSS files and include them in class completion. - Added tests for hover functionality on custom classes to ensure accurate display of CSS rules. - Improved error handling during project directory scanning for CSS files.
1 parent 89dee31 commit 7cd34a0

File tree

7 files changed

+1529
-0
lines changed

7 files changed

+1529
-0
lines changed

packages/tailwindcss-language-server/src/projects.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { URI } from 'vscode-uri'
2424
import { showError, showWarning, SilentError } from './util/error'
2525
import * as path from 'node:path'
2626
import * as fs from 'node:fs'
27+
import * as fsPromises from 'node:fs/promises'
2728
import findUp from 'find-up'
2829
import picomatch from 'picomatch'
2930
import { resolveFrom, setPnpApi } from './util/resolveFrom'
@@ -1078,6 +1079,24 @@ export async function createProjectService(
10781079
cssFiles.push(state.configPath)
10791080
}
10801081

1082+
// Also scan CSS files in the project directory for custom classes
1083+
try {
1084+
const projectDir = path.dirname(state.configPath)
1085+
const projectFiles = await fsPromises.readdir(projectDir)
1086+
const projectCssFiles = projectFiles
1087+
.filter((file) => file.endsWith('.css'))
1088+
.map((file) => path.join(projectDir, file))
1089+
1090+
// Add project CSS files that aren't already in dependencies
1091+
for (const cssFile of projectCssFiles) {
1092+
if (!cssFiles.includes(cssFile)) {
1093+
cssFiles.push(cssFile)
1094+
}
1095+
}
1096+
} catch (error) {
1097+
console.error('Error scanning project directory for CSS files:', error)
1098+
}
1099+
10811100
if (cssFiles.length > 0) {
10821101
try {
10831102
await scanCssFilesForCustomClasses(state, cssFiles)

0 commit comments

Comments
 (0)