Prevent errors in not semicolon languages (#461)

* fix: prevent errors in not semicolon languages

* fix: extends fix for sugarss and stylus

* Formatting

* Fix document access

Co-authored-by: Brad Cornes <bradlc41@gmail.com>
master
Lucas Vazquez 2022-02-23 08:18:53 -03:00 committed by GitHub
parent 3a33b8345f
commit 627d463f8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 1 deletions

View File

@ -27,11 +27,23 @@ export function getInvalidTailwindDirectiveDiagnostics(
ranges.push(...boundaries.css) ranges.push(...boundaries.css)
} }
let notSemicolonLanguages = ['sass', 'sugarss', 'stylus']
let regex: RegExp
if (
notSemicolonLanguages.includes(document.languageId) ||
(state.editor &&
notSemicolonLanguages.includes(state.editor.userLanguages[document.languageId]))
) {
regex = /(?:\s|^)@tailwind\s+(?<value>[^\n]+)/g
} else {
regex = /(?:\s|^)@tailwind\s+(?<value>[^;]+)/g
}
let hasVariantsDirective = state.jit && semver.gte(state.version, '2.1.99') let hasVariantsDirective = state.jit && semver.gte(state.version, '2.1.99')
ranges.forEach((range) => { ranges.forEach((range) => {
let text = document.getText(range) let text = document.getText(range)
let matches = findAll(/(?:\s|^)@tailwind\s+(?<value>[^;]+)/g, text) let matches = findAll(regex, text)
let valid = [ let valid = [
'utilities', 'utilities',