Skip to content

x/tools/gopls: add support for provided WorkDoneToken in ExecuteCommand #40527

Closed
@leitzler

Description

@leitzler

What version of Go are you using (go version)?

$ go version
-
x/tools@644d4167

What did you do?

Called ExecuteCommand with a provided WorkDoneToken:

&protocol.ExecuteCommandParams{
     Command:   "generate",
     Arguments: {
         {0x22, 0x66, 0x69, 0x6c, 0x65, 0x3a, 0x2f, 0x2f, 0x2f, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x72, 0x2f, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72, 0x73, 0x2f, 0x78, 0x6d, 0x2f, 0x6c, 0x73, 0x32, 0x30, 0x38, 0x78, 0x64, 0x31, 0x37, 0x34, 0x76, 0x39, 0x35, 0x70, 0x67, 0x64, 0x32, 0x30, 0x72, 0x6e, 0x5f, 0x71, 0x62, 0x68, 0x30, 0x30, 0x30, 0x30, 0x67, 0x6e, 0x2f, 0x54, 0x2f, 0x74, 0x6d, 0x70, 0x2e, 0x5a, 0x53, 0x69, 0x38, 0x48, 0x67, 0x49, 0x47, 0x22},
         {0x66, 0x61, 0x6c, 0x73, 0x65},
     },
     WorkDoneProgressParams: protocol.WorkDoneProgressParams{
         WorkDoneToken: int(1001),
     },
}

When gopls starts to execute go generate, it sends a ShowMessageRequest to the client so the client can present a dialog to the user. That dialog includes an action, Cancel, to let the user cancel go generate before it's done.

Using a WorkDoneToken in the ExecuteCommand request is the only way I found to tie the dialog to a specific execution. If it can't be tied to that specific execution there is no way to know when the dialog should be automatically closed (i.e. when go generate is done and Cancel isn't a valid action anymore).

What did you expect to see?

The WorkDoneToken used during progress reporting.

What did you see instead?

A new token created for me:

WorkDoneProgressCreate callback: &protocol.WorkDoneProgressCreateParams{
    Token: "8674665223082153551",
}

That is used to report progress:

Progress callback: &protocol.ProgressParams{
    Token: "8674665223082153551",
    Value: map[string]interface {}{
        "cancellable": bool(true),
        "kind":        "begin",
        "message":     "running go generate",
        "title":       "generate",
    },
}
Progress callback: &protocol.ProgressParams{
    Token: "8674665223082153551",
    Value: map[string]interface {}{
        "cancellable": bool(true),
        "kind":        "report",
        "message":     "sleep 10\n",
    },
}
Progress callback: &protocol.ProgressParams{
    Token: "8674665223082153551",
    Value: map[string]interface {}{
        "kind":    "end",
        "message": "finished",
    },
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions