Skip to content

Commit 7148251

Browse files
committed
Improve regexp to recognize className attributes
Previously, regular expression patterns are inconsistent. For example, at the cursor <|> in `className="w-[100px] foo<|>"`, definition provider doesn't provide the definition of `.foo` because the pattern doesn't include `[]`, the part `className="w-[100px] foo` isn't recognized.
1 parent 5dc4f43 commit 7148251

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/extension.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ const registerCompletionProvider = (
155155
break;
156156
}
157157
case "javascript": {
158-
const REGEXP1 = /className=(?:{?"|{?'|{?`)([\w-@:\/ ]*$)/;
159-
const REGEXP2 = /class=(?:{?"|{?')([\w-@:\/ ]*$)/;
158+
const REGEXP1 = /className=(?:{?"|{?'|{?`)([-\w,@\\:\[\] ]*$)/;
159+
const REGEXP2 = /class=(?:{?"|{?')([-\w,@\\:\[\] ]*$)/;
160160

161161
let matched = false;
162162

@@ -330,7 +330,7 @@ const registerHTMLProviders = (disposables: Disposable[]) =>
330330
workspace.getConfiguration()
331331
?.get<string[]>(Configuration.HTMLLanguages)
332332
?.forEach((extension) => {
333-
disposables.push(registerCompletionProvider(extension, { type: "regexp", classMatchRegex: /class=["|']([\w-@:\/ ]*$)/ }));
333+
disposables.push(registerCompletionProvider(extension, { type: "regexp", classMatchRegex: /class=["|']([-\w,@\\:\[\] ]*$)/ }));
334334
});
335335

336336
const registerCSSProviders = (disposables: Disposable[]) =>
@@ -340,15 +340,15 @@ const registerCSSProviders = (disposables: Disposable[]) =>
340340
// The @apply rule was a CSS proposal which has since been abandoned,
341341
// check the proposal for more info: http://tabatkins.github.io/specs/css-apply-rule/
342342
// Its support should probably be removed
343-
disposables.push(registerCompletionProvider(extension, { type: "regexp", classMatchRegex: /@apply ([.\w-@:\/ ]*$)/ }, "."));
343+
disposables.push(registerCompletionProvider(extension, { type: "regexp", classMatchRegex: /@apply ((?:\.|[-\w,@\\:\[\] ])*$)/ }, "."));
344344
});
345345

346346
const registerJavaScriptProviders = (disposables: Disposable[]) =>
347347
workspace.getConfiguration()
348348
.get<string[]>(Configuration.JavaScriptLanguages)
349349
?.forEach((extension) => {
350350
disposables.push(registerCompletionProvider(extension, { type: "javascript" }));
351-
disposables.push(registerDefinitionProvider(extension, /class(?:Name)?=["|']([\w- ]*$)/));
351+
disposables.push(registerDefinitionProvider(extension, /class(?:Name)?=(?:\{?["'`])([-\w,@\\:\[\] ]*$)/));
352352
});
353353

354354
function registerEmmetProviders(disposables: Disposable[]) {

0 commit comments

Comments
 (0)