Skip to content

Commit db78580

Browse files
committed
Refactor CSS class scanning and hover tests
- Removed the CSS class scanning logic from the project service to streamline functionality. - Deleted outdated hover tests for custom classes to improve test clarity and maintainability. - Enhanced error handling and logging during project directory scanning for CSS files.
1 parent 7cd34a0 commit db78580

File tree

2 files changed

+0
-127
lines changed

2 files changed

+0
-127
lines changed

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

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ 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'
2827
import findUp from 'find-up'
2928
import picomatch from 'picomatch'
3029
import { resolveFrom, setPnpApi } from './util/resolveFrom'
@@ -57,7 +56,6 @@ import { doCodeActions } from '@tailwindcss/language-service/src/codeActions/cod
5756
import { getDocumentColors } from '@tailwindcss/language-service/src/documentColorProvider'
5857
import { getDocumentLinks } from '@tailwindcss/language-service/src/documentLinksProvider'
5958
import { debounce } from 'debounce'
60-
import { scanCssFilesForCustomClasses } from '@tailwindcss/language-service/src/util/css-class-scanner'
6159
import { getModuleDependencies } from './util/getModuleDependencies'
6260
import assert from 'node:assert'
6361
// import postcssLoadConfig from 'postcss-load-config'
@@ -1071,40 +1069,6 @@ export async function createProjectService(
10711069
}
10721070
state.variants = getVariants(state)
10731071

1074-
// Scan CSS files for custom classes (v3 projects)
1075-
const cssFiles = Array.from(state.dependencies ?? []).filter((dep) => dep.endsWith('.css'))
1076-
1077-
// Also scan the main CSS file if it's a CSS config
1078-
if (state.isCssConfig && state.configPath) {
1079-
cssFiles.push(state.configPath)
1080-
}
1081-
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-
1100-
if (cssFiles.length > 0) {
1101-
try {
1102-
await scanCssFilesForCustomClasses(state, cssFiles)
1103-
} catch (error) {
1104-
console.error('Error scanning CSS files for custom classes:', error)
1105-
}
1106-
}
1107-
11081072
let screens = dlv(state.config, 'theme.screens', dlv(state.config, 'screens', {}))
11091073
state.screens = isObject(screens) ? Object.keys(screens) : []
11101074

@@ -1186,20 +1150,7 @@ export async function createProjectService(
11861150
state.variants = getVariants(state)
11871151
state.blocklist = Array.from(designSystem.invalidCandidates ?? [])
11881152

1189-
// Scan CSS files for custom classes
11901153
let deps = designSystem.dependencies()
1191-
const cssFiles = Array.from(deps).filter((dep) => dep.endsWith('.css'))
1192-
1193-
// Also scan the main CSS file
1194-
cssFiles.push(state.configPath)
1195-
1196-
if (cssFiles.length > 0) {
1197-
try {
1198-
await scanCssFilesForCustomClasses(state, cssFiles)
1199-
} catch (error) {
1200-
console.error('Error scanning CSS files for custom classes:', error)
1201-
}
1202-
}
12031154

12041155
for (let dep of deps) {
12051156
dependencies.add(dep)

packages/tailwindcss-language-server/tests/hover/hover.test.js

Lines changed: 0 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -554,84 +554,6 @@ withFixture('v4/path-mappings', (c) => {
554554
})
555555
})
556556

557-
withFixture('custom-classes', (c) => {
558-
async function testHover(
559-
name,
560-
{ text, lang, position, exact = false, expected, expectedRange, settings },
561-
) {
562-
test(name, async ({ expect }) => {
563-
let textDocument = await c.openDocument({ text, lang, settings })
564-
let res = await c.sendRequest('textDocument/hover', {
565-
textDocument,
566-
position,
567-
})
568-
569-
if (!exact && expected) {
570-
expected = {
571-
contents: {
572-
language: 'css',
573-
value: expected,
574-
},
575-
range: expectedRange,
576-
}
577-
}
578-
579-
expect(res).toEqual(expected)
580-
})
581-
}
582-
583-
testHover('custom button class', {
584-
text: '<div class="custom-button">',
585-
position: { line: 0, character: 13 },
586-
expected:
587-
'.custom-button {\n' +
588-
' background-color: #1a9dd9;\n' +
589-
' color: white;\n' +
590-
' padding: 0.5rem 1rem;\n' +
591-
' border-radius: 0.25rem;\n' +
592-
' font-weight: 600;\n' +
593-
'}',
594-
expectedRange: {
595-
start: { line: 0, character: 12 },
596-
end: { line: 0, character: 25 },
597-
},
598-
})
599-
600-
testHover('typography h3 class', {
601-
text: '<div class="typography-h3">',
602-
position: { line: 0, character: 13 },
603-
expected:
604-
'.typography-h3 {\n' +
605-
' font-family: Montserrat;\n' +
606-
' font-size: 48px;\n' +
607-
' font-style: normal;\n' +
608-
' font-weight: 700;\n' +
609-
' line-height: 116.7%;\n' +
610-
'}',
611-
expectedRange: {
612-
start: { line: 0, character: 12 },
613-
end: { line: 0, character: 25 },
614-
},
615-
})
616-
617-
testHover('card class', {
618-
text: '<div class="card">',
619-
position: { line: 0, character: 13 },
620-
expected:
621-
'.card {\n' +
622-
' background-color: white;\n' +
623-
' border: 1px solid #e5e7eb;\n' +
624-
' border-radius: 0.5rem;\n' +
625-
' padding: 1.5rem;\n' +
626-
' box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);\n' +
627-
'}',
628-
expectedRange: {
629-
start: { line: 0, character: 12 },
630-
end: { line: 0, character: 16 },
631-
},
632-
})
633-
})
634-
635557
defineTest({
636558
name: 'Can hover showing theme values used in var(…) and theme(…) functions',
637559
fs: {

0 commit comments

Comments
 (0)