Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: Would it be possible to run gopls.run_test command in json mode? #49464

Closed
tjdevries opened this issue Nov 8, 2021 · 4 comments
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. help wanted Tools This label describes issues relating to any tools in the x/tools repository.

Comments

@tjdevries
Copy link

tjdevries commented Nov 8, 2021

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

$ go version
go 1.17.1 linux/amd64

Does this issue reproduce with the latest release?

Yes, but it's more of a feature request (I can put this somewhere else if that's what is desired)

Feature Request?

Currently, the gopls.run_test works really great for viewing the test results! I love it. I was hoping it could be possible though to get the JSON results back to programmatically do something if there is a test failure.

An additional argument to run_tests of JSON would be appreciated. I understand if it's too odd of a request though.

Thanks!

@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Nov 8, 2021
@gopherbot gopherbot added this to the Unreleased milestone Nov 8, 2021
@hyangah hyangah modified the milestones: Unreleased, gopls/unplanned Nov 10, 2021
@gopherbot
Copy link

gopherbot commented Aug 26, 2022

Change https://go.dev/cl/425954 mentions this issue: gopls: Add a parameter to gopls.run_tests for emitting results back as JSON.

@jadekler
Copy link
Member

jadekler commented Aug 26, 2022

I'm taking a stab at this.

https://go-review.git.corp.google.com/c/tools/+/425954 is one quick hot take, using the easiest approach of just passing JSON to protocol.ClientCloser, rather than trying to do something more sweeping. The output is on window/showMessage and looks like this:

window/showMessage. params: {Type:3 Message:{"tests":{"ran":3,"passed":["TestYyy"],"failed":["TestXxx","TestZzz"]},"benchmarks":{"ran":0,"passed":["TestYyy"],"failed":null}}}

The structure is:

type Result struct {
    NumRan int      `json:"ran"`
    Passed []string `json:"passed"`
    Failed []string `json:"failed"`
}
type AllResults struct {
    Tests      *Result `json:"tests"`
    Benchmarks *Result `json:"benchmarks"`
}

@tjdevries is this kind of what you were looking for? Or, are you looking for something different? If so, maybe could you sketch out a "here's what I have in non-JSON form, where's how I would like to see it in JSON" to make the conversation a bit more concrete?


I came up with https://github.com/jadekler/lsprobe as a way to integration test a client and (gopls) server.

@jadekler
Copy link
Member

jadekler commented Sep 23, 2022

Since this has been sitting for a bit now, I'll close the issue. We can circle back around if there's more discussion to be had later! =)

@findleyr
Copy link
Contributor

findleyr commented Sep 25, 2022

Thanks @jadekler for looking into this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest gopls Issues related to the Go language server, gopls. help wanted Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

5 participants