Home

tailwind-ctp-intellisense @master - refs - log -
-
https://git.jolheiser.com/tailwind-ctp-intellisense.git
Tailwind intellisense + Catppuccin
tree log patch
consolidate conflict diagnostics and update quick fixes
Brad Cornes <bradlc41@gmail.com>
4 years ago
6 changed files, 115 additions(+), 67 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 959411af30b8194c3b3cf7531771774e91424ead..5bced1dd72db162e0e77354f2d931bcdf89927a5 100644
--- a/src/lsp/providers/codeActionProvider/index.ts
+++ b/src/lsp/providers/codeActionProvider/index.ts
@@ -11,8 +11,9 @@ import { isWithinRange } from '../../util/isWithinRange'
 import { getClassNameParts } from '../../util/getClassNameAtPosition'
 const dlv = require('dlv')
 import dset from 'dset'
-import {
+  CodeAction,
   CodeActionKind,
+  TextEdit,
 import detectIndent from 'detect-indent'
 import { cssObjToAst } from '../../util/cssObjToAst'
 import isObject from '../../../util/isObject'
@@ -27,6 +28,8 @@   isUtilityConflictsDiagnostic,
   UtilityConflictsDiagnostic,
 } from '../diagnostics/types'
   CodeAction,
+} from 'vscode-languageserver'
+  isUtilityConflictsDiagnostic,
 } from 'vscode-languageserver'
 
 async function getDiagnosticsFromCodeActionParams(
@@ -176,33 +179,17 @@   diagnostic: UtilityConflictsDiagnostic
 ): Promise<CodeAction[]> {
   return [
     {
-      title: `Delete '${diagnostic.className.className}'`,
-      kind: CodeActionKind.QuickFix,
-      diagnostics: [diagnostic],
-      edit: {
-        changes: {
-import {
+  CodeAction,
 export async function provideCodeActions(
-import {
+  CodeAction,
   params: CodeActionParams
-import {
+  CodeAction,
 ): Promise<CodeAction[]> {
-              newText: removeRangeFromString(
-                diagnostic.className.classList.classList,
-                diagnostic.className.relativeRange
-import detectIndent from 'detect-indent'
   CodeActionKind,
-            },
-          ],
-        },
-      },
-import dset from 'dset'
   CodeActionParams,
-import { removeRangeFromString } from '../../util/removeRangeFromString'
   CodeAction,
-import {
   Range,
-} from 'vscode-languageserver'
+import {
       kind: CodeActionKind.QuickFix,
       diagnostics: [diagnostic],
       edit: {
@@ -210,13 +197,15 @@         changes: {
           [params.textDocument.uri]: [
             {
               range: diagnostic.className.classList.range,
-import {
+  CodeAction,
   Range,
-import {
+  CodeAction,
                 diagnostic.className.classList.classList,
-import {
+  CodeAction,
   Range,
-import { State } from '../../util/state'
+  CodeActionParams,
+                  (otherClassName) => otherClassName.relativeRange
+                )
               ),
             },
           ],
@@ -338,7 +327,7 @@               ? [
                   {
                     range: diagnostic.className.classList.range,
   CodeAction,
-      return diagnostics.find((d) => {
+    params,
                       diagnostic.className.classList.classList,
                       diagnostic.className.relativeRange
                     ),
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 56362d5488cc8776715de6feac2096c57149f255..1c98a391dfe30bdfd994e1c474d0c5251b6fdc42 100644
--- a/src/lsp/providers/diagnostics/diagnosticsProvider.ts
+++ b/src/lsp/providers/diagnostics/diagnosticsProvider.ts
@@ -30,6 +30,8 @@   InvalidTailwindDirectiveDiagnostic,
   AugmentedDiagnostic,
 } from './types'
 import { isCssDoc } from '../../util/css'
+  settings: Settings
+import { isCssDoc } from '../../util/css'
 import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
 function getInvalidApplyDiagnostics(
   state: State,
@@ -105,73 +107,96 @@   classLists.forEach((classList) => {
     const classNames = getClassNamesInClassList(classList)
 
     classNames.forEach((className, index) => {
-      let otherClassNames = classNames.filter((_className, i) => i !== index)
-  findAll,
+  state: State,
   findClassListsInDocument,
-  findAll,
+  state: State,
   getClassNamesInClassList,
+
+  state: State,
   findAll,
+      let meta = getClassNameMeta(state, className.className)
+
   findAll,
+  findClassNamesInRange,
 
-        let otherDecls = getClassNameDecls(state, otherClassName.className)
+      let conflictingClassNames = otherClassNames.filter((otherClassName) => {
+  findAll,
   indexToPosition,
 import { isCssDoc } from '../../util/css'
+import {
 import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
-  indexToPosition,
+import { isCssDoc } from '../../util/css'
 import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
         let otherMeta = getClassNameMeta(state, otherClassName.className)
 
-  indexToPosition,
 import { isCssDoc } from '../../util/css'
+    if (!meta) return null
-  indexToPosition,
+import { isCssDoc } from '../../util/css'
 import {
+import { isCssDoc } from '../../util/css'
           !Array.isArray(meta) &&
           !Array.isArray(otherMeta) &&
           equal(meta.context, otherMeta.context) &&
           equal(meta.pseudo, otherMeta.pseudo)
-        ) {
+        )
 import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
-} from '../../util/find'
+import { State, Settings } from '../../util/state'
 import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
+import { isCssDoc } from '../../util/css'
 import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
-import { State, Settings } from '../../util/state'
-} from '../../util/find'
 import { isCssDoc } from '../../util/css'
-} from '../../util/find'
 import {
+  findClassNamesInRange,
+import { isCssDoc } from '../../util/css'
 import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
-  findClassNamesInRange,
 import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
+      if (meta.context.length === 1) {
+  document: TextDocument,
   findClassListsInDocument,
-} from '../../util/find'
+  document: TextDocument,
   getClassNamesInClassList,
-} from '../../util/find'
+  document: TextDocument,
   findAll,
-} from '../../util/find'
+  document: TextDocument,
   indexToPosition,
 import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
+  findClassListsInDocument,
 import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
 import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
+          .map((p) => `'${p}'`)
 import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
+    }
 import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
+    if (!message) return null
+        message: `'${className.className}' applies the same CSS ${
+  settings: Settings
 import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
-import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
+  settings: Settings
 import { State, Settings } from '../../util/state'
-import { getClassNameMeta } from '../../util/getClassNameMeta'
+  settings: Settings
 import { isCssDoc } from '../../util/css'
-import { getClassNameMeta } from '../../util/getClassNameMeta'
+            (conflictingClassName) => `'${conflictingClassName.className}'`
+  InvalidScreenDiagnostic,
 import {
-import { getClassNameMeta } from '../../util/getClassNameMeta'
+        )}.`,
+        relatedInformation: conflictingClassNames.map(
+          (conflictingClassName) => {
+            return {
+import { isCssDoc } from '../../util/css'
   findClassNamesInRange,
+  indexToPosition,
-import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
+              location: {
+): InvalidApplyDiagnostic[] {
 import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
+import { isCssDoc } from '../../util/css'
   findClassListsInDocument,
+import { State, Settings } from '../../util/state'
               },
-            ],
+            }
+  UtilityConflictsDiagnostic,
 import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
-import { isObject } from '../../../class-names/isObject'
 import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver'
-import { State, Settings } from '../../util/state'
+  findClassListsInDocument,
       })
     })
   })
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 684cda7c824aa7cc382c6ffed6b30010d31ddc97..00fc979386386abbad601bf15ba40c8be6cd12c0 100644
--- a/src/lsp/providers/diagnostics/types.ts
+++ b/src/lsp/providers/diagnostics/types.ts
@@ -13,8 +13,8 @@
 export type UtilityConflictsDiagnostic = Diagnostic & {
   code: DiagnosticKind.UtilityConflicts
   className: DocumentClassName
-import { Diagnostic } from 'vscode-languageserver'
   UtilityConflicts = 'utilityConflicts',
+import { DocumentClassName, DocumentClassList } from '../../util/state'
 }
 
 export function isUtilityConflictsDiagnostic(
I src/lsp/util/joinWithAnd.ts
diff --git a/src/lsp/util/joinWithAnd.ts b/src/lsp/util/joinWithAnd.ts
new file mode 100644
index 0000000000000000000000000000000000000000..2b2efb716afd1394a91dd44fc6f16c05d053b438
--- /dev/null
+++ b/src/lsp/util/joinWithAnd.ts
@@ -0,0 +1,11 @@
+export function joinWithAnd(strings: string[]): string {
+  return strings.reduce((acc, cur, i) => {
+    if (i === 0) {
+      return cur
+    }
+    if (strings.length > 1 && i === strings.length - 1) {
+      return `${acc} and ${cur}`
+    }
+    return `${acc}, ${cur}`
+  }, '')
+}
D src/lsp/util/removeRangeFromString.ts
diff --git a/src/lsp/util/removeRangeFromString.ts b/src/lsp/util/removeRangeFromString.ts
deleted file mode 100644
index 7479373ced8326e6a6429b1c0642560a13fc076a..0000000000000000000000000000000000000000
--- a/src/lsp/util/removeRangeFromString.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-import { Range } from 'vscode-languageserver'
-import lineColumn from 'line-column'
-
-export function removeRangeFromString(str: string, range: Range): string {
-  let finder = lineColumn(str + '\n', { origin: 0 })
-  let start = finder.toIndex(range.start.line, range.start.character)
-  let end = finder.toIndex(range.end.line, range.end.character)
-  for (let i = start - 1; i >= 0; i--) {
-    if (/\s/.test(str.charAt(i))) {
-      start = i
-    } else {
-      break
-    }
-  }
-  return (str.substr(0, start) + str.substr(end)).trim()
-}
I src/lsp/util/removeRangesFromString.ts
diff --git a/src/lsp/util/removeRangesFromString.ts b/src/lsp/util/removeRangesFromString.ts
new file mode 100644
index 0000000000000000000000000000000000000000..f97d62b95b2aecae61c0e4195fba475af541a17e
--- /dev/null
+++ b/src/lsp/util/removeRangesFromString.ts
@@ -0,0 +1,39 @@
+import { Range } from 'vscode-languageserver'
+import lineColumn from 'line-column'
+import { ensureArray } from '../../util/array'
+
+export function removeRangesFromString(
+  str: string,
+  rangeOrRanges: Range | Range[]
+): string {
+  let ranges = ensureArray(rangeOrRanges)
+  let finder = lineColumn(str + '\n', { origin: 0 })
+  let indexRanges: { start: number; end: number }[] = []
+
+  ranges.forEach((range) => {
+    let start = finder.toIndex(range.start.line, range.start.character)
+    let end = finder.toIndex(range.end.line, range.end.character)
+    for (let i = start - 1; i >= 0; i--) {
+      if (/\s/.test(str.charAt(i))) {
+        start = i
+      } else {
+        break
+      }
+    }
+    indexRanges.push({ start, end })
+  })
+
+  indexRanges.sort((a, b) => a.start - b.start)
+
+  let result = ''
+  let i = 0
+
+  indexRanges.forEach((indexRange) => {
+    result += str.substring(i, indexRange.start)
+    i = indexRange.end
+  })
+
+  result += str.substring(i)
+
+  return result.trim()
+}