classRegex: increase search range, make search global (#129)
parent
f95c881b45
commit
85fb953d0a
|
@ -205,26 +205,29 @@ async function provideCustomClassNameCompletions(
|
||||||
const regexes = dlv(settings, 'experimental.classRegex', [])
|
const regexes = dlv(settings, 'experimental.classRegex', [])
|
||||||
if (regexes.length === 0) return null
|
if (regexes.length === 0) return null
|
||||||
|
|
||||||
const searchRange = {
|
const positionOffset = document.offsetAt(position)
|
||||||
start: { line: Math.max(position.line - 10, 0), character: 0 },
|
|
||||||
end: { line: position.line + 10, character: 0 },
|
const searchRange: Range = {
|
||||||
|
start: document.positionAt(Math.max(0, positionOffset - 500)),
|
||||||
|
end: document.positionAt(positionOffset + 500),
|
||||||
}
|
}
|
||||||
|
|
||||||
let str = document.getText(searchRange)
|
let str = document.getText(searchRange)
|
||||||
|
|
||||||
for (let i = 0; i < regexes.length; i++) {
|
for (let i = 0; i < regexes.length; i++) {
|
||||||
|
try {
|
||||||
let [containerRegex, classRegex] = Array.isArray(regexes[i])
|
let [containerRegex, classRegex] = Array.isArray(regexes[i])
|
||||||
? regexes[i]
|
? regexes[i]
|
||||||
: [regexes[i]]
|
: [regexes[i]]
|
||||||
containerRegex = new MultiRegexp(new RegExp(containerRegex))
|
|
||||||
try {
|
containerRegex = new MultiRegexp(new RegExp(containerRegex, 'g'))
|
||||||
const match = containerRegex.execForGroup(str, 1)
|
let containerMatch
|
||||||
if (match === null) {
|
|
||||||
throw Error()
|
while ((containerMatch = containerRegex.execForGroup(str, 1)) !== null) {
|
||||||
}
|
console.log(containerMatch)
|
||||||
const searchStart = document.offsetAt(searchRange.start)
|
const searchStart = document.offsetAt(searchRange.start)
|
||||||
const matchStart = searchStart + match.start
|
const matchStart = searchStart + containerMatch.start
|
||||||
const matchEnd = searchStart + match.end
|
const matchEnd = searchStart + containerMatch.end
|
||||||
const cursor = document.offsetAt(position)
|
const cursor = document.offsetAt(position)
|
||||||
if (cursor >= matchStart && cursor <= matchEnd) {
|
if (cursor >= matchStart && cursor <= matchEnd) {
|
||||||
let classList
|
let classList
|
||||||
|
@ -232,8 +235,12 @@ async function provideCustomClassNameCompletions(
|
||||||
if (classRegex) {
|
if (classRegex) {
|
||||||
classRegex = new MultiRegexp(new RegExp(classRegex, 'g'))
|
classRegex = new MultiRegexp(new RegExp(classRegex, 'g'))
|
||||||
let classMatch
|
let classMatch
|
||||||
|
|
||||||
while (
|
while (
|
||||||
(classMatch = classRegex.execForGroup(match.match, 1)) !== null
|
(classMatch = classRegex.execForGroup(
|
||||||
|
containerMatch.match,
|
||||||
|
1
|
||||||
|
)) !== null
|
||||||
) {
|
) {
|
||||||
const classMatchStart = matchStart + classMatch.start
|
const classMatchStart = matchStart + classMatch.start
|
||||||
const classMatchEnd = matchStart + classMatch.end
|
const classMatchEnd = matchStart + classMatch.end
|
||||||
|
@ -241,11 +248,12 @@ async function provideCustomClassNameCompletions(
|
||||||
classList = classMatch.match.substr(0, cursor - classMatchStart)
|
classList = classMatch.match.substr(0, cursor - classMatchStart)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof classList === 'undefined') {
|
if (typeof classList === 'undefined') {
|
||||||
throw Error()
|
throw Error()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
classList = match.match.substr(0, cursor - matchStart)
|
classList = containerMatch.match.substr(0, cursor - matchStart)
|
||||||
}
|
}
|
||||||
|
|
||||||
return completionsFromClassList(state, classList, {
|
return completionsFromClassList(state, classList, {
|
||||||
|
@ -256,6 +264,7 @@ async function provideCustomClassNameCompletions(
|
||||||
end: position,
|
end: position,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue