File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ import {
2
+ CodeAction ,
3
+ CodeActionParams ,
4
+ CodeActionKind ,
5
+ } from 'vscode-languageserver'
6
+ import { State } from '../util/state'
7
+ import { findLast } from '../util/find'
8
+
9
+ export function provideCodeActions (
10
+ _state : State ,
11
+ params : CodeActionParams
12
+ ) : CodeAction [ ] {
13
+ if ( params . context . diagnostics . length === 0 ) {
14
+ return null
15
+ }
16
+
17
+ return params . context . diagnostics
18
+ . map ( ( diagnostic ) => {
19
+ let match = findLast (
20
+ / D i d y o u m e a n (?: s o m e t h i n g l i k e ) ? ' (?< replacement > [ ^ ' ] + ) ' \? $ / g,
21
+ diagnostic . message
22
+ )
23
+
24
+ if ( ! match ) {
25
+ return null
26
+ }
27
+
28
+ return {
29
+ title : `Replace with '${ match . groups . replacement } '` ,
30
+ kind : CodeActionKind . QuickFix ,
31
+ diagnostics : [ diagnostic ] ,
32
+ edit : {
33
+ changes : {
34
+ [ params . textDocument . uri ] : [
35
+ {
36
+ range : diagnostic . range ,
37
+ newText : match . groups . replacement ,
38
+ } ,
39
+ ] ,
40
+ } ,
41
+ } ,
42
+ }
43
+ } )
44
+ . filter ( Boolean )
45
+ }
Original file line number Diff line number Diff line change @@ -16,6 +16,8 @@ import {
16
16
Hover ,
17
17
TextDocumentPositionParams ,
18
18
DidChangeConfigurationNotification ,
19
+ CodeActionParams ,
20
+ CodeAction ,
19
21
} from 'vscode-languageserver'
20
22
import getTailwindState from '../class-names/index'
21
23
import { State , Settings , EditorState } from './util/state'
@@ -32,6 +34,7 @@ import {
32
34
clearAllDiagnostics ,
33
35
} from './providers/diagnosticsProvider'
34
36
import { createEmitter } from '../lib/emitter'
37
+ import { provideCodeActions } from './providers/codeActionProvider'
35
38
36
39
let connection = createConnection ( ProposedFeatures . all )
37
40
let state : State = { enabled : false , emitter : createEmitter ( connection ) }
@@ -171,6 +174,7 @@ connection.onInitialize(
171
174
] ,
172
175
} ,
173
176
hoverProvider : true ,
177
+ codeActionProvider : true ,
174
178
} ,
175
179
}
176
180
}
@@ -226,4 +230,9 @@ connection.onHover(
226
230
}
227
231
)
228
232
233
+ connection . onCodeAction ( ( params : CodeActionParams ) : CodeAction [ ] => {
234
+ if ( ! state . enabled ) return null
235
+ return provideCodeActions ( state , params )
236
+ } )
237
+
229
238
connection . listen ( )
You can’t perform that action at this time.
0 commit comments