-
Notifications
You must be signed in to change notification settings - Fork 7
/
code_actions.go
58 lines (46 loc) · 1.74 KB
/
code_actions.go
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
46
47
48
49
50
51
52
53
54
55
56
57
58
package lsp
import (
"sort"
lsp "github.com/Azure/azapi-lsp/internal/protocol"
)
const (
// SourceFormatAllTerraform is a Terraform specific format code action.
SourceFormatAllTerraform = "source.formatAll.terraform"
)
type CodeActions map[lsp.CodeActionKind]bool
// `source.*`: Source code actions apply to the entire file. They must be explicitly
// requested and will not show in the normal lightbulb menu. Source actions
// can be run on save using editor.codeActionsOnSave and are also shown in
// the source context menu.
// For action definitions, refer to: https://code.visualstudio.com/api/references/vscode-api#CodeActionKind
// `source.fixAll`: Fix all actions automatically fix errors that have a clear fix that do
// not require user input. They should not suppress errors or perform unsafe
// fixes such as generating new types or classes.
// ** We don't support this as terraform fmt only adjusts style**
// lsp.SourceFixAll: true,
// `source.formatAll`: Generic format code action.
// We do not register this for terraform to allow fine grained selection of actions.
// A user should be able to set `source.formatAll` to true, and source.formatAll.terraform to false to allow all
// files to be formatted, but not terraform files (or vice versa).
var SupportedCodeActions = CodeActions{
SourceFormatAllTerraform: true,
}
func (c CodeActions) AsSlice() []lsp.CodeActionKind {
s := make([]lsp.CodeActionKind, 0)
for v := range c {
s = append(s, v)
}
sort.SliceStable(s, func(i, j int) bool {
return string(s[i]) < string(s[j])
})
return s
}
func (ca CodeActions) Only(only []lsp.CodeActionKind) CodeActions {
wanted := make(CodeActions)
for _, kind := range only {
if v, ok := ca[kind]; ok {
wanted[kind] = v
}
}
return wanted
}