Skip to content

Commit

Permalink
internal/lsp/protocol: fix whitespace in comments
Browse files Browse the repository at this point in the history
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 <[email protected]>
gopls-CI: kokoro <[email protected]>
Trust: Peter Weinberger <[email protected]>
Reviewed-by: Robert Findley <[email protected]>
  • Loading branch information
pjweinbgo committed Dec 1, 2021
1 parent 3c63f30 commit d99d6fa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
30 changes: 24 additions & 6 deletions internal/lsp/protocol/tsprotocol.go

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

15 changes: 8 additions & 7 deletions internal/lsp/protocol/typescript/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down Expand Up @@ -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()}`);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down

0 comments on commit d99d6fa

Please sign in to comment.