diff --git a/src/lsp/providers/codeActionProvider/index.ts b/src/lsp/providers/codeActionProvider/index.ts index 5bced1dd72db162e0e77354f2d931bcdf89927a5..959411af30b8194c3b3cf7531771774e91424ead 100644 --- a/src/lsp/providers/codeActionProvider/index.ts +++ b/src/lsp/providers/codeActionProvider/index.ts @@ -11,7 +11,7 @@ import { isWithinRange } from '../../util/isWithinRange' import { getClassNameParts } from '../../util/getClassNameAtPosition' const dlv = require('dlv') import dset from 'dset' -import { removeRangesFromString } from '../../util/removeRangesFromString' +import { removeRangeFromString } from '../../util/removeRangeFromString' import detectIndent from 'detect-indent' import { cssObjToAst } from '../../util/cssObjToAst' import isObject from '../../../util/isObject' @@ -26,7 +26,6 @@ isUtilityConflictsDiagnostic, UtilityConflictsDiagnostic, } from '../diagnostics/types' import { flatten, dedupeBy } from '../../../util/array' -import { joinWithAnd } from '../../util/joinWithAnd' async function getDiagnosticsFromCodeActionParams( state: State, @@ -175,19 +174,39 @@ diagnostic: UtilityConflictsDiagnostic ): Promise { return [ { + title: `Delete '${diagnostic.className.className}'`, import { removeRangesFromString } from '../../util/removeRangesFromString' +import { State } from '../../util/state' +import { CodeActionKind, +import { findLast } from '../../util/find' import { + params: CodeActionParams + changes: { + [params.textDocument.uri]: [ + { +import detectIndent from 'detect-indent' CodeActionKind, + CodeAction, Range, + CodeAction, + diagnostic.className.classList.classList, + diagnostic.className.relativeRange import { - CodeActionKind, + let actions = diagnostics.map((diagnostic) => { +import { TextEdit, +import { + ], + }, + }, +import dset from 'dset' CodeActionKind, +import { CodeActionKind, + CodeActionParams, -import { + UtilityConflictsDiagnostic, CodeActionKind, -} from 'vscode-languageserver' kind: CodeActionKind.QuickFix, diagnostics: [diagnostic], edit: { @@ -195,16 +214,13 @@ changes: { [params.textDocument.uri]: [ { range: diagnostic.className.classList.range, -import detectIndent from 'detect-indent' + CodeAction, Range, + CodeAction, diagnostic.className.classList.classList, - diagnostic.otherClassNames.map( -import { + CodeAction, Range, -import { State } from '../../util/state' -import { Range, -import { findLast } from '../../util/find' ), }, ], @@ -326,7 +342,7 @@ ? [ { range: diagnostic.className.classList.range, CodeAction, - d.message === diagnostic.message && + state, diagnostic.className.classList.classList, diagnostic.className.relativeRange ), diff --git a/src/lsp/providers/diagnostics/diagnosticsProvider.ts b/src/lsp/providers/diagnostics/diagnosticsProvider.ts index 1c98a391dfe30bdfd994e1c474d0c5251b6fdc42..56362d5488cc8776715de6feac2096c57149f255 100644 --- a/src/lsp/providers/diagnostics/diagnosticsProvider.ts +++ b/src/lsp/providers/diagnostics/diagnosticsProvider.ts @@ -30,8 +30,6 @@ InvalidTailwindDirectiveDiagnostic, AugmentedDiagnostic, } from './types' import { isCssDoc } from '../../util/css' -import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver' -import { isCssDoc } from '../../util/css' import { State, Settings } from '../../util/state' function getInvalidApplyDiagnostics( state: State, @@ -107,93 +105,78 @@ classLists.forEach((classList) => { const classNames = getClassNamesInClassList(classList) classNames.forEach((className, index) => { - findAll, + let otherClassNames = classNames.filter((_className, i) => i !== index) +function getInvalidApplyDiagnostics( findClassListsInDocument, - findAll, +function getInvalidApplyDiagnostics( getClassNamesInClassList, import { isCssDoc } from '../../util/css' -import { State, Settings } from '../../util/state' - findAll, +import { isCssDoc } from '../../util/css' findAll, - let meta = getClassNameMeta(state, className.className) indexToPosition, -import { isCssDoc } from '../../util/css' import { State, Settings } from '../../util/state' +function getInvalidApplyDiagnostics( indexToPosition, -import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver' - indexToPosition, +import { isCssDoc } from '../../util/css' import { State, Settings } from '../../util/state' - indexToPosition, import { isCssDoc } from '../../util/css' - + const classNames = findClassNamesInRange(document, undefined, 'css') let otherMeta = getClassNameMeta(state, otherClassName.className) - return ( + if ( - equal(properties, Object.keys(otherDecls)) && + equal(Object.keys(decls), Object.keys(otherDecls)) && !Array.isArray(meta) && !Array.isArray(otherMeta) && equal(meta.context, otherMeta.context) && equal(meta.pseudo, otherMeta.pseudo) - ) - }) import { isCssDoc } from '../../util/css' -import { State, Settings } from '../../util/state' -} from '../../util/find' +import { import { isCssDoc } from '../../util/css' import { isCssDoc } from '../../util/css' -import { State, Settings } from '../../util/state' -} from '../../util/find' +import { import { -} from '../../util/find' + state: State, findClassNamesInRange, -} from '../../util/find' + state: State, findClassListsInDocument, -} from '../../util/find' + state: State, getClassNamesInClassList, -} from '../../util/find' + state: State, findAll, -} from '../../util/find' + state: State, indexToPosition, -import { getClassNameMeta } from '../../util/getClassNameMeta' + document: TextDocument, -import { getClassNameMeta } from '../../util/getClassNameMeta' + document: TextDocument, import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver' -import { getClassNameMeta } from '../../util/getClassNameMeta' + document: TextDocument, import { State, Settings } from '../../util/state' -import { getClassNameMeta } from '../../util/getClassNameMeta' + document: TextDocument, import { isCssDoc } from '../../util/css' -import { getClassNameMeta } from '../../util/getClassNameMeta' + document: TextDocument, import { -import { getClassNameMeta } from '../../util/getClassNameMeta' + document: TextDocument, findClassNamesInRange, -import { getClassNameMeta } from '../../util/getClassNameMeta' + document: TextDocument, findClassListsInDocument, -import { getClassNameMeta } from '../../util/getClassNameMeta' + document: TextDocument, getClassNamesInClassList, -import { getClassNameMeta } from '../../util/getClassNameMeta' + document: TextDocument, findAll, -import { getClassNameMeta } from '../../util/getClassNameMeta' + document: TextDocument, indexToPosition, -import { getClassNameDecls } from '../../util/getClassNameDecls' + settings: Settings import { getClassNameDecls } from '../../util/getClassNameDecls' -import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver' + getClassNamesInClassList, - return { -import { getClassNameDecls } from '../../util/getClassNameDecls' import { isCssDoc } from '../../util/css' - location: { + findClassListsInDocument, import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver' - InvalidScreenDiagnostic, -import { getClassNameDecls } from '../../util/getClassNameDecls' +import { isCssDoc } from '../../util/css' findClassListsInDocument, -import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver' import { State, Settings } from '../../util/state' - getClassNamesInClassList, import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver' -import { State, Settings } from '../../util/state' findAll, import { TextDocument, DiagnosticSeverity, Range } from 'vscode-languageserver' - AugmentedDiagnostic, - ), }) }) }) diff --git a/src/lsp/providers/diagnostics/types.ts b/src/lsp/providers/diagnostics/types.ts index 00fc979386386abbad601bf15ba40c8be6cd12c0..684cda7c824aa7cc382c6ffed6b30010d31ddc97 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( diff --git a/src/lsp/util/joinWithAnd.ts b/src/lsp/util/joinWithAnd.ts deleted file mode 100644 index 2b2efb716afd1394a91dd44fc6f16c05d053b438..0000000000000000000000000000000000000000 --- a/src/lsp/util/joinWithAnd.ts +++ /dev/null @@ -1,11 +0,0 @@ -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}` - }, '') -} diff --git a/src/lsp/util/removeRangeFromString.ts b/src/lsp/util/removeRangeFromString.ts new file mode 100644 index 0000000000000000000000000000000000000000..7479373ced8326e6a6429b1c0642560a13fc076a --- /dev/null +++ b/src/lsp/util/removeRangeFromString.ts @@ -0,0 +1,16 @@ +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() +} diff --git a/src/lsp/util/removeRangesFromString.ts b/src/lsp/util/removeRangesFromString.ts deleted file mode 100644 index f97d62b95b2aecae61c0e4195fba475af541a17e..0000000000000000000000000000000000000000 --- a/src/lsp/util/removeRangesFromString.ts +++ /dev/null @@ -1,39 +0,0 @@ -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() -}