Skip to content

Commit

Permalink
quickfix: fixes organize imports
Browse files Browse the repository at this point in the history
fixes CompatibleCodeActions to recognize codeActionKinds

the type switch would not trigger the case protocol.CodeActionOptions
when using the latest gopls version.

this quickfix uses a map[string]interface{} to get around that
but it probably should be fixed in the protocol package.

gopls version
golang.org/x/tools/gopls v0.14.0
    golang.org/x/tools/gopls@v0.14.0
    h1:SaFctK7aL3S21p7r/K4+XU+mEyjobk7rIe9B+KiER5s=
go version go1.21.3 linux/amd64
  • Loading branch information
kmx1 committed Oct 26, 2023
1 parent c6ffdf3 commit dea92a6
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions internal/lsp/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,38 @@ func CompatibleCodeActions(cap *protocol.ServerCapabilities, kinds []protocol.Co
}
return nil
case protocol.CodeActionOptions:
return matchCompats(kinds, ap.CodeActionKinds)
case map[string]interface{}:
compatI := ap["codeActionKinds"].([]interface{})
var compat []protocol.CodeActionKind
for _, k := range kinds {
found := false
for _, kk := range ap.CodeActionKinds {
if k == kk {
found = true
break
}
}
if found {
compat = append(compat, k)
} else {
log.Printf("code action %v is not compatible with server", k)
}
for _, c := range compatI {
cStr := c.(string)
compat = append(compat, protocol.CodeActionKind(cStr))
}
return compat
return matchCompats(kinds, compat)
}
return nil
}

func matchCompats(kinds []protocol.CodeActionKind, compats []protocol.CodeActionKind) []protocol.CodeActionKind {
var compat []protocol.CodeActionKind
for _, k := range kinds {
found := false
for _, kk := range compats {
if k == kk {
found = true
break
}
}
if found {
compat = append(compat, k)
} else {
log.Printf("code action %v is not compatible with server", k)
}
}
return compat
}

func LocationLink(l *protocol.Location) string {
p := text.ToPath(l.URI)
return fmt.Sprintf("%s:%v:%v-%v:%v", p,
Expand Down

0 comments on commit dea92a6

Please sign in to comment.