1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
import {
CodeAction,
CodeActionParams,
CodeActionKind,
} from 'vscode-languageserver'
import { State } from '../util/state'
import { findLast } from '../util/find'
export function provideCodeActions(
_state: State,
params: CodeActionParams
): CodeAction[] {
if (params.context.diagnostics.length === 0) {
return null
}
return params.context.diagnostics
.map((diagnostic) => {
let match = findLast(
/ Did you mean (?:something like )?'(?<replacement>[^']+)'\?$/g,
diagnostic.message
)
if (!match) {
return null
}
return {
title: `Replace with '${match.groups.replacement}'`,
kind: CodeActionKind.QuickFix,
diagnostics: [diagnostic],
edit: {
changes: {
[params.textDocument.uri]: [
{
range: diagnostic.range,
newText: match.groups.replacement,
},
],
},
},
}
})
.filter(Boolean)
}
|