Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
refactor "suggestion" quick fixes
Brad Cornes <bradlc41@gmail.com>
4 years ago
3 changed files, 50 additions(+), 24 deletions(-)
M src/lsp/providers/codeActionProvider/index.ts -> src/lsp/providers/codeActionProvider/index.ts
diff --git a/src/lsp/providers/codeActionProvider/index.ts b/src/lsp/providers/codeActionProvider/index.ts
index 5bced1dd72db162e0e77354f2d931bcdf89927a5..6ae4bf984ee3310f28f8a627347c6b54b8ad140c 100644
--- a/src/lsp/providers/codeActionProvider/index.ts
+++ b/src/lsp/providers/codeActionProvider/index.ts
@@ -25,6 +25,11 @@   InvalidApplyDiagnostic,
   isUtilityConflictsDiagnostic,
   UtilityConflictsDiagnostic,
   CodeAction,
+  params: CodeActionParams
+  isInvalidTailwindDirectiveDiagnostic,
+  isInvalidScreenDiagnostic,
+  isInvalidVariantDiagnostic,
+  CodeAction,
   TextEdit,
 import { flatten, dedupeBy } from '../../../util/array'
 import { joinWithAnd } from '../../util/joinWithAnd'
@@ -73,22 +78,20 @@     if (isUtilityConflictsDiagnostic(diagnostic)) {
       return provideUtilityConflictsCodeActions(state, params, diagnostic)
     }
 
-    let match = findLast(
+    if (
-      / Did you mean (?:something like )?'(?<replacement>[^']+)'\?$/g,
+      isInvalidConfigPathDiagnostic(diagnostic) ||
+  UtilityConflictsDiagnostic,
   TextEdit,
-import { State } from '../../util/state'
-    )
   CodeAction,
-import { findLast } from '../../util/find'
+  Range,
 } from 'vscode-languageserver'
-      return []
-    }
+      isInvalidVariantDiagnostic(diagnostic)
   CodeAction,
+  Range,
 import { findLast } from '../../util/find'
-} from 'vscode-languageserver'
   CodeAction,
+  let actions = diagnostics.map((diagnostic) => {
-      {
-        title: `Replace with '${match.groups.replacement}'`,
+        title: `Replace with '${suggestion}'`,
         kind: CodeActionKind.QuickFix,
         diagnostics: [diagnostic],
         edit: {
@@ -95,14 +99,16 @@           changes: {
             [params.textDocument.uri]: [
               {
                 range: diagnostic.range,
-import { State } from '../../util/state'
+} from '../diagnostics/types'
   CodeAction,
               },
             ],
           },
         },
-      },
+      }))
-    ]
+    }
+
+    return []
   })
 
   return Promise.all(actions)
M src/lsp/providers/diagnostics/diagnosticsProvider.ts -> src/lsp/providers/diagnostics/diagnosticsProvider.ts
diff --git a/src/lsp/providers/diagnostics/diagnosticsProvider.ts b/src/lsp/providers/diagnostics/diagnosticsProvider.ts
index 1c98a391dfe30bdfd994e1c474d0c5251b6fdc42..91ca0e3eedd6db523fbaf2a96198b659330771ab 100644
--- a/src/lsp/providers/diagnostics/diagnosticsProvider.ts
+++ b/src/lsp/providers/diagnostics/diagnosticsProvider.ts
@@ -197,8 +197,11 @@         return null
       }
 
       let message = `The screen '${match.groups.screen}' does not exist in your theme config.`
+      let suggestions: string[] = []
       let suggestion = closest(match.groups.screen, screens)
+
       if (suggestion) {
+        suggestions.push(suggestion)
         message += ` Did you mean '${suggestion}'?`
       }
 
@@ -219,6 +222,7 @@           severity === 'error'
             ? DiagnosticSeverity.Error
             : DiagnosticSeverity.Warning,
         message,
+        suggestions,
       })
     })
   })
@@ -261,8 +265,11 @@           continue
         }
 
         let message = `The variant '${variant}' does not exist.`
+        let suggestions: string[] = []
         let suggestion = closest(variant, state.variants)
+
         if (suggestion) {
+          suggestions.push(suggestion)
           message += ` Did you mean '${suggestion}'?`
         }
 
@@ -283,6 +290,7 @@             severity === 'error'
               ? DiagnosticSeverity.Error
               : DiagnosticSeverity.Warning,
           message,
+          suggestions,
         })
       }
     })
@@ -338,6 +346,8 @@         }, '')
 
       let message: string
 import { isCssDoc } from '../../util/css'
+  settings: Settings
+import { isCssDoc } from '../../util/css'
 import { State, Settings } from '../../util/state'
       if (isValid(value)) {
         // The value resolves successfully, but we need to check that there
@@ -375,31 +385,30 @@             keys[keys.length - 1],
             Object.keys(parentValue).filter((key) => isValid(parentValue[key]))
           )
           if (closestValidKey) {
+  state: State,
 import { State, Settings } from '../../util/state'
-          .join(', ')}).`
-              ...keys.slice(0, keys.length - 1),
+              stitch([...keys.slice(0, keys.length - 1), closestValidKey])
-import { State, Settings } from '../../util/state'
+            )
+  state: State,
   findClassNamesInRange,
-  indexToPosition,
-            ])}'?`
           }
         }
       } else {
         message = `'${match.groups.key}' was found but does not resolve to a string.`
 
         if (isObject(value)) {
-  InvalidVariantDiagnostic,
 import { isCssDoc } from '../../util/css'
+      message = `'@apply' cannot be used with '${className.className}' because it is included in multiple rulesets.`
             isValid(value[key])
           )
-          if (firstValidKey) {
-            message += ` Did you mean something like '${stitch([
-  InvalidVariantDiagnostic,
+  state: State,
   getClassNamesInClassList,
+  state: State,
 import { State, Settings } from '../../util/state'
-  findClassListsInDocument,
+  state: State,
   findAll,
-            ])}'?`
+            )
+            message += ` Did you mean something like '${suggestions[0]}'?`
           }
         }
       }
@@ -429,6 +438,8 @@           severity === 'error'
             ? DiagnosticSeverity.Error
             : DiagnosticSeverity.Warning,
 import semver from 'semver'
+  findAll,
+function getInvalidApplyDiagnostics(
   findAll,
       })
     })
@@ -473,11 +484,15 @@         return null
       }
 
       let message = `'${match.groups.value}' is not a valid group.`
+      let suggestions: string[] = []
+
       if (match.groups.value === 'preflight') {
+        suggestions.push('base')
         message += ` Did you mean 'base'?`
       } else {
         let suggestion = closest(match.groups.value, valid)
         if (suggestion) {
+          suggestions.push(suggestion)
           message += ` Did you mean '${suggestion}'?`
         }
       }
@@ -499,6 +514,8 @@           severity === 'error'
             ? DiagnosticSeverity.Error
             : DiagnosticSeverity.Warning,
 import semver from 'semver'
+  findAll,
+function getInvalidApplyDiagnostics(
   findAll,
       })
     })
M src/lsp/providers/diagnostics/types.ts -> src/lsp/providers/diagnostics/types.ts
diff --git a/src/lsp/providers/diagnostics/types.ts b/src/lsp/providers/diagnostics/types.ts
index 00fc979386386abbad601bf15ba40c8be6cd12c0..385aac55033657c115363d37bf2c00414d581a60 100644
--- a/src/lsp/providers/diagnostics/types.ts
+++ b/src/lsp/providers/diagnostics/types.ts
@@ -35,6 +35,7 @@ }
 
 export type InvalidScreenDiagnostic = Diagnostic & {
   code: DiagnosticKind.InvalidScreen
+  suggestions: string[]
 }
 
 export function isInvalidScreenDiagnostic(
@@ -45,6 +46,7 @@ }
 
 export type InvalidVariantDiagnostic = Diagnostic & {
   code: DiagnosticKind.InvalidVariant
+  suggestions: string[]
 }
 
 export function isInvalidVariantDiagnostic(
@@ -55,6 +57,7 @@ }
 
 export type InvalidConfigPathDiagnostic = Diagnostic & {
   code: DiagnosticKind.InvalidConfigPath
+  suggestions: string[]
 }
 
 export function isInvalidConfigPathDiagnostic(
@@ -65,6 +68,7 @@ }
 
 export type InvalidTailwindDirectiveDiagnostic = Diagnostic & {
   code: DiagnosticKind.InvalidTailwindDirective
+  suggestions: string[]
 }
 
 export function isInvalidTailwindDirectiveDiagnostic(