Deduplicate classlist candidates (#572)
parent
05a8685c49
commit
d09a4b11f1
|
@ -11,6 +11,7 @@ import { getLanguageBoundaries } from './getLanguageBoundaries'
|
||||||
import { resolveRange } from './resolveRange'
|
import { resolveRange } from './resolveRange'
|
||||||
import dlv from 'dlv'
|
import dlv from 'dlv'
|
||||||
import { createMultiRegexp } from './createMultiRegexp'
|
import { createMultiRegexp } from './createMultiRegexp'
|
||||||
|
import { rangesEqual } from './rangesEqual'
|
||||||
|
|
||||||
export function findAll(re: RegExp, str: string): RegExpMatchArray[] {
|
export function findAll(re: RegExp, str: string): RegExpMatchArray[] {
|
||||||
let match: RegExpMatchArray
|
let match: RegExpMatchArray
|
||||||
|
@ -277,6 +278,13 @@ export async function findClassListsInHtmlRange(
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dedupeClassLists(classLists: DocumentClassList[]): DocumentClassList[] {
|
||||||
|
return classLists.filter(
|
||||||
|
(classList, classListIndex) =>
|
||||||
|
classListIndex === classLists.findIndex((c) => rangesEqual(c.range, classList.range))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export async function findClassListsInRange(
|
export async function findClassListsInRange(
|
||||||
state: State,
|
state: State,
|
||||||
doc: TextDocument,
|
doc: TextDocument,
|
||||||
|
@ -290,7 +298,10 @@ export async function findClassListsInRange(
|
||||||
} else {
|
} else {
|
||||||
classLists = await findClassListsInHtmlRange(state, doc, range)
|
classLists = await findClassListsInHtmlRange(state, doc, range)
|
||||||
}
|
}
|
||||||
return [...classLists, ...(includeCustom ? await findCustomClassLists(state, doc, range) : [])]
|
return dedupeClassLists([
|
||||||
|
...classLists,
|
||||||
|
...(includeCustom ? await findCustomClassLists(state, doc, range) : []),
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function findClassListsInDocument(
|
export async function findClassListsInDocument(
|
||||||
|
@ -304,7 +315,8 @@ export async function findClassListsInDocument(
|
||||||
let boundaries = getLanguageBoundaries(state, doc)
|
let boundaries = getLanguageBoundaries(state, doc)
|
||||||
if (!boundaries) return []
|
if (!boundaries) return []
|
||||||
|
|
||||||
return flatten([
|
return dedupeClassLists(
|
||||||
|
flatten([
|
||||||
...(await Promise.all(
|
...(await Promise.all(
|
||||||
boundaries
|
boundaries
|
||||||
.filter((b) => b.type === 'html' || b.type === 'jsx')
|
.filter((b) => b.type === 'html' || b.type === 'jsx')
|
||||||
|
@ -315,6 +327,7 @@ export async function findClassListsInDocument(
|
||||||
.map(({ range }) => findClassListsInCssRange(doc, range)),
|
.map(({ range }) => findClassListsInCssRange(doc, range)),
|
||||||
await findCustomClassLists(state, doc),
|
await findCustomClassLists(state, doc),
|
||||||
])
|
])
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function findHelperFunctionsInDocument(
|
export function findHelperFunctionsInDocument(
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { Range } from 'vscode-languageserver'
|
import type { Range } from 'vscode-languageserver'
|
||||||
|
|
||||||
export function rangesEqual(a: Range, b: Range): boolean {
|
export function rangesEqual(a: Range, b: Range): boolean {
|
||||||
return (
|
return (
|
||||||
|
|
Loading…
Reference in New Issue