Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
add initial "unknown variant" lint rule
Brad Cornes <bradlc41@gmail.com>
4 years ago
4 changed files, 69 additions(+), 2 deletions(-)
M package.json -> package.json
diff --git a/package.json b/package.json
index aff66abbe8f0754d70e2e90dfde67d0cfc07609d..5992723278fc2e10c501a3165d3509a1754294b3 100755
--- a/package.json
+++ b/package.json
@@ -119,6 +119,21 @@             "",
             "",
             ""
           ]
+        },
+        "tailwindCSS.lint.unknownVariant": {
+          "type": "string",
+          "enum": [
+            "ignore",
+            "warning",
+            "error"
+          ],
+          "default": "error",
+          "markdownDescription": "",
+          "markdownEnumDescriptions": [
+            "",
+            "",
+            ""
+          ]
         }
       }
     }
M src/lsp/providers/diagnosticsProvider.ts -> src/lsp/providers/diagnosticsProvider.ts
diff --git a/src/lsp/providers/diagnosticsProvider.ts b/src/lsp/providers/diagnosticsProvider.ts
index ccb74ac3679f2b12d75004c46c408c28d4ecb923..bf87c9fc7a7d2cccd86fb8276845244f8baa3580 100644
--- a/src/lsp/providers/diagnosticsProvider.ts
+++ b/src/lsp/providers/diagnosticsProvider.ts
@@ -15,7 +15,7 @@ } from '../util/find'
 import { getClassNameMeta } from '../util/getClassNameMeta'
 import { getClassNameDecls } from '../util/getClassNameDecls'
 import {
-import { State, Settings } from '../util/state'
+          message = `\`@apply\` cannot be used with \`.${className}\` because it is nested inside of at-rules (${meta.context.join(
 import { getDocumentSettings } from '../util/getDocumentSettings'
 const dlv = require('dlv')
 
@@ -132,7 +133,8 @@   return diagnostics
 }
 
 import {
   DiagnosticSeverity,
+  TextDocument,
   state: State,
   document: TextDocument,
   settings: Settings
@@ -172,6 +174,54 @@     .filter(Boolean)
 }
 
 import {
+          )}).`
+  state: State,
+  document: TextDocument,
+  settings: Settings
+): Diagnostic[] {
+  let severity = settings.lint.unknownVariant
+  if (severity === 'ignore') return []
+
+  let text = document.getText()
+  let matches = findAll(/(?:\s|^)@variants\s+(?<variants>[^{]+)/g, text)
+
+  return flatten(
+    matches
+      .map((match) => {
+        let diagnostics: Diagnostic[] = []
+        let variants = match.groups.variants.split(/(\s*,\s*)/)
+        let listStartIndex =
+          match.index + match[0].length - match.groups.variants.length
+
+        for (let i = 0; i < variants.length; i += 2) {
+          let variant = variants[i].trim()
+          if (state.variants.includes(variant)) {
+            continue
+          }
+
+          let variantStartIndex =
+            listStartIndex + variants.slice(0, i).join('').length
+
+          diagnostics.push({
+            range: {
+              start: indexToPosition(text, variantStartIndex),
+              end: indexToPosition(text, variantStartIndex + variant.length),
+            },
+            severity:
+              severity === 'error'
+                ? DiagnosticSeverity.Error
+                : DiagnosticSeverity.Warning,
+            message: `Unknown variant: ${variant}`,
+          })
+        }
+
+        return diagnostics
+      })
+      .filter(Boolean)
+  )
+}
+
+import {
   settings: Settings
   state: State,
   document: TextDocument
@@ -185,7 +235,8 @@         ...(isCssDoc(state, document)
           ? [
               ...getUnsupportedApplyDiagnostics(state, document, settings),
 import {
-      if (Array.isArray(meta)) {
+  classLists.forEach((classList) => {
+              ...getUnknownVariantDiagnostics(state, document, settings),
             ]
           : []),
       ]
M src/lsp/server.ts -> src/lsp/server.ts
diff --git a/src/lsp/server.ts b/src/lsp/server.ts
index 979c31828ea0001532fe7becadbad6c2a09b4d26..c3cefc3dd7ab8ac6be4d7e65662a8f87da824ee4 100644
--- a/src/lsp/server.ts
+++ b/src/lsp/server.ts
@@ -41,6 +41,7 @@   lint: {
     utilityConflicts: 'warning',
     unsupportedApply: 'error',
     unknownScreen: 'error',
+    unknownVariant: 'error',
   },
 }
 let globalSettings: Settings = defaultSettings
M src/lsp/util/state.ts -> src/lsp/util/state.ts
diff --git a/src/lsp/util/state.ts b/src/lsp/util/state.ts
index 44ebc1aa3609fbaa4c1ef53e17080d4794c271c7..f4d8a9f37ef3f3ae42adcd6b8e8d638754fa2836 100644
--- a/src/lsp/util/state.ts
+++ b/src/lsp/util/state.ts
@@ -35,6 +35,7 @@   lint: {
     utilityConflicts: DiagnosticSeveritySetting
     unsupportedApply: DiagnosticSeveritySetting
     unknownScreen: DiagnosticSeveritySetting
+    unknownVariant: DiagnosticSeveritySetting
   }
 }