From 1a0c6081c56a37d2e11f78315a6a63af8bd9b51b Mon Sep 17 00:00:00 2001 From: Peter Weinbergr Date: Fri, 16 Apr 2021 11:05:54 -0400 Subject: [PATCH] internal/lsp/protocol/typescript: update documentation and generated code Modifies README.md to be clearer about the necessary version of the typescript compiler. Adds generated code that allows unmarshalling type errors on Initialize messages. See https://go-review.googlesource.com/c/tools/+/310109 Fixes golang/go#35316 Change-Id: Id128c23e807e67e02d1354edaa0b164c9d36101c Reviewed-on: https://go-review.googlesource.com/c/tools/+/310753 Trust: Peter Weinberger Trust: Rebecca Stambler Reviewed-by: Rebecca Stambler --- internal/lsp/protocol/tsclient.go | 2 +- internal/lsp/protocol/tsprotocol.go | 25 +--------------------- internal/lsp/protocol/tsserver.go | 12 ++++++----- internal/lsp/protocol/typescript/README.md | 7 +++--- internal/lsp/protocol/typescript/code.ts | 14 ++++++++++-- 5 files changed, 25 insertions(+), 35 deletions(-) diff --git a/internal/lsp/protocol/tsclient.go b/internal/lsp/protocol/tsclient.go index 0287acab4..34d698ffd 100644 --- a/internal/lsp/protocol/tsclient.go +++ b/internal/lsp/protocol/tsclient.go @@ -7,7 +7,7 @@ package protocol // Package protocol contains data types and code for LSP jsonrpcs // generated automatically from vscode-languageserver-node // commit: dae62de921d25964e8732411ca09e532dde992f5 -// last fetched Thu Feb 04 2021 11:11:02 GMT-0500 (Eastern Standard Time) +// last fetched Fri Apr 16 2021 08:46:13 GMT-0400 (Eastern Daylight Time) // Code generated (see typescript/README.md) DO NOT EDIT. diff --git a/internal/lsp/protocol/tsprotocol.go b/internal/lsp/protocol/tsprotocol.go index 0a2590b29..f1c2c1672 100644 --- a/internal/lsp/protocol/tsprotocol.go +++ b/internal/lsp/protocol/tsprotocol.go @@ -5,7 +5,7 @@ // Package protocol contains data types and code for LSP jsonrpcs // generated automatically from vscode-languageserver-node // commit: dae62de921d25964e8732411ca09e532dde992f5 -// last fetched Thu Feb 04 2021 11:11:02 GMT-0500 (Eastern Standard Time) +// last fetched Fri Apr 16 2021 08:46:13 GMT-0400 (Eastern Daylight Time) package protocol // Code generated (see typescript/README.md) DO NOT EDIT. @@ -4288,29 +4288,6 @@ type WillSaveTextDocumentParams struct { Reason TextDocumentSaveReason `json:"reason"` } -type WindowClientCapabilities struct { - /** - * Whether client supports handling progress notifications. If set - * servers are allowed to report in `workDoneProgress` property in the - * request specific server capabilities. - * - * @since 3.15.0 - */ - WorkDoneProgress bool `json:"workDoneProgress,omitempty"` - /** - * Capabilities specific to the showMessage request. - * - * @since 3.16.0 - */ - ShowMessage ShowMessageRequestClientCapabilities `json:"showMessage,omitempty"` - /** - * Capabilities specific to the showDocument request. - * - * @since 3.16.0 - */ - ShowDocument ShowDocumentClientCapabilities `json:"showDocument,omitempty"` -} - type WorkDoneProgressBegin struct { Kind string `json:"kind"` /** diff --git a/internal/lsp/protocol/tsserver.go b/internal/lsp/protocol/tsserver.go index c93c8efd0..2a572f476 100644 --- a/internal/lsp/protocol/tsserver.go +++ b/internal/lsp/protocol/tsserver.go @@ -7,7 +7,7 @@ package protocol // Package protocol contains data types and code for LSP jsonrpcs // generated automatically from vscode-languageserver-node // commit: dae62de921d25964e8732411ca09e532dde992f5 -// last fetched Thu Feb 04 2021 11:11:02 GMT-0500 (Eastern Standard Time) +// last fetched Fri Apr 16 2021 08:46:13 GMT-0400 (Eastern Daylight Time) // Code generated (see typescript/README.md) DO NOT EDIT. @@ -47,7 +47,7 @@ type Server interface { IncomingCalls(context.Context, *CallHierarchyIncomingCallsParams) ([]CallHierarchyIncomingCall /*CallHierarchyIncomingCall[] | null*/, error) OutgoingCalls(context.Context, *CallHierarchyOutgoingCallsParams) ([]CallHierarchyOutgoingCall /*CallHierarchyOutgoingCall[] | null*/, error) SemanticTokensFull(context.Context, *SemanticTokensParams) (*SemanticTokens /*SemanticTokens | null*/, error) - SemanticTokensFullDelta(context.Context, *SemanticTokensDeltaParams) (interface{} /* SemanticTokens | SemanticTokensDelta | nil*/, error) + SemanticTokensFullDelta(context.Context, *SemanticTokensDeltaParams) (interface{} /* SemanticTokens | SemanticTokensDelta | float64*/, error) SemanticTokensRange(context.Context, *SemanticTokensRangeParams) (*SemanticTokens /*SemanticTokens | null*/, error) SemanticTokensRefresh(context.Context) error ShowDocument(context.Context, *ShowDocumentParams) (*ShowDocumentResult, error) @@ -336,7 +336,9 @@ func serverDispatch(ctx context.Context, server Server, reply jsonrpc2.Replier, case "initialize": // req var params ParamInitialize if err := json.Unmarshal(r.Params(), ¶ms); err != nil { - return true, sendParseError(ctx, reply, err) + if _, ok := err.(*json.UnmarshalTypeError); !ok { + return true, sendParseError(ctx, reply, err) + } } resp, err := server.Initialize(ctx, ¶ms) return true, reply(ctx, resp, err) @@ -663,8 +665,8 @@ func (s *serverDispatcher) SemanticTokensFull(ctx context.Context, params *Seman return result, nil } -func (s *serverDispatcher) SemanticTokensFullDelta(ctx context.Context, params *SemanticTokensDeltaParams) (interface{} /* SemanticTokens | SemanticTokensDelta | nil*/, error) { - var result interface{} /* SemanticTokens | SemanticTokensDelta | nil*/ +func (s *serverDispatcher) SemanticTokensFullDelta(ctx context.Context, params *SemanticTokensDeltaParams) (interface{} /* SemanticTokens | SemanticTokensDelta | float64*/, error) { + var result interface{} /* SemanticTokens | SemanticTokensDelta | float64*/ if err := Call(ctx, s.Conn, "textDocument/semanticTokens/full/delta", params, &result); err != nil { return nil, err } diff --git a/internal/lsp/protocol/typescript/README.md b/internal/lsp/protocol/typescript/README.md index bf6dc8d6f..61ba187c6 100644 --- a/internal/lsp/protocol/typescript/README.md +++ b/internal/lsp/protocol/typescript/README.md @@ -3,14 +3,15 @@ ## Setup Make sure `node` and `tsc` are installed and in your PATH. There are detailed instructions below. +(`tsc -v` should be at least `4.2.4`.) Get the typescript code for the jsonrpc protocol with `git clone git@github.com:microsoft vscode-languageserver-node.git` or `git clone https://github.com/microsoft/vscode-languageserver-node.git` -`util.ts`` expects it to be in your HOME directory +`util.ts` expects it to be in your HOME directory -If you want to reproduce the existing files you need to be on a branch with the same git hash, for instance, `git checkout 7b90c29` +If you want to reproduce the existing files you need to be on a branch with the same git hash that `util.ts` expects, for instance, `git checkout 7b90c29` ## Usage @@ -50,5 +51,5 @@ the generated files and stored in the variable `gitHash` in `go.ts`. It is check 1. This will likely give warning messages that indicate you've failed to set up a project. Ignore them. 2. Your home directory will now have new directories `.npm` and `node_modules` (and a `package_lock.json` file) 3. The typescript executable `tsc` will be in `node_modules/.bin`, so put that directory in your path. - 4. `tsc -v` should print "Version 3.7.2" (or later). If not you may (as I did) have an obsolete tsc earlier in your path. + 4. `tsc -v` should print "Version 4.2.4" (or later). If not you may (as I did) have an obsolete tsc earlier in your path. 6. `npm install @types/node` (Without this there will be many incomprehensible typescript error messages.) diff --git a/internal/lsp/protocol/typescript/code.ts b/internal/lsp/protocol/typescript/code.ts index dc5d266fe..b63050bc5 100644 --- a/internal/lsp/protocol/typescript/code.ts +++ b/internal/lsp/protocol/typescript/code.ts @@ -916,18 +916,20 @@ function goUnionType(n: ts.UnionTypeNode, nm: string): string { if (nm == 'textDocument/documentSymbol') { return `[]interface{} ${help}`; } - if (aa == 'TypeReference' && bb == 'ArrayType' && cc == 'NullKeyword') { + if (aa == 'TypeReference' && bb == 'ArrayType' && (cc == 'NullKeyword' || cc === 'LiteralType')) { return `${goType(n.types[0], 'd')} ${help}`; } if (aa == 'TypeReference' && bb == aa && cc == 'ArrayType') { // should check that this is Hover.Contents return `${goType(n.types[0], 'e')} ${help}`; } - if (aa == 'ArrayType' && bb == 'TypeReference' && cc == 'NullKeyword') { + if (aa == 'ArrayType' && bb == 'TypeReference' && (cc == 'NullKeyword' || cc === 'LiteralType')) { // check this is nm == 'textDocument/completion' return `${goType(n.types[1], 'f')} ${help}`; } if (aa == 'LiteralType' && bb == aa && cc == aa) return `string ${help}`; + // keep this for diagnosing unexpected interface{} results + // console.log(`931, interface{} for ${aa}/${goType(n.types[0], 'g')},${bb}/${goType(n.types[1], 'h')},${cc}/${goType(n.types[2], 'i')} ${nm}`); break; } case 4: @@ -1206,6 +1208,14 @@ function goReq(side: side, m: string) { if err := json.Unmarshal(r.Params(), ¶ms); err != nil { return true, sendParseError(ctx, reply, err) }`; + if (a === 'ParamInitialize') { + case1 = `var params ${a} + if err := json.Unmarshal(r.Params(), ¶ms); err != nil { + if _, ok := err.(*json.UnmarshalTypeError); !ok { + return true, sendParseError(ctx, reply, err) + } + }`; + } } const arg2 = a == '' ? '' : ', ¶ms'; // if case2 is not explicitly typed string, typescript makes it a union of strings