From c3a64bcb178032c5ca6829a4d64a6a0839bd7ed3 Mon Sep 17 00:00:00 2001 From: Gabriela Araujo Britto Date: Tue, 12 Oct 2021 15:24:06 -0700 Subject: [PATCH] small fixes; fixed tests --- src/compiler/emitter.ts | 4 - src/compiler/utilities.ts | 4 + src/services/completions.ts | 5 -- src/services/snippets.ts | 56 ------------- src/services/tsconfig.json | 1 - .../fourslash/completionsOverridingMethod.ts | 80 ++++++++++++++----- .../fourslash/completionsOverridingMethod1.ts | 5 +- .../fourslash/completionsOverridingMethod2.ts | 2 +- 8 files changed, 66 insertions(+), 91 deletions(-) delete mode 100644 src/services/snippets.ts diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index b0e4d9d08bf..caed89fa338 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -4551,10 +4551,6 @@ namespace ts { writer.write(s); } - function escapeSnippetText(text: string): string { - return text.replace(/\$/gm, "\\$"); - } - function increaseIndent() { writer.increaseIndent(); } diff --git a/src/compiler/utilities.ts b/src/compiler/utilities.ts index f93498f8ec7..7a3e51032e4 100644 --- a/src/compiler/utilities.ts +++ b/src/compiler/utilities.ts @@ -7419,4 +7419,8 @@ namespace ts { export function isFunctionExpressionOrArrowFunction(node: Node): node is FunctionExpression | ArrowFunction { return node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.ArrowFunction; } + + export function escapeSnippetText(text: string): string { + return text.replace(/\$/gm, "\\$"); + } } diff --git a/src/services/completions.ts b/src/services/completions.ts index 2d69bc30ae7..9f80cfb83b6 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -909,11 +909,6 @@ namespace ts.Completions { } } - // TODO: move to services/utilities? - function escapeSnippetText(text: string): string { - return text.replace(/\$/gm, "\\$"); - } - function originToCompletionEntryData(origin: SymbolOriginInfoExport): CompletionEntryData | undefined { return { exportName: origin.exportName, diff --git a/src/services/snippets.ts b/src/services/snippets.ts deleted file mode 100644 index f6e4a821c77..00000000000 --- a/src/services/snippets.ts +++ /dev/null @@ -1,56 +0,0 @@ -/* eslint-disable no-fallthrough */ -/* @internal */ -namespace ts.snippets { - // interface SnippetWriter extends EmitTextWriter, PrintHandlers {} - - // function createSnippetWriter(newLine: string): SnippetWriter { - // const substituteNode = (_hint: EmitHint, node: Node) => { - // switch (node.kind) { - // // Comments: - // // TODO: doesn't work because comments are `TextRanges` with a syntax kind, but are not nodes. - // // case SyntaxKind.SingleLineCommentTrivia: - // // case SyntaxKind.MultiLineCommentTrivia: - // // return escapeTrivia(node); - // // >> comments are emitted in previous phase - // // String-like literals: - // case SyntaxKind.StringLiteral: // >> emitLiteral - // return escapeLiteralLikeNode(node as StringLiteral); - // case SyntaxKind.RegularExpressionLiteral: // >> emitLiteral - // return escapeLiteralLikeNode(node as RegularExpressionLiteral); - // case SyntaxKind.NoSubstitutionTemplateLiteral: // >> emitLiteral - // // Has .rawText but also .text - // // Templates: - // // >> .rawText - // case SyntaxKind.TemplateHead: // >> emitLiteral - // case SyntaxKind.TemplateMiddle: // >> emitLiteral - // case SyntaxKind.TemplateTail: // >> emitLiteral - // // Identifiers: - // case SyntaxKind.Identifier: // >> emitIdentifier - // case SyntaxKind.PrivateIdentifier: // >> emitPrivateIdentifier - // // Other: - // // >> TODO: JSX? JSDoc? - - // return undefined; - // } - // return node; - // }; - - // const writer = createTextWriter(newLine); - - - // return { - // ...writer, - // substituteNode, - // }; - // } - - // function escapeLiteralLikeNode(node: T): T { - // const copy = getSynthesizedDeepClone(node); - // copy.text = escapeSnippetText(node.text); - // return copy; - // } - - // function escapeSnippetText(text: string): string { - // return text.replace(/\$/gm, "\\$"); - // } -} diff --git a/src/services/tsconfig.json b/src/services/tsconfig.json index 729386a3b77..1e0934804ed 100644 --- a/src/services/tsconfig.json +++ b/src/services/tsconfig.json @@ -33,7 +33,6 @@ "preProcess.ts", "rename.ts", "smartSelection.ts", - "snippets.ts", "signatureHelp.ts", "inlayHints.ts", "sourcemaps.ts", diff --git a/tests/cases/fourslash/completionsOverridingMethod.ts b/tests/cases/fourslash/completionsOverridingMethod.ts index 0097a44c402..ec166f52a14 100644 --- a/tests/cases/fourslash/completionsOverridingMethod.ts +++ b/tests/cases/fourslash/completionsOverridingMethod.ts @@ -81,6 +81,20 @@ //// f/*g*/ ////} +// @Filename: h.ts +// Case: Static method +// Note: static methods are only suggested for completions after the `static` keyword +////class HBase { +//// static met(n: number): number { +//// return n; +//// } +////} +//// +////class HSub extends HBase { +//// /*h1*/ +//// static /*h2*/ +////} + // format.setFormatOptions({ // newLineCharacter: "\n", // }); @@ -91,7 +105,7 @@ verify.completions({ isNewIdentifierLocation: true, preferences: { includeCompletionsWithInsertText: true, - includeCompletionsWithSnippetText: true, + includeCompletionsWithSnippetText: false, }, includes: [ { @@ -102,9 +116,8 @@ verify.completions({ pos: 0, end: 0, }, - isSnippet: true, insertText: -"foo(param1: string, param2: boolean): Promise {\r\n $1;\r\n}\r\n", +"foo(param1: string, param2: boolean): Promise {\r\n}\r\n", } ], }); @@ -114,7 +127,7 @@ verify.completions({ isNewIdentifierLocation: true, preferences: { includeCompletionsWithInsertText: true, - includeCompletionsWithSnippetText: true, + includeCompletionsWithSnippetText: false, }, includes: [ { @@ -125,9 +138,8 @@ verify.completions({ pos: 0, end: 0, }, - isSnippet: true, insertText: -"foo(a: string, b: string): string {\r\n $1;\r\n}\r\n", +"foo(a: string, b: string): string {\r\n}\r\n", } ], }); @@ -137,7 +149,7 @@ verify.completions({ isNewIdentifierLocation: true, preferences: { includeCompletionsWithInsertText: true, - includeCompletionsWithSnippetText: true, + includeCompletionsWithSnippetText: false, }, includes: [ { @@ -148,9 +160,8 @@ verify.completions({ pos: 0, end: 0, }, - isSnippet: true, insertText: -"foo(a: string): string {\r\n $1;\r\n}\r\n", +"foo(a: string): string {\r\n}\r\n", } ], }); @@ -160,7 +171,7 @@ verify.completions({ isNewIdentifierLocation: true, preferences: { includeCompletionsWithInsertText: true, - includeCompletionsWithSnippetText: true, + includeCompletionsWithSnippetText: false, }, includes: [ { @@ -171,9 +182,8 @@ verify.completions({ pos: 0, end: 0, }, - isSnippet: true, insertText: -"foo(a: string): string {\r\n $1;\r\n}\r\n", +"foo(a: string): string {\r\n}\r\n", } ], }); @@ -183,7 +193,7 @@ verify.completions({ isNewIdentifierLocation: true, preferences: { includeCompletionsWithInsertText: true, - includeCompletionsWithSnippetText: true, + includeCompletionsWithSnippetText: false, }, includes: [ { @@ -194,9 +204,8 @@ verify.completions({ pos: 0, end: 0, }, - isSnippet: true, insertText: -"foo(a: string): string {\r\n $1;\r\n}\r\n", +"foo(a: string): string {\r\n}\r\n", } ], }); @@ -206,7 +215,7 @@ verify.completions({ isNewIdentifierLocation: true, preferences: { includeCompletionsWithInsertText: true, - includeCompletionsWithSnippetText: true, + includeCompletionsWithSnippetText: false, }, includes: [ { @@ -217,9 +226,8 @@ verify.completions({ pos: 0, end: 0, }, - isSnippet: true, insertText: -"foo(a: string): string {\r\n $1;\r\n}\r\n", +"foo(a: string): string {\r\n}\r\n", } ], }); @@ -229,7 +237,7 @@ verify.completions({ isNewIdentifierLocation: true, preferences: { includeCompletionsWithInsertText: true, - includeCompletionsWithSnippetText: true, + includeCompletionsWithSnippetText: false, }, includes: [ { @@ -240,11 +248,41 @@ verify.completions({ pos: 0, end: 0, }, - isSnippet: true, insertText: "foo(a: string): string;\r\n\ foo(a: undefined, b: number): string;\r\n\ -foo(a: any, b?: any): string {\r\n $1;\r\n}\r\n", +foo(a: any, b?: any): string {\r\n}\r\n", + } + ], +}); + +verify.completions({ + marker: "h1", + isNewIdentifierLocation: true, + preferences: { + includeCompletionsWithInsertText: true, + includeCompletionsWithSnippetText: false, + }, + excludes: "met", +}); +verify.completions({ + marker: "h2", + isNewIdentifierLocation: true, + preferences: { + includeCompletionsWithInsertText: true, + includeCompletionsWithSnippetText: false, + }, + includes: [ + { + name: "met", + sortText: completion.SortText.LocationPriority, + replacementSpan: { + fileName: "", + pos: 0, + end: 0, + }, + insertText: +"met(n: number): number {\r\n}\r\n", } ], }); \ No newline at end of file diff --git a/tests/cases/fourslash/completionsOverridingMethod1.ts b/tests/cases/fourslash/completionsOverridingMethod1.ts index 3377ac5c742..9ff6bff1fcb 100644 --- a/tests/cases/fourslash/completionsOverridingMethod1.ts +++ b/tests/cases/fourslash/completionsOverridingMethod1.ts @@ -21,7 +21,7 @@ verify.completions({ isNewIdentifierLocation: true, preferences: { includeCompletionsWithInsertText: true, - includeCompletionsWithSnippetText: true, + includeCompletionsWithSnippetText: false, }, includes: [ { @@ -32,9 +32,8 @@ verify.completions({ pos: 0, end: 0, }, - isSnippet: true, insertText: -"override foo(a: string): void {\r\n $1;\r\n}\r\n", +"override foo(a: string): void {\r\n}\r\n", } ], }); \ No newline at end of file diff --git a/tests/cases/fourslash/completionsOverridingMethod2.ts b/tests/cases/fourslash/completionsOverridingMethod2.ts index 5f833a2ffa5..7e1ab801c06 100644 --- a/tests/cases/fourslash/completionsOverridingMethod2.ts +++ b/tests/cases/fourslash/completionsOverridingMethod2.ts @@ -32,7 +32,7 @@ verify.completions({ }, isSnippet: true, insertText: -"$usd(a: number): number {\r\n $0\r\n}\r\n", +"\"\\$usd\"(${1:a}: ${2:number}): ${3:number} {\r\n $0\r\n}\r\n", } ], }); \ No newline at end of file