Skip to content

Commit 1a0c608

Browse files
committed
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 <[email protected]> Trust: Rebecca Stambler <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent fe50371 commit 1a0c608

File tree

5 files changed

+25
-35
lines changed

5 files changed

+25
-35
lines changed

internal/lsp/protocol/tsclient.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/lsp/protocol/tsprotocol.go

+1-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/lsp/protocol/tsserver.go

+7-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/lsp/protocol/typescript/README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
## Setup
44

55
Make sure `node` and `tsc` are installed and in your PATH. There are detailed instructions below.
6+
(`tsc -v` should be at least `4.2.4`.)
67
Get the typescript code for the jsonrpc protocol with
78

89
`git clone [email protected]:microsoft vscode-languageserver-node.git` or
910
`git clone https://github.com/microsoft/vscode-languageserver-node.git`
1011

11-
`util.ts`` expects it to be in your HOME directory
12+
`util.ts` expects it to be in your HOME directory
1213

13-
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`
14+
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`
1415

1516
## Usage
1617

@@ -50,5 +51,5 @@ the generated files and stored in the variable `gitHash` in `go.ts`. It is check
5051
1. This will likely give warning messages that indicate you've failed to set up a project. Ignore them.
5152
2. Your home directory will now have new directories `.npm` and `node_modules` (and a `package_lock.json` file)
5253
3. The typescript executable `tsc` will be in `node_modules/.bin`, so put that directory in your path.
53-
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.
54+
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.
5455
6. `npm install @types/node` (Without this there will be many incomprehensible typescript error messages.)

internal/lsp/protocol/typescript/code.ts

+12-2
Original file line numberDiff line numberDiff line change
@@ -916,18 +916,20 @@ function goUnionType(n: ts.UnionTypeNode, nm: string): string {
916916
if (nm == 'textDocument/documentSymbol') {
917917
return `[]interface{} ${help}`;
918918
}
919-
if (aa == 'TypeReference' && bb == 'ArrayType' && cc == 'NullKeyword') {
919+
if (aa == 'TypeReference' && bb == 'ArrayType' && (cc == 'NullKeyword' || cc === 'LiteralType')) {
920920
return `${goType(n.types[0], 'd')} ${help}`;
921921
}
922922
if (aa == 'TypeReference' && bb == aa && cc == 'ArrayType') {
923923
// should check that this is Hover.Contents
924924
return `${goType(n.types[0], 'e')} ${help}`;
925925
}
926-
if (aa == 'ArrayType' && bb == 'TypeReference' && cc == 'NullKeyword') {
926+
if (aa == 'ArrayType' && bb == 'TypeReference' && (cc == 'NullKeyword' || cc === 'LiteralType')) {
927927
// check this is nm == 'textDocument/completion'
928928
return `${goType(n.types[1], 'f')} ${help}`;
929929
}
930930
if (aa == 'LiteralType' && bb == aa && cc == aa) return `string ${help}`;
931+
// keep this for diagnosing unexpected interface{} results
932+
// console.log(`931, interface{} for ${aa}/${goType(n.types[0], 'g')},${bb}/${goType(n.types[1], 'h')},${cc}/${goType(n.types[2], 'i')} ${nm}`);
931933
break;
932934
}
933935
case 4:
@@ -1206,6 +1208,14 @@ function goReq(side: side, m: string) {
12061208
if err := json.Unmarshal(r.Params(), &params); err != nil {
12071209
return true, sendParseError(ctx, reply, err)
12081210
}`;
1211+
if (a === 'ParamInitialize') {
1212+
case1 = `var params ${a}
1213+
if err := json.Unmarshal(r.Params(), &params); err != nil {
1214+
if _, ok := err.(*json.UnmarshalTypeError); !ok {
1215+
return true, sendParseError(ctx, reply, err)
1216+
}
1217+
}`;
1218+
}
12091219
}
12101220
const arg2 = a == '' ? '' : ', &params';
12111221
// if case2 is not explicitly typed string, typescript makes it a union of strings

0 commit comments

Comments
 (0)