tailwind-ctp-intellisense @master -
refs -
log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Revert "Improve conflict diagnostics (#503)" (#525)
This reverts commit ddfaea21cc5feca1bbf71ddb36645a61f01daea3.
Signature
-----BEGIN PGP SIGNATURE-----
wsBcBAABCAAQBQJiVz9yCRBK7hj4Ov3rIwAAzyUIAEc9tyWjJXbN83zqwpRhj8Sx
LlZ2gTGPqIL+sQdWAOhT/1HagW0q1FoAoIshkJX8jE5aFVJcBjMFWIBwHPozk/JV
nGYUB8d5/dls+DsAfMY6TP3YZxWKpVqOTmY0Jn5PBSl+Q6UgEocRcO1bU5eBCdly
TQAlPOgR7sAClU5UnhibH9eZ6w0c8Sixd7mnnk80hwBLsJkBOPVTvKbZtPcakfuo
hsNpbBD0rFC/od9ozf3+lGLfpi4PdAF0MHMEuQc8W/8BWTzTXE6wkNMany3lonfb
XNvddJgHU1CzI9p7GhX+p/3gQmu+Udx2maKYx3D16EnVKoStS7A+KOOkWP5NBa0=
=ALB6
-----END PGP SIGNATURE-----
diff --git a/packages/tailwindcss-language-service/src/util/find.ts b/packages/tailwindcss-language-service/src/util/find.ts
index d0ad26681d864cb45c0d893a556e2bd88cc44497..d9a23c461e9c490c4d9708b6768822329c04c25d 100644
--- a/packages/tailwindcss-language-service/src/util/find.ts
+++ b/packages/tailwindcss-language-service/src/util/find.ts
@@ -77,15 +77,7 @@ mode?: 'html' | 'css',
includeCustom: boolean = true
): Promise<DocumentClassName[]> {
const classLists = await findClassListsInRange(state, doc, range, mode, includeCustom)
- return flatten(
- classLists.flatMap((classList) => {
- if (Array.isArray(classList)) {
- return classList.map(getClassNamesInClassList)
- } else {
- return [getClassNamesInClassList(classList)]
- }
- })
- )
+ return flatten(classLists.map(getClassNamesInClassList))
}
export async function findClassNamesInDocument(
@@ -93,15 +85,7 @@ state: State,
doc: TextDocument
): Promise<DocumentClassName[]> {
const classLists = await findClassListsInDocument(state, doc)
- return flatten(
- classLists.flatMap((classList) => {
- if (Array.isArray(classList)) {
- return classList.map(getClassNamesInClassList)
- } else {
- return [getClassNamesInClassList(classList)]
- }
- })
- )
+ return flatten(classLists.map(getClassNamesInClassList))
}
export function findClassListsInCssRange(doc: TextDocument, range?: Range): DocumentClassList[] {
@@ -198,7 +182,7 @@ export async function findClassListsInHtmlRange(
state: State,
doc: TextDocument,
range?: Range
-): Promise<Array<DocumentClassList | DocumentClassList[]>> {
+): Promise<DocumentClassList[]> {
const text = doc.getText(range)
const matches = matchClassAttributes(
@@ -206,7 +190,7 @@ text,
(await state.editor.getConfiguration(doc.uri)).tailwindCSS.classAttributes
)
- const result: Array<DocumentClassList | DocumentClassList[]> = []
+ const result: DocumentClassList[] = []
matches.forEach((match) => {
const subtext = text.substr(match.index + match[0].length - 1)
@@ -217,11 +201,9 @@ ? getComputedClassAttributeLexer()
: getClassAttributeLexer()
lexer.reset(subtext)
- let classLists: Array<{ value: string; offset: number } | { value: string; offset: number }[]> =
- []
- let rootClassList: { value: string; offset: number }[] = []
+ let classLists: { value: string; offset: number }[] = []
+ let token: moo.Token
let currentClassList: { value: string; offset: number }
- let depth = 0
try {
for (let token of lexer) {
@@ -236,53 +218,56 @@ }
}
} else {
if (currentClassList) {
- if (depth === 0) {
- rootClassList.push({
- value: currentClassList.value,
- offset: currentClassList.offset,
- })
- } else {
- classLists.push({
- value: currentClassList.value,
- offset: currentClassList.offset,
- })
- }
+ classLists.push({
+ value: currentClassList.value,
+ offset: currentClassList.offset,
+ })
}
currentClassList = undefined
}
- if (token.type === 'lbrace') {
- depth += 1
- } else if (token.type === 'rbrace') {
- depth -= 1
- }
}
} catch (_) {}
if (currentClassList) {
- if (depth === 0) {
- rootClassList.push({
- value: currentClassList.value,
- offset: currentClassList.offset,
- })
- } else {
- classLists.push({
- value: currentClassList.value,
- offset: currentClassList.offset,
- })
- }
+ classLists.push({
+ value: currentClassList.value,
+ offset: currentClassList.offset,
+ })
}
- classLists.push(rootClassList)
-
result.push(
...classLists
- .map((classList) => {
- if (Array.isArray(classList)) {
- return classList
- .map((classList) => resolveClassList(classList, text, match, range))
- .filter((x) => x !== null)
- } else {
- return resolveClassList(classList, text, match, range)
+ .map(({ value, offset }) => {
+ if (value.trim() === '') {
+ return null
+ }
+
+ const before = value.match(/^\s*/)
+ const beforeOffset = before === null ? 0 : before[0].length
+ const after = value.match(/\s*$/)
+ const afterOffset = after === null ? 0 : -after[0].length
+
+ const start = indexToPosition(
+ text,
+ match.index + match[0].length - 1 + offset + beforeOffset
+ )
+ const end = indexToPosition(
+ text,
+ match.index + match[0].length - 1 + offset + value.length + afterOffset
+ )
+
+ return {
+ classList: value.substr(beforeOffset, value.length + afterOffset),
+ range: {
+ start: {
+ line: (range?.start.line || 0) + start.line,
+ character: (end.line === 0 ? range?.start.character || 0 : 0) + start.character,
+ },
+ end: {
+ line: (range?.start.line || 0) + end.line,
+ character: (end.line === 0 ? range?.start.character || 0 : 0) + end.character,
+ },
+ },
}
})
.filter((x) => x !== null)
@@ -292,51 +277,14 @@
return result
}
-function resolveClassList(
- classList: { value: string; offset: number },
- text: string,
- match: RegExpMatchArray,
- range?: Range
-): DocumentClassList {
- let { value, offset } = classList
- if (value.trim() === '') {
- return null
- }
-
- const before = value.match(/^\s*/)
- const beforeOffset = before === null ? 0 : before[0].length
- const after = value.match(/\s*$/)
- const afterOffset = after === null ? 0 : -after[0].length
-
- const start = indexToPosition(text, match.index + match[0].length - 1 + offset + beforeOffset)
- const end = indexToPosition(
- text,
- match.index + match[0].length - 1 + offset + value.length + afterOffset
- )
-
- return {
- classList: value.substr(beforeOffset, value.length + afterOffset),
- range: {
- start: {
- line: (range?.start.line || 0) + start.line,
- character: (end.line === 0 ? range?.start.character || 0 : 0) + start.character,
- },
- end: {
- line: (range?.start.line || 0) + end.line,
- character: (end.line === 0 ? range?.start.character || 0 : 0) + end.character,
- },
- },
- }
-}
-
export async function findClassListsInRange(
state: State,
doc: TextDocument,
range?: Range,
mode?: 'html' | 'css',
includeCustom: boolean = true
-): Promise<Array<DocumentClassList | DocumentClassList[]>> {
- let classLists: Array<DocumentClassList | DocumentClassList[]>
+): Promise<DocumentClassList[]> {
+ let classLists: DocumentClassList[]
if (mode === 'css') {
classLists = findClassListsInCssRange(doc, range)
} else {
@@ -348,7 +296,7 @@
export async function findClassListsInDocument(
state: State,
doc: TextDocument
-): Promise<Array<DocumentClassList | DocumentClassList[]>> {
+): Promise<DocumentClassList[]> {
if (isCssDoc(state, doc)) {
return findClassListsInCssRange(doc)
}