-
Notifications
You must be signed in to change notification settings - Fork 138
/
Copy pathcode_actions.go
52 lines (42 loc) · 1.03 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
package lsp
import (
"sort"
lsp "github.com/hashicorp/terraform-ls/internal/protocol"
)
const (
SourceFormatAll = "source.formatAll"
SourceFormatAllTerraformLs = "source.formatAll.terraform-ls"
)
type CodeActions map[lsp.CodeActionKind]bool
var (
SupportedCodeActions = CodeActions{
lsp.Source: true,
lsp.SourceFixAll: true,
SourceFormatAll: true,
SourceFormatAllTerraformLs: 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 {
// if only is empty, assume that the client wants all code actions
// else build mapping of requested and determine if supported
if len(only) == 0 {
return ca
}
wanted := make(CodeActions, 0)
for _, kind := range only {
if v, ok := ca[kind]; ok {
wanted[kind] = v
}
}
return wanted
}