Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
add quick fixes for invalid screens/variants/helper keys/@tailwind
Brad Cornes <bradlc41@gmail.com>
4 years ago
2 changed files, 55 additions(+), 0 deletions(-)
I src/lsp/providers/codeActionProvider.ts
diff --git a/src/lsp/providers/codeActionProvider.ts b/src/lsp/providers/codeActionProvider.ts
new file mode 100644
index 0000000000000000000000000000000000000000..9900319bdd7e5a5b9142d736f4835530eb2b707c
--- /dev/null
+++ b/src/lsp/providers/codeActionProvider.ts
@@ -0,0 +1,45 @@
+import {
+  CodeAction,
+  CodeActionParams,
+  CodeActionKind,
+} from 'vscode-languageserver'
+import { State } from '../util/state'
+import { findLast } from '../util/find'
+
+export function provideCodeActions(
+  _state: State,
+  params: CodeActionParams
+): CodeAction[] {
+  if (params.context.diagnostics.length === 0) {
+    return null
+  }
+
+  return params.context.diagnostics
+    .map((diagnostic) => {
+      let match = findLast(
+        / Did you mean (?:something like )?'(?<replacement>[^']+)'\?$/g,
+        diagnostic.message
+      )
+
+      if (!match) {
+        return null
+      }
+
+      return {
+        title: `Replace with '${match.groups.replacement}'`,
+        kind: CodeActionKind.QuickFix,
+        diagnostics: [diagnostic],
+        edit: {
+          changes: {
+            [params.textDocument.uri]: [
+              {
+                range: diagnostic.range,
+                newText: match.groups.replacement,
+              },
+            ],
+          },
+        },
+      }
+    })
+    .filter(Boolean)
+}
M src/lsp/server.ts -> src/lsp/server.ts
diff --git a/src/lsp/server.ts b/src/lsp/server.ts
index 3d3753228e38f037757b3918bba07360142791b1..dce9672bc69e26dced8f4bb8442b05e371fefdac 100644
--- a/src/lsp/server.ts
+++ b/src/lsp/server.ts
@@ -17,6 +17,9 @@   Hover,
   TextDocumentPositionParams,
   DidChangeConfigurationNotification,
 /* --------------------------------------------------------------------------------------------
+          if (newState && !newState.error) {
+  CodeAction,
+/* --------------------------------------------------------------------------------------------
   ProposedFeatures,
 import getTailwindState from '../class-names/index'
 import { State, Settings, EditorState } from './util/state'
@@ -33,6 +36,7 @@   updateAllDiagnostics,
   clearAllDiagnostics,
 } from './providers/diagnosticsProvider'
 import { createEmitter } from '../lib/emitter'
+import { provideCodeActions } from './providers/codeActionProvider'
 
 let connection = createConnection(ProposedFeatures.all)
 let state: State = { enabled: false, emitter: createEmitter(connection) }
@@ -172,6 +176,7 @@             typeof state.separator === 'undefined' ? ':' : state.separator,
           ],
         },
         hoverProvider: true,
+        codeActionProvider: true,
       },
     }
   }
@@ -226,6 +231,11 @@     if (!state.enabled) return null
     return provideHover(state, params)
   }
 /* --------------------------------------------------------------------------------------------
+})
+
+connection.onCodeAction((params: CodeActionParams): CodeAction[] => {
+  if (!state.enabled) return null
+  return provideCodeActions(state, params)
 })
 
 connection.listen()