small fixes; fixed tests

This commit is contained in:
Gabriela Araujo Britto
2021-10-12 15:24:06 -07:00
parent 69ee9fc069
commit c3a64bcb17
8 changed files with 66 additions and 91 deletions

View File

@@ -4551,10 +4551,6 @@ namespace ts {
writer.write(s);
}
function escapeSnippetText(text: string): string {
return text.replace(/\$/gm, "\\$");
}
function increaseIndent() {
writer.increaseIndent();
}

View File

@@ -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, "\\$");
}
}

View File

@@ -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,

View File

@@ -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<T extends LiteralLikeNode>(node: T): T {
// const copy = getSynthesizedDeepClone(node);
// copy.text = escapeSnippetText(node.text);
// return copy;
// }
// function escapeSnippetText(text: string): string {
// return text.replace(/\$/gm, "\\$");
// }
}

View File

@@ -33,7 +33,6 @@
"preProcess.ts",
"rename.ts",
"smartSelection.ts",
"snippets.ts",
"signatureHelp.ts",
"inlayHints.ts",
"sourcemaps.ts",

View File

@@ -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<void> {\r\n $1;\r\n}\r\n",
"foo(param1: string, param2: boolean): Promise<void> {\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",
}
],
});

View File

@@ -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",
}
],
});

View File

@@ -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",
}
],
});