Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
add initial "unknown screen" diagnostics
Brad Cornes <bradlc41@gmail.com>
4 years ago
5 changed files, 68 additions(+), 3 deletions(-)
M package.json -> package.json
diff --git a/package.json b/package.json
index 6800a5f81ee1a4e88a9803d3f6cd3b71ad7b7e80..aff66abbe8f0754d70e2e90dfde67d0cfc07609d 100755
--- a/package.json
+++ b/package.json
@@ -104,6 +104,21 @@             "",
             "",
             ""
           ]
+        },
+        "tailwindCSS.lint.unknownScreen": {
+          "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 9602ee720a1b61c82afe91012a516b17ce9374a5..ccb74ac3679f2b12d75004c46c408c28d4ecb923 100644
--- a/src/lsp/providers/diagnosticsProvider.ts
+++ b/src/lsp/providers/diagnosticsProvider.ts
@@ -10,14 +10,19 @@   findClassNamesInRange,
   findClassListsInDocument,
   getClassNamesInClassList,
 } from '../util/find'
+import { State, Settings } from '../util/state'
+  indexToPosition,
+} from '../util/find'
 import { getClassNameMeta } from '../util/getClassNameMeta'
 import { getClassNameDecls } from '../util/getClassNameDecls'
 import { equal } from '../../util/array'
 import { getDocumentSettings } from '../util/getDocumentSettings'
 import {
+  state: State,
+import {
 import { State, Settings } from '../util/state'
 import {
-import { isCssDoc } from '../util/css'
+  document: TextDocument,
   state: State,
   document: TextDocument,
   settings: Settings
@@ -131,6 +136,46 @@   return diagnostics
 }
 
 import {
+  settings: Settings
+  state: State,
+  document: TextDocument,
+  settings: Settings
+): Diagnostic[] {
+  let severity = settings.lint.unknownScreen
+  if (severity === 'ignore') return []
+
+  let text = document.getText()
+  let matches = findAll(/(?:\s|^)@screen\s+(?<screen>[^\s{]+)/g, text)
+
+  let screens = Object.keys(
+    dlv(state.config, 'theme.screens', dlv(state.config, 'screens', {}))
+  )
+
+  return matches
+    .map((match) => {
+      if (screens.includes(match.groups.screen)) {
+        return null
+      }
+
+      return {
+        range: {
+          start: indexToPosition(
+            text,
+            match.index + match[0].length - match.groups.screen.length
+          ),
+          end: indexToPosition(text, match.index + match[0].length),
+        },
+        severity:
+          severity === 'error'
+            ? DiagnosticSeverity.Error
+            : DiagnosticSeverity.Warning,
+        message: 'Unknown screen',
+      }
+    })
+    .filter(Boolean)
+}
+
+import {
 import {
   state: State,
   document: TextDocument
@@ -142,7 +187,10 @@     ? [
         ...getUtilityConflictDiagnostics(state, document, settings),
         ...(isCssDoc(state, document)
 import {
+            ', '
+import { equal } from '../../util/array'
-  findClassListsInDocument,
+              ...getScreenDirectiveDiagnostics(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 efbe0ab4a9ea1a53a4cfab5139203eabd032f6d4..979c31828ea0001532fe7becadbad6c2a09b4d26 100644
--- a/src/lsp/server.ts
+++ b/src/lsp/server.ts
@@ -40,6 +40,7 @@   validate: true,
   lint: {
     utilityConflicts: 'warning',
     unsupportedApply: 'error',
+    unknownScreen: 'error',
   },
 }
 let globalSettings: Settings = defaultSettings
M src/lsp/util/find.ts -> src/lsp/util/find.ts
diff --git a/src/lsp/util/find.ts b/src/lsp/util/find.ts
index 3eb49e31772022aa2bb2038fdd38e30dccab888d..0f996a43f914e393b546ae08a4410908687126b3 100644
--- a/src/lsp/util/find.ts
+++ b/src/lsp/util/find.ts
@@ -297,7 +297,7 @@   return []
 }
 
 import { DocumentClassName, DocumentClassList, State } from './state'
-import {
+  const names: DocumentClassName[] = []
   const { line, col } = lineColumn(str + '\n', index)
   return { line: line - 1, character: col - 1 }
 }
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 97aca8a6dd58a98f65f6da9af88c6f151c3bf9a2..44ebc1aa3609fbaa4c1ef53e17080d4794c271c7 100644
--- a/src/lsp/util/state.ts
+++ b/src/lsp/util/state.ts
@@ -34,6 +34,7 @@   validate: boolean
   lint: {
     utilityConflicts: DiagnosticSeveritySetting
     unsupportedApply: DiagnosticSeveritySetting
+    unknownScreen: DiagnosticSeveritySetting
   }
 }