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: improve internal/lsp/cmd package #38085

Closed
stamblerre opened this issue Mar 26, 2020 · 6 comments
Closed

x/tools/gopls: improve internal/lsp/cmd package #38085

stamblerre opened this issue Mar 26, 2020 · 6 comments
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.

Comments

@stamblerre
Copy link
Contributor

I am really struggling to do code reviews for the cmd package. The logical flow is hard to reason about, and the way to set options, etc. is not obvious. We should spend some time restructuring it to be more clear.

@findleyr, @heschik: If any suggestions/ideas immediately come to mind, please let me know.

@stamblerre stamblerre added this to the gopls/v0.5.0 milestone Mar 26, 2020
@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 Mar 26, 2020
@findleyr
Copy link
Contributor

Agree that it is hard to follow. I spent a long time staring at it for https://golang.org/cl/215742 -- and that CL simplified some things but made others more complicated. Also, feel free to send those reviews my way...

Can we list what we'd want to change? Off the top of my head, the following things are complex or confusing:

  1. the fact that commands interact with an in-process LSP server, and therefore have to translate async LSP into a synchronous command
  2. handling of the LSP connection: each subcommand connects and terminates the connection itself, duplicating logic and tightly coupling to the connection
  3. the internal@ hack/optimization for cmdtests
  4. special handling to default to the serve subcommand
  5. sharding of flags across the application and the subcommand
  6. handling of files, and translating to and from LSP file coordinates / URIs

Anything else come to mind?

Some of these probably can't/shouldn't be fixed, for example I think executing commands over LSP is The Right Thing To Do. Also, it's probably too late to stop defaulting to the serve subcommand (or is it?!).

As a starting point, I think we can improve (2) and (3): it would help to lift handling of the cmdClient / jsonrpc2.Conn out of .Run and up to the application layer, instead injecting in the connection to the subcommand. That might also simplify the internal@ optimization. I can take a stab at this.

Another straightforward improvement is just to add a bunch more documentation around the tricky parts.

WDYT?

@stamblerre
Copy link
Contributor Author

Some of these probably can't/shouldn't be fixed, for example I think executing commands over LSP is The Right Thing To Do. Also, it's probably too late to stop defaulting to the serve subcommand (or is it?!).

Yes, I think is too late for that.

As a starting point, I think we can improve (2) and (3): it would help to lift handling of the cmdClient / jsonrpc2.Conn out of .Run and up to the application layer, instead injecting in the connection to the subcommand. That might also simplify the internal@ optimization. I can take a stab at this.

Agree with this plan - for me (3) is the hardest to reason about. Thanks!

Another straightforward improvement is just to add a bunch more documentation around the tricky parts.

Definitely. Even just writing down how the tests work would help immensely.

Another point of confusion to add to the list - we originally had a gopls query command for which the feature commands would be subcommands. Somehow this got lost along the way, but definition is still invoked as gopls query definition. We should make this consistent in one way or another. Maybe @ianthehat can shed light on what the benefits of query would have been?

@findleyr
Copy link
Contributor

Oh, another that occurred to me (perhaps that can't be fixed) is the fact that options is a func(*source.Options). That frequently confuses me -- especially since source.Options is huge.

@findleyr
Copy link
Contributor

Agree with this plan - for me (3) is the hardest to reason about. Thanks!

Do you think it's reasonable to expect that workspace initialization will ever be cacheable enough to delete the internal hack altogether? In other words, for cmdtests we initialize a gopls remote and just connect each cmd to a new session on the remote? That would be the ideal solution (and also would be an optimization for real-world usage of commands).

@ianthehat
Copy link

I think the actual command line needs some thought.

  • I do not think it is too late to change it at all, but once we go beta it might be.
  • We should not default to the serve command
  • We should put some effort into separating automation verbs (and their flags) from user verbs. The former we should promise backwards compatibility but not worry about ugliness, the latter we should be happy to change/break for the benefit of clarity at any time.

I agree the internal hack should be vaporized, it ought to be possible (but maybe with a different cleaner hack added to the client server behavior)

@stamblerre stamblerre modified the milestones: gopls/v0.5.0, gopls/v0.6.0 Apr 2, 2020
@stamblerre stamblerre modified the milestones: gopls/v0.6.0, gopls/v0.5.0 Jun 26, 2020
@stamblerre stamblerre modified the milestones: gopls/v0.5.0, gopls/v1.0.0 Jul 22, 2020
@stamblerre stamblerre removed this from the gopls/v1.0.0 milestone Sep 9, 2020
@stamblerre stamblerre added this to the gopls/unplanned milestone Oct 21, 2020
@findleyr
Copy link
Contributor

Closing this issue as no longer actionable. The command package has changed a bit, and while it's still not as clear as it could be, this issue does not track work that we plan to do.

@findleyr findleyr closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants