wip: more fixes and tests

This commit is contained in:
Gabriela Araujo Britto
2021-09-23 12:22:00 -07:00
parent 2fa43e8531
commit 1d04720a9b
2 changed files with 35 additions and 29 deletions
+31 -26
View File
@@ -772,37 +772,42 @@ namespace ts.Completions {
{ program, host },
preferences,
importAdder,
// `addNewNodeForMemberSymbol` calls this callback function for each new member node
// it adds for the given member symbol.
// We store these member nodes in the `completionNodes` array.
// Note that there might be:
// - No nodes if `addNewNodeForMemberSymbol` cannot figure out a node for the member;
// - One node;
// - More than one node if the member is overloaded (e.g. a method with overload signatures).
node => {
// `addNewNodeForMemberSymbol` calls this callback function for each new member node
// it adds for the given member symbol.
// We store these member nodes in the `completionNodes` array.
// Note that there might be:
// - No nodes if `addNewNodeForMemberSymbol` cannot figure out a node for the member;
// - One node;
// - More than one node if the member is overloaded (e.g. a method with overload signatures).
if (isClassDeclaration(classLikeDeclaration) && hasAbstractModifier(classLikeDeclaration)) {
// >> TODO: making it abstract. might not need it after all.
// if (hasAbstractModifier(classLikeDeclaration)) {
// Add `abstract` modifier
// node = factory.updateModifiers(
// node,
// concatenate([factory.createModifier(SyntaxKind.AbstractKeyword)], node.modifiers),
// );
// if (isMethodDeclaration(node)) {
// // Remove method body
// node = factory.updateMethodDeclaration(
// node,
// node.decorators,
// node.modifiers,
// node.asteriskToken,
// node.name,
// node.questionToken,
// node.typeParameters,
// node.parameters,
// node.type,
// /* body */ undefined,
// );
// }
// }
if (options.noImplicitOverride && /* TODO: isOverride(node) */ undefined) {
node = factory.updateModifiers(
node,
concatenate([factory.createModifier(SyntaxKind.AbstractKeyword)], node.modifiers),
concatenate([factory.createModifier(SyntaxKind.OverrideKeyword)], node.modifiers),
);
// >> TODO: we want to remove the body in more cases I think
// >> e.g. interfaces?
if (isMethodDeclaration(node)) {
// Remove method body
node = factory.updateMethodDeclaration(
node,
node.decorators,
node.modifiers,
node.asteriskToken,
node.name,
node.questionToken,
node.typeParameters,
node.parameters,
node.type,
/* body */ undefined,
);
}
}
completionNodes.push(node);
},
@@ -173,7 +173,7 @@ verify.completions({
},
isSnippet: true,
insertText:
"abstract foo(a: string): string;\r\n",
"foo(a: string): string {\r\n $1;\r\n}\r\n",
}
],
});
@@ -219,7 +219,7 @@ verify.completions({
},
isSnippet: true,
insertText:
"abstract foo(a: string): string;\r\n",
"foo(a: string): string {\r\n $1;\r\n}\r\n",
}
],
});
@@ -247,4 +247,5 @@ foo(a: undefined, b: number): string;\r\n\
foo(a: any, b?: any): string {\r\n $1;\r\n}\r\n",
}
],
});
});