|
1 | 1 | import { State } from '../util/state'
|
2 |
| -import type { |
3 |
| - CodeActionParams, |
4 |
| - CodeAction, |
| 2 | +import { |
| 3 | + type CodeActionParams, CodeAction, |
| 4 | + CodeActionKind, |
| 5 | + Command, |
5 | 6 | } from 'vscode-languageserver'
|
6 | 7 | import { CssConflictDiagnostic, InvalidIdentifierDiagnostic } from '../diagnostics/types'
|
7 | 8 | import { joinWithAnd } from '../util/joinWithAnd'
|
8 | 9 | import { removeRangesFromString } from '../util/removeRangesFromString'
|
9 | 10 |
|
| 11 | + |
10 | 12 | export async function provideInvalidIdentifierCodeActions(
|
11 | 13 | _state: State,
|
12 | 14 | params: CodeActionParams,
|
13 | 15 | diagnostic: InvalidIdentifierDiagnostic
|
14 | 16 | ): Promise<CodeAction[]> {
|
15 |
| - if (!diagnostic.suggestion) return []; |
16 |
| - |
17 |
| - debugger; |
18 |
| - return [ |
19 |
| - { |
20 |
| - title: `Replace with '${diagnostic.suggestion}'`, |
21 |
| - kind: 'quickfix', // CodeActionKind.QuickFix, |
22 |
| - diagnostics: [diagnostic], |
23 |
| - edit: { |
24 |
| - changes: { |
25 |
| - [params.textDocument.uri]: [ |
26 |
| - { |
27 |
| - range: diagnostic.range, |
28 |
| - newText: diagnostic.suggestion, |
29 |
| - }, |
30 |
| - ], |
31 |
| - }, |
32 |
| - }, |
33 |
| - }, |
34 |
| - ] |
| 17 | + const actions: CodeAction[] = [{ |
| 18 | + title: `Ignore '${diagnostic.chunk}' in this workspace`, |
| 19 | + kind: CodeActionKind.QuickFix, |
| 20 | + diagnostics: [diagnostic], |
| 21 | + command: Command.create(`Ignore '${diagnostic.chunk}' in this workspace`, 'tailwindCSS.addWordToWorkspaceFileFromServer', diagnostic.chunk) |
| 22 | + }]; |
| 23 | + |
| 24 | + if (typeof diagnostic.suggestion == 'string') { |
| 25 | + actions.push({ |
| 26 | + title: `Replace with '${diagnostic.suggestion}'`, |
| 27 | + kind: CodeActionKind.QuickFix, |
| 28 | + diagnostics: [diagnostic], |
| 29 | + isPreferred: true, |
| 30 | + edit: { |
| 31 | + changes: { |
| 32 | + [params.textDocument.uri]: [ |
| 33 | + { |
| 34 | + range: diagnostic.range, |
| 35 | + newText: diagnostic.suggestion, |
| 36 | + }, |
| 37 | + ], |
| 38 | + }, |
| 39 | + }, |
| 40 | + }) |
| 41 | + } else { |
| 42 | + // unimplemented. |
| 43 | + } |
| 44 | + |
| 45 | + return actions; |
35 | 46 | }
|
0 commit comments