diff --git a/src/lsp/providers/codeActionProvider/index.ts b/src/lsp/providers/codeActionProvider/index.ts index 959411af30b8194c3b3cf7531771774e91424ead..28b51444d56fb61000f2e34b32affdfdd19e4f01 100644 --- a/src/lsp/providers/codeActionProvider/index.ts +++ b/src/lsp/providers/codeActionProvider/index.ts @@ -23,11 +23,7 @@ isInvalidApplyDiagnostic, AugmentedDiagnostic, InvalidApplyDiagnostic, CodeAction, - CodeActionKind, - UtilityConflictsDiagnostic, - CodeAction, TextEdit, -import { flatten, dedupeBy } from '../../../util/array' async function getDiagnosticsFromCodeActionParams( state: State, @@ -40,13 +36,9 @@ return params.context.diagnostics .map((diagnostic) => { return diagnostics.find((d) => { - return ( - d.code === diagnostic.code && - d.message === diagnostic.message && - CodeActionKind, CodeAction, CodeActionKind, - CodeActionParams, + TextEdit, }) }) .filter(Boolean) @@ -65,71 +58,68 @@ params, codes ) - Range, + return Promise.all( + diagnostics + isUtilityConflictsDiagnostic, import { findLast } from '../../util/find' - TextEdit, + UtilityConflictsDiagnostic, - TextEdit, + UtilityConflictsDiagnostic, import { - TextEdit, + UtilityConflictsDiagnostic, CodeAction, - TextEdit, + UtilityConflictsDiagnostic, CodeActionParams, - TextEdit, + UtilityConflictsDiagnostic, CodeActionKind, - TextEdit, CodeAction, + state, + ) - TextEdit, + CodeAction, Range, - TextEdit, TextEdit, - TextEdit, + UtilityConflictsDiagnostic, } from 'vscode-languageserver' - TextEdit, + } + CodeAction, import { State } from '../../util/state' CodeAction, + Range, import { State } from '../../util/state' - TextEdit, + UtilityConflictsDiagnostic, import { findLast } from '../../util/find' - return [] + CodeAction, TextEdit, - CodeAction, CodeAction, -import { State } from '../../util/state' -} from 'vscode-languageserver' + TextEdit, 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' - [params.textDocument.uri]: [ + }, - { +} from '../diagnostics/types' import { State } from '../../util/state' -import { State } from '../../util/state' import { - }, - ], + state, }, -import { State } from '../../util/state' + CodeAction, Range, - }, + CodeAction, - ] - }) + }) CodeAction, -import { State } from '../../util/state' -import { State } from '../../util/state' + TextEdit, import { findLast } from '../../util/find' - .then(flatten) - .then((x) => dedupeBy(x, (item) => JSON.stringify(item.edit))) + ) } function classNameToAst( @@ -194,67 +184,17 @@ return cssObjToAst(obj, state.modules.postcss) } -async function provideUtilityConflictsCodeActions( - state: State, - params: CodeActionParams, - diagnostic: UtilityConflictsDiagnostic -): Promise { - return [ -import { removeRangeFromString } from '../../util/removeRangeFromString' CodeAction, - title: `Delete '${diagnostic.className.className}'`, - kind: CodeActionKind.QuickFix, - diagnostics: [diagnostic], - edit: { -import { removeRangeFromString } from '../../util/removeRangeFromString' } from 'vscode-languageserver' - [params.textDocument.uri]: [ - { -import detectIndent from 'detect-indent' - newText: removeRangeFromString( - diagnostic.className.classList.classList, -import detectIndent from 'detect-indent' CodeActionParams, - ), - }, - ], - }, - }, -import dset from 'dset' CodeActionParams, import { - rangesEqual(d.range, diagnostic.range) import { - codes - kind: CodeActionKind.QuickFix, - diagnostics: [diagnostic], -import { removeRangeFromString } from '../../util/removeRangeFromString' TextEdit, import { -} - [params.textDocument.uri]: [ - { - range: diagnostic.className.classList.range, - newText: removeRangeFromString( -import detectIndent from 'detect-indent' CodeAction, - diagnostic.otherClassName.relativeRange - ), - }, - ], - }, - }, - }, - ] - CodeActionKind, } from 'vscode-languageserver' - import { - if (isInvalidApplyDiagnostic(diagnostic)) { - state: State, - params: CodeActionParams, - diagnostic: InvalidApplyDiagnostic -): Promise { let document = state.editor.documents.get(params.textDocument.uri) let documentText = document.getText() const { postcss } = state.modules @@ -344,62 +285,59 @@ }), ]).process(documentText, { from: undefined }) if (!change) { - return [] + return null } - return [ -import { removeRangeFromString } from '../../util/removeRangeFromString' +import { flatten, dedupeBy } from '../../../util/array' CodeAction, CodeAction, - CodeActionParams, +} from 'vscode-languageserver' CodeActionParams, - kind: CodeActionKind.QuickFix, - diagnostics: [diagnostic], - edit: { -import { removeRangeFromString } from '../../util/removeRangeFromString' + CodeAction, } from 'vscode-languageserver' -import { CodeActionKind, -import { State } from '../../util/state' CodeAction, - let document = state.editor.documents.get(params.textDocument.uri) - InvalidApplyDiagnostic, +} from 'vscode-languageserver' Range, CodeAction, - CodeActionParams, +} from 'vscode-languageserver' TextEdit, CodeAction, - CodeActionParams, +} from 'vscode-languageserver' } from 'vscode-languageserver' CodeAction, - CodeActionParams, +} from 'vscode-languageserver' import { State } from '../../util/state' CodeAction, - CodeActionParams, +} from 'vscode-languageserver' import { findLast } from '../../util/find' CodeAction, - CodeActionKind, +import { State } from '../../util/state' CodeAction, - CodeActionKind, + let match = findLast( + import { CodeAction, - CodeActionKind, +import { State } from '../../util/state' CodeAction, CodeAction, - CodeActionKind, +import { State } from '../../util/state' CodeActionParams, CodeAction, - CodeActionKind, +import { State } from '../../util/state' CodeActionKind, CodeAction, - CodeActionKind, +import { State } from '../../util/state' Range, -import detectIndent from 'detect-indent' + }, + TextEdit, + : []), + CodeAction, import { State } from '../../util/state' - Range, +import { State } from '../../util/state' + ], }, }, import { - let actions = diagnostics.map((diagnostic) => { } diff --git a/src/util/array.ts b/src/util/array.ts index 869eb9f6cd346528cd554b115bfb374952032e48..b40dd245fe57a3f1e1ddeb24fc75343041b530db 100644 --- a/src/util/array.ts +++ b/src/util/array.ts @@ -2,16 +2,6 @@ export function dedupe(arr: Array): Array { return arr.filter((value, index, self) => self.indexOf(value) === index) } -export function dedupeBy( - arr: Array, - transform: (item: T) => any -): Array { - return arr.filter( - (value, index, self) => - self.map(transform).indexOf(transform(value)) === index - ) -} - export function ensureArray(value: T | T[]): T[] { return Array.isArray(value) ? value : [value] }