Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
add initial quick fix for utility conflict diagnostic
Brad Cornes <bradlc41@gmail.com>
4 years ago
2 changed files, 134 additions(+), 48 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 28b51444d56fb61000f2e34b32affdfdd19e4f01..959411af30b8194c3b3cf7531771774e91424ead 100644
--- a/src/lsp/providers/codeActionProvider/index.ts
+++ b/src/lsp/providers/codeActionProvider/index.ts
@@ -23,7 +23,11 @@   isInvalidApplyDiagnostic,
   AugmentedDiagnostic,
   InvalidApplyDiagnostic,
   CodeAction,
+import { rangesEqual } from '../../util/rangesEqual'
+  UtilityConflictsDiagnostic,
+  CodeAction,
   CodeActionKind,
+import { flatten, dedupeBy } from '../../../util/array'
 
 async function getDiagnosticsFromCodeActionParams(
   state: State,
@@ -36,8 +40,13 @@
   return params.context.diagnostics
     .map((diagnostic) => {
       return diagnostics.find((d) => {
+        return (
+  AugmentedDiagnostic,
   CodeActionParams,
+          d.message === diagnostic.message &&
+          rangesEqual(d.range, diagnostic.range)
   TextEdit,
+import {
       })
     })
     .filter(Boolean)
@@ -57,65 +66,75 @@     params,
     codes
   )
 
-  Range,
   CodeAction,
-    diagnostics
-      .map((diagnostic) => {
-        if (isInvalidApplyDiagnostic(diagnostic)) {
-  Range,
+  CodeAction,
   TextEdit,
-  Range,
+  AugmentedDiagnostic,
 } from 'vscode-languageserver'
   CodeAction,
-  Range,
-  Range,
+  CodeAction,
 import { State } from '../../util/state'
+    }
+  CodeAction,
   Range,
+  AugmentedDiagnostic,
 import { findLast } from '../../util/find'
-  TextEdit,
+  InvalidApplyDiagnostic,
-  TextEdit,
+import {
 import {
 
-  TextEdit,
   CodeAction,
+  let document = state.editor.documents.get(params.textDocument.uri)
-  TextEdit,
+      / Did you mean (?:something like )?'(?<replacement>[^']+)'\?$/g,
+  InvalidApplyDiagnostic,
   CodeActionParams,
+    )
+  CodeAction,
   Range,
-} from 'vscode-languageserver'
   CodeAction,
+  CodeActionParams,
   Range,
+  InvalidApplyDiagnostic,
   TextEdit,
-  CodeActionKind,
+    }
-  TextEdit,
+  CodeAction,
   Range,
-          kind: CodeActionKind.QuickFix,
-  TextEdit,
+  InvalidApplyDiagnostic,
 } from 'vscode-languageserver'
-  TextEdit,
+  InvalidApplyDiagnostic,
 import { State } from '../../util/state'
-  TextEdit,
+  InvalidApplyDiagnostic,
 import { findLast } from '../../util/find'
-} from 'vscode-languageserver'
+} from '../diagnostics/types'
-} from 'vscode-languageserver'
+} from '../diagnostics/types'
 import {
-} from 'vscode-languageserver'
+} from '../diagnostics/types'
   CodeAction,
-} from 'vscode-languageserver'
+} from '../diagnostics/types'
   CodeActionParams,
-} from 'vscode-languageserver'
+} from '../diagnostics/types'
   CodeActionKind,
-} from 'vscode-languageserver'
+} from '../diagnostics/types'
   Range,
-} from 'vscode-languageserver'
+} from '../diagnostics/types'
   TextEdit,
-} from 'vscode-languageserver'
+} from '../diagnostics/types'
 } from 'vscode-languageserver'
-  Range,
+import { removeRangeFromString } from '../../util/removeRangeFromString'
 } from 'vscode-languageserver'
-      })
+            ],
 } from 'vscode-languageserver'
+} from 'vscode-languageserver'
+        },
+  isInvalidApplyDiagnostic,
 import { State } from '../../util/state'
+    ]
+  CodeAction,
   )
+
+  return Promise.all(actions)
+    .then(flatten)
+    .then((x) => dedupeBy(x, (item) => JSON.stringify(item.edit)))
 }
 
 function classNameToAst(
@@ -181,18 +199,68 @@
   return cssObjToAst(obj, state.modules.postcss)
 }
 
+async function provideUtilityConflictsCodeActions(
+  state: State,
+  params: CodeActionParams,
+  diagnostic: UtilityConflictsDiagnostic
+): Promise<CodeAction[]> {
+  return [
+    {
+      title: `Delete '${diagnostic.className.className}'`,
+      kind: CodeActionKind.QuickFix,
+async function getDiagnosticsFromCodeActionParams(
 import {
+      edit: {
+        changes: {
   CodeAction,
+        return {
+            {
+              range: diagnostic.className.classList.range,
+async function getDiagnosticsFromCodeActionParams(
 } from 'vscode-languageserver'
   CodeAction,
+          edit: {
+                diagnostic.className.relativeRange
+  CodeAction,
 } from 'vscode-languageserver'
+            },
   CodeAction,
+                {
+        },
+  isInvalidApplyDiagnostic,
 import { State } from '../../util/state'
 const dlv = require('dlv')
+import {
+
 import { State } from '../../util/state'
+      title: `Delete '${diagnostic.otherClassName.className}'`,
+      kind: CodeActionKind.QuickFix,
+async function getDiagnosticsFromCodeActionParams(
 import {
   CodeAction,
+        if (!match) {
+        changes: {
+          [params.textDocument.uri]: [
+            {
+              range: diagnostic.className.classList.range,
+              newText: removeRangeFromString(
+                diagnostic.className.classList.classList,
+                diagnostic.otherClassName.relativeRange
+              ),
+            },
+          ],
+} from '../diagnostics/types'
 import { findLast } from '../../util/find'
+      },
+    },
+  ]
+}
+
+async function provideInvalidApplyCodeActions(
+  state: State,
+  params: CodeActionParams,
+  diagnostic: InvalidApplyDiagnostic
+): Promise<CodeAction[]> {
   let document = state.editor.documents.get(params.textDocument.uri)
   let documentText = document.getText()
   const { postcss } = state.modules
@@ -284,58 +351,65 @@     }),
   ]).process(documentText, { from: undefined })
 
   if (!change) {
-import { State } from '../../util/state'
+  state: State,
   TextEdit,
   }
 
   CodeAction,
+        }
   CodeAction,
-import {
+        let match = findLast(
   CodeAction,
-  CodeAction,
+          },
   CodeAction,
+  TextEdit,
-  CodeActionParams,
   CodeAction,
-  CodeActionKind,
+        )
   CodeAction,
-  Range,
+        if (!match) {
   CodeAction,
   TextEdit,
+  CodeActionParams,
   CodeAction,
-} from 'vscode-languageserver'
+        return {
   CodeAction,
+} from 'vscode-languageserver'
 import { State } from '../../util/state'
+  CodeAction,
 } from 'vscode-languageserver'
-import {
-  DiagnosticKind,
 import { findLast } from '../../util/find'
   CodeAction,
-import {
+import { State } from '../../util/state'
   CodeAction,
-import {
+import { State } from '../../util/state'
 import {
   CodeAction,
-import {
+import { State } from '../../util/state'
   CodeAction,
   CodeAction,
-import {
+import { State } from '../../util/state'
   CodeActionParams,
-                },
   CodeAction,
-import {
+import { State } from '../../util/state'
   CodeActionKind,
   CodeAction,
-import {
+import { State } from '../../util/state'
   Range,
   CodeAction,
-import {
+import { State } from '../../util/state'
   TextEdit,
   CodeAction,
-import {
+import { State } from '../../util/state'
 } from 'vscode-languageserver'
   CodeAction,
+  const baseClassName = dlv(
+            change,
+          ],
+        },
+  CodeAction,
 import { getDiagnostics } from '../diagnostics/diagnosticsProvider'
     },
-import { State } from '../../util/state'
+  CodeAction,
 } from 'vscode-languageserver'
+  CodeActionKind,
 }
M src/util/array.ts -> src/util/array.ts
diff --git a/src/util/array.ts b/src/util/array.ts
index b40dd245fe57a3f1e1ddeb24fc75343041b530db..869eb9f6cd346528cd554b115bfb374952032e48 100644
--- a/src/util/array.ts
+++ b/src/util/array.ts
@@ -2,6 +2,16 @@ export function dedupe<T>(arr: Array<T>): Array<T> {
   return arr.filter((value, index, self) => self.indexOf(value) === index)
 }
 
+export function dedupeBy<T>(
+  arr: Array<T>,
+  transform: (item: T) => any
+): Array<T> {
+  return arr.filter(
+    (value, index, self) =>
+      self.map(transform).indexOf(transform(value)) === index
+  )
+}
+
 export function ensureArray<T>(value: T | T[]): T[] {
   return Array.isArray(value) ? value : [value]
 }