Skip to content

Commit

Permalink
internal/lsp/protocol/typescript: update documentation and generated …
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
pjweinbgo committed Apr 16, 2021
1 parent fe50371 commit 1a0c608
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 35 deletions.
2 changes: 1 addition & 1 deletion internal/lsp/protocol/tsclient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 1 addition & 24 deletions internal/lsp/protocol/tsprotocol.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 7 additions & 5 deletions internal/lsp/protocol/tsserver.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions internal/lsp/protocol/typescript/README.md
Expand Up @@ -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

Expand Down Expand Up @@ -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.)
14 changes: 12 additions & 2 deletions internal/lsp/protocol/typescript/code.ts
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1a0c608

Please sign in to comment.