From a98e7fcfeb29c6507a62caeebba3d5079ea94ee7 Mon Sep 17 00:00:00 2001 From: Peter Weinberger Date: Thu, 19 Dec 2019 11:25:26 -0500 Subject: [PATCH] internal/lps/protocol: bring code.ts up to date with latest changes. This CL makes sure that code.ts will generate the latest version of tsprotocol.go. It has a more succinct way of deciding which fields need to be pointers. Change-Id: I6854cb2f096d3707bc3b828a9601f9384638f475 Reviewed-on: https://go-review.googlesource.com/c/tools/+/212140 Run-TryBot: Peter Weinberger TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- internal/lsp/protocol/typescript/code.ts | 30 ++++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/internal/lsp/protocol/typescript/code.ts b/internal/lsp/protocol/typescript/code.ts index de8a051d40..111cc44355 100644 --- a/internal/lsp/protocol/typescript/code.ts +++ b/internal/lsp/protocol/typescript/code.ts @@ -466,6 +466,13 @@ function toGo(d: Data, nm: string) { `more cases in toGo ${nm} ${d.as.length} ${d.generics.length} `) } +// these fields need a * +var starred: [string, string][] = [ + ['TextDocumentContentChangeEvent', 'range'], ['CodeAction', 'command'], + ['DidSaveTextDocumentParams', 'text'], ['CompletionItem', 'command'], + ['CompletionItem', 'textEdit'] +]; + // generate Go code for an interface function goInterface(d: Data, nm: string) { let ans = `type ${goName(nm)} struct {\n`; @@ -479,18 +486,10 @@ function goInterface(d: Data, nm: string) { // SelectionRange is a recursive type let gt = goType(n.type, n.name.getText()); if (gt == d.name) gt = '*' + gt; // avoid recursive types - // There's a difference between a nil Range and a zero Range (at the - // beginning of files) - if (d.name == 'TextDocumentContentChangeEvent' && - n.name.getText() == 'range') { - gt = '*' + gt; - } - if (d.name == 'CodeAction' && n.name.getText() == 'command') { - gt = '*' + gt; - } - if (d.name == 'DidSaveTextDocumentParams' && n.name.getText() == 'text') { - gt = '*' + gt; - } + // there are several cases where a * is needed + starred.forEach(([a, b]) => { + if (d.name == a && n.name.getText() == b) gt = '*' + gt + }); ans = ans.concat(`${goName(n.name.getText())} ${gt}`, json, '\n') }; d.properties.forEach(g) @@ -650,8 +649,8 @@ function goUnionType(n: ts.UnionTypeNode, nm: string): string { const bb = strKind(n.types[1]) const cc = strKind(n.types[2]) if (nm == 'DocumentFilter') { - // not really a union. the first is enough, up to a missing omitempty - // but avoid repetitious comments + // not really a union. the first is enough, up to a missing + // omitempty but avoid repetitious comments return `${goType(n.types[0], 'g')}` } if (nm == 'textDocument/documentSymbol') { @@ -856,7 +855,8 @@ const notNil = `if r.Params != nil { return true }`; -// Go code for notifications. Side is client or server, m is the request method +// Go code for notifications. Side is client or server, m is the request +// method function goNot(side: side, m: string) { if (m == '$/cancelRequest') return; // handled specially in protocol.go const n = not.get(m);