Skip to content

Commit 02f9d00

Browse files
committed
wip
1 parent f49c7e8 commit 02f9d00

File tree

4 files changed

+56
-35
lines changed

4 files changed

+56
-35
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ function createVirtualCssDocument(textDocument: TextDocument): TextDocument {
357357
/@media(\s+screen\s*\([^)]+\))/g,
358358
(_match, screen) => `@media (${MEDIA_MARKER})${' '.repeat(screen.length - 4)}`
359359
)
360+
.replace(/(?<=\b(?:theme|config)\([^)]*)[.[\]]/g, '_')
360361
)
361362
}
362363

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ const TRIGGER_CHARACTERS = [
112112
// @apply and emmet-style
113113
'.',
114114
// config/theme helper
115+
'(',
115116
'[',
116117
// JIT "important" prefix
117118
'!',

packages/tailwindcss-language-service/src/completionProvider.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -537,14 +537,26 @@ function provideCssHelperCompletions(
537537

538538
const match = text
539539
.substr(0, text.length - 1) // don't include that extra character from earlier
540-
.match(/\b(?<helper>config|theme)\(['"](?<keys>[^'"]*)$/)
540+
.match(/\b(?<helper>config|theme)\(\s*['"]?(?<path>[^)'"]*)$/)
541541

542542
if (match === null) {
543543
return null
544544
}
545545

546+
let alpha: string
547+
let path = match.groups.path.replace(/^['"]+/g, '')
548+
let matches = path.match(/^([^\s]+)(?![^\[]*\])(?:\s*\/\s*([^\/\s]*))$/)
549+
if (matches) {
550+
path = matches[1]
551+
alpha = matches[2]
552+
}
553+
554+
if (alpha !== undefined) {
555+
return null
556+
}
557+
546558
let base = match.groups.helper === 'config' ? state.config : dlv(state.config, 'theme', {})
547-
let parts = match.groups.keys.split(/([\[\].]+)/)
559+
let parts = path.split(/([\[\].]+)/)
548560
let keys = parts.filter((_, i) => i % 2 === 0)
549561
let separators = parts.filter((_, i) => i % 2 !== 0)
550562
// let obj =

packages/tailwindcss-language-service/src/diagnostics/getInvalidConfigPathDiagnostics.ts

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -179,42 +179,49 @@ export function getInvalidConfigPathDiagnostics(
179179

180180
ranges.forEach((range) => {
181181
let text = getTextWithoutComments(document, 'css', range)
182-
let matches = findAll(
183-
/(?<prefix>\s|^)(?<helper>config|theme)\((?<quote>['"])(?<key>[^)]+)\k<quote>[^)]*\)/g,
184-
text
185-
)
182+
let matches = findAll(/(?<prefix>\s|^)(?<helper>config|theme)\((?<path>[^)]*)\)/g, text)
186183

187184
matches.forEach((match) => {
188-
let base = match.groups.helper === 'theme' ? ['theme'] : []
189-
let result = validateConfigPath(state, match.groups.key, base)
190-
191-
if (result.isValid === true) {
192-
return null
185+
let path = match.groups.path.replace(/^['"]+|['"]+$/g, '')
186+
let alpha: string
187+
let matches = path.match(/^([^\s]+)(?![^\[]*\])(?:\s*\/\s*([^\/\s]+))$/)
188+
if (matches) {
189+
path = matches[1]
190+
alpha = matches[2]
193191
}
194-
195-
let startIndex =
196-
match.index +
197-
match.groups.prefix.length +
198-
match.groups.helper.length +
199-
1 + // open paren
200-
match.groups.quote.length
201-
202-
diagnostics.push({
203-
code: DiagnosticKind.InvalidConfigPath,
204-
range: absoluteRange(
205-
{
206-
start: indexToPosition(text, startIndex),
207-
end: indexToPosition(text, startIndex + match.groups.key.length),
208-
},
209-
range
210-
),
211-
severity:
212-
severity === 'error'
213-
? 1 /* DiagnosticSeverity.Error */
214-
: 2 /* DiagnosticSeverity.Warning */,
215-
message: result.reason,
216-
suggestions: result.suggestions,
217-
})
192+
console.log({ path, alpha })
193+
return
194+
195+
// let base = match.groups.helper === 'theme' ? ['theme'] : []
196+
// let result = validateConfigPath(state, match.groups.path, base)
197+
198+
// if (result.isValid === true) {
199+
// return null
200+
// }
201+
202+
// let startIndex =
203+
// match.index +
204+
// match.groups.prefix.length +
205+
// match.groups.helper.length +
206+
// 1 + // open paren
207+
// match.groups.innerPrefix.length
208+
209+
// diagnostics.push({
210+
// code: DiagnosticKind.InvalidConfigPath,
211+
// range: absoluteRange(
212+
// {
213+
// start: indexToPosition(text, startIndex),
214+
// end: indexToPosition(text, startIndex + match.groups.path.length),
215+
// },
216+
// range
217+
// ),
218+
// severity:
219+
// severity === 'error'
220+
// ? 1 /* DiagnosticSeverity.Error */
221+
// : 2 /* DiagnosticSeverity.Warning */,
222+
// message: result.reason,
223+
// suggestions: result.suggestions,
224+
// })
218225
})
219226
})
220227

0 commit comments

Comments
 (0)