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 <pjw@google.com>
Trust: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Peter Weinbergr 2021-04-16 11:05:54 -04:00 коммит произвёл Peter Weinberger
Родитель fe5037164a
Коммит 1a0c6081c5
5 изменённых файлов: 25 добавлений и 35 удалений

Просмотреть файл

@ -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.

Просмотреть файл

@ -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"`
/**

Просмотреть файл

@ -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(), &params); 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, &params)
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
}

Просмотреть файл

@ -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.)

Просмотреть файл

@ -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(), &params); err != nil {
return true, sendParseError(ctx, reply, err)
}`;
if (a === 'ParamInitialize') {
case1 = `var params ${a}
if err := json.Unmarshal(r.Params(), &params); err != nil {
if _, ok := err.(*json.UnmarshalTypeError); !ok {
return true, sendParseError(ctx, reply, err)
}
}`;
}
}
const arg2 = a == '' ? '' : ', &params';
// if case2 is not explicitly typed string, typescript makes it a union of strings