1
0
mirror of https://github.com/golang/go synced 2024-11-18 13:14:47 -07:00
go/internal/lsp/helper
Daisuke Suzuki 5dffee2a89 internal/lsp: change to helper.go to output a formatted file
Use format.Source before output.

Change-Id: I8504fc80defa77aeaab748b9dc65d6382da500a3
Reviewed-on: https://go-review.googlesource.com/c/tools/+/217177
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-01-31 20:35:38 +00:00
..
helper.go internal/lsp: change to helper.go to output a formatted file 2020-01-31 20:35:38 +00:00
README.md internal/lsp: fix typo 2020-01-31 14:37:46 +00:00

Generate server_gen.go

helper generates boilerplate code for server.go by processing the generated code in protocol/tsserver.go.

First, build helper in this directory (go build .).

In directory lsp, executing go generate server.go generates the stylized file server_gen.go that contains stubs for type Server.

It decides what stubs are needed and their signatures by looking at the Server interface (-t flag). These all look somewhat like Resolve(context.Context, *CompletionItem) (*CompletionItem, error).

It then parses the lsp directory (-u flag) to see if there is a corresponding implementation function (which in this case would be named resolve). If so it discovers the parameter names needed, and generates (in server_gen.go) code like

func (s *Server) resolve(ctx context.Context, params *protocol.CompletionItem) (*protocol.CompletionItem, error) {
    return s.resolve(ctx, params)
}

If resolve is not defined (and it is not), then the body of the generated function is

    return nil, notImplemented("resolve")

So to add a capability currently not implemented, just define it somewhere in lsp. In this case, just define func (s *Server) resolve(...) and re-generate server_gen.go.