mirror of
https://github.com/golang/go
synced 2024-11-18 20:14:43 -07:00
internal/lsp: make sure CodeAction.Command is a pointer
This is causing the "command '' not found" errors that we've been seeing, specifically reported in microsoft/vscode-go#2920. Also, fixed an issue with import organization in single-line files that was caught as a result of this. Change-Id: I2dfedb5d1b8dda976f356b0d6fcd146e53f1a650 Reviewed-on: https://go-review.googlesource.com/c/tools/+/209219 Run-TryBot: Rebecca Stambler <rstambler@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
c1736c0f0a
commit
ecd32218bd
@ -79,12 +79,28 @@ func TestCapabilities(t *testing.T) {
|
||||
ContentChanges: []protocol.TextDocumentContentChangeEvent{
|
||||
{
|
||||
Range: nil,
|
||||
Text: `package main; func main() {}; func main2() {};`,
|
||||
Text: `package main; func main() { fmt.Println("") }`,
|
||||
},
|
||||
},
|
||||
}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Send a code action request to validate expected types.
|
||||
actions, err := c.Server.CodeAction(ctx, &protocol.CodeActionParams{
|
||||
TextDocument: protocol.TextDocumentIdentifier{
|
||||
URI: uri,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, action := range actions {
|
||||
// Validate that an empty command is sent along with import organization responses.
|
||||
if action.Kind == protocol.SourceOrganizeImports && action.Command != nil {
|
||||
t.Errorf("unexpected command for import organization")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func validateCapabilities(result *protocol.InitializeResult) error {
|
||||
|
@ -62,7 +62,7 @@ func (s *Server) codeAction(ctx context.Context, params *protocol.CodeActionPara
|
||||
codeActions = append(codeActions, protocol.CodeAction{
|
||||
Title: "Tidy",
|
||||
Kind: protocol.SourceOrganizeImports,
|
||||
Command: protocol.Command{
|
||||
Command: &protocol.Command{
|
||||
Title: "Tidy",
|
||||
Command: "tidy",
|
||||
Arguments: []interface{}{
|
||||
|
@ -126,7 +126,7 @@ type CodeAction struct {
|
||||
* provides a edit and a command, first the edit is
|
||||
* executed and then the command.
|
||||
*/
|
||||
Command Command `json:"command,omitempty"`
|
||||
Command *Command `json:"command,omitempty"`
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -315,7 +315,9 @@ func trimToFirstNonImport(fset *token.FileSet, f *ast.File, src []byte, err erro
|
||||
}
|
||||
end := f.End()
|
||||
if firstDecl != nil {
|
||||
end = tok.LineStart(fset.Position(firstDecl.Pos()).Line - 1)
|
||||
if firstDeclLine := fset.Position(firstDecl.Pos()).Line; firstDeclLine > 1 {
|
||||
end = tok.LineStart(firstDeclLine - 1)
|
||||
}
|
||||
}
|
||||
// Any errors in the file must be after the part of the file that we care about.
|
||||
switch err := err.(type) {
|
||||
|
Loading…
Reference in New Issue
Block a user