From d99d6faea5e3361cd13df47fba611740060e1c6e Mon Sep 17 00:00:00 2001 From: Peter Weinberger Date: Wed, 1 Dec 2021 11:03:28 -0500 Subject: [PATCH] internal/lsp/protocol: fix whitespace in comments There's one case when doing something about newlines in comments is necessary, but the existing code removed newlines from comments in several other places. The new code fixes that and a few other leftovers. Change-Id: Ia7905f07584ea1774f4fde786bdd5ee732acc818 Reviewed-on: https://go-review.googlesource.com/c/tools/+/368214 Run-TryBot: Peter Weinberger gopls-CI: kokoro Trust: Peter Weinberger Reviewed-by: Robert Findley --- internal/lsp/protocol/tsprotocol.go | 30 +++++++++++++++++++----- internal/lsp/protocol/typescript/code.ts | 15 ++++++------ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/internal/lsp/protocol/tsprotocol.go b/internal/lsp/protocol/tsprotocol.go index 857b142d128..c22ed9c67b1 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: d959faf4be476a6e0a08d5612e91fcac14ff9929 -// last fetched Mon Nov 29 2021 15:51:05 GMT-0500 (Eastern Standard Time) +// last fetched Wed Dec 01 2021 09:27:34 GMT-0500 (Eastern Standard Time) package protocol // Code generated (see typescript/README.md) DO NOT EDIT. @@ -382,7 +382,13 @@ type CodeActionClientCapabilities struct { * The code action kind is support with the following value * set. */ - CodeActionKind struct { /** * The code action kind values the client supports. When this * property exists the client also guarantees that it will * handle values outside its set gracefully and falls back * to a default value when unknown. */ + CodeActionKind struct { + /** + * The code action kind values the client supports. When this + * property exists the client also guarantees that it will + * handle values outside its set gracefully and falls back + * to a default value when unknown. + */ ValueSet []CodeActionKind `json:"valueSet"` } `json:"codeActionKind"` } `json:"codeActionLiteralSupport,omitempty"` @@ -745,7 +751,10 @@ type CompletionClientCapabilities struct { * * @since 3.15.0 */ - TagSupport struct { /** * The tags supported by the client. */ + TagSupport struct { + /** + * The tags supported by the client. + */ ValueSet []CompletionItemTag `json:"valueSet"` } `json:"tagSupport,omitempty"` /** @@ -762,7 +771,10 @@ type CompletionClientCapabilities struct { * * @since 3.16.0 */ - ResolveSupport struct { /** * The properties that a client can resolve lazily. */ + ResolveSupport struct { + /** + * The properties that a client can resolve lazily. + */ Properties []string `json:"properties"` } `json:"resolveSupport,omitempty"` /** @@ -4139,7 +4151,13 @@ type SignatureHelpClientCapabilities struct { /** * Client capabilities specific to parameter information. */ - ParameterInformation struct { /** * The client supports processing label offsets instead of a * simple label string. * * @since 3.14.0 */ + ParameterInformation struct { + /** + * The client supports processing label offsets instead of a + * simple label string. + * + * @since 3.14.0 + */ LabelOffsetSupport bool `json:"labelOffsetSupport,omitempty"` } `json:"parameterInformation,omitempty"` /** @@ -5113,7 +5131,7 @@ type WorkspaceEdit struct { /** * Holds changes to existing resources. */ - Changes map[DocumentURI]interface{}/*[uri: DocumentUri]: TextEdit[];*/ `json:"changes,omitempty"` + Changes map[DocumentURI][]TextEdit/*[uri: DocumentUri]: TextEdit[];*/ `json:"changes,omitempty"` /** * Depending on the client capability `workspace.workspaceEdit.resourceOperations` document changes * are either an array of `TextDocumentEdit`s to express changes to n different text documents diff --git a/internal/lsp/protocol/typescript/code.ts b/internal/lsp/protocol/typescript/code.ts index d7342aed878..807800aadf4 100644 --- a/internal/lsp/protocol/typescript/code.ts +++ b/internal/lsp/protocol/typescript/code.ts @@ -876,9 +876,8 @@ function goUnionType(n: ts.UnionTypeNode, nm: string): string { if (a == 'NumberKeyword' && b == 'StringKeyword') { // ID return `interface{} ${help}`; } - if (b == 'NullKeyword' || n.types[1].getText() === 'null') { - // PJW: fix this. it looks like 'null' is now being parsed as LiteralType - // and check the other keyword cases + // for null, b is not useful (LiternalType) + if (n.types[1].getText() === 'null') { if (nm == 'textDocument/codeAction') { // (Command | CodeAction)[] | null return `[]CodeAction ${help}`; @@ -948,8 +947,8 @@ function goUnionType(n: ts.UnionTypeNode, nm: string): string { if (nm == 'documentChanges') return `TextDocumentEdit ${help} `; if (nm == 'textDocument/prepareRename') return `Range ${help} `; break; - case 8: // LSPany - break; + case 8: // LSPany + break; default: throw new Error(`957 goUnionType len=${n.types.length} nm=${nm} ${n.getText()}`); } @@ -1075,7 +1074,9 @@ function goTypeLiteral(n: ts.TypeLiteralNode, nm: string): string { let json = u.JSON(nx); let typ = goType(nx.type, nx.name.getText()); // }/*\n*/`json:v` is not legal, the comment is a newline - typ = typ.replace(/\n\t*/g, ' '); // PJW: try to do this only when needed + if (typ.includes('\n') && typ.indexOf('*/') === typ.length - 2) { + typ = typ.replace(/\n\t*/g, ' '); + } const v = getComments(nx) || ''; starred.forEach(([a, b]) => { if (a != nm || b != typ.toLowerCase()) return; @@ -1094,7 +1095,7 @@ function goTypeLiteral(n: ts.TypeLiteralNode, nm: string): string { } else if (nx.getText().startsWith('[uri: string')) { res = 'map[string]interface{}'; } else if (nx.getText().startsWith('[uri: DocumentUri')) { - res = 'map[DocumentURI]interface{}'; //PJW make this more precise + res = 'map[DocumentURI][]TextEdit'; } else if (nx.getText().startsWith('[key: string')) { res = 'map[string]interface{}'; } else {