update type of addNewNodeForMemberSymbol

This commit is contained in:
Gabriela Araujo Britto
2021-09-20 11:39:07 -07:00
parent 2c84d88686
commit 4d2d476962
5 changed files with 37 additions and 12 deletions
@@ -42,7 +42,7 @@ namespace ts.codefix {
const abstractAndNonPrivateExtendsSymbols = checker.getPropertiesOfType(instantiatedExtendsType).filter(symbolPointsToNonPrivateAndAbstractMember);
const importAdder = createImportAdder(sourceFile, context.program, preferences, context.host);
createMissingMemberNodes(classDeclaration, abstractAndNonPrivateExtendsSymbols, sourceFile, context, preferences, importAdder, member => changeTracker.insertNodeAtClassStart(sourceFile, classDeclaration, member));
createMissingMemberNodes(classDeclaration, abstractAndNonPrivateExtendsSymbols, sourceFile, context, preferences, importAdder, member => changeTracker.insertNodeAtClassStart(sourceFile, classDeclaration, member as ClassElement)); // >> TODO.
importAdder.writeFixes(changeTracker);
}
@@ -64,7 +64,7 @@ namespace ts.codefix {
}
const importAdder = createImportAdder(sourceFile, context.program, preferences, context.host);
createMissingMemberNodes(classDeclaration, nonPrivateAndNotExistedInHeritageClauseMembers, sourceFile, context, preferences, importAdder, member => insertInterfaceMemberNode(sourceFile, classDeclaration, member));
createMissingMemberNodes(classDeclaration, nonPrivateAndNotExistedInHeritageClauseMembers, sourceFile, context, preferences, importAdder, member => insertInterfaceMemberNode(sourceFile, classDeclaration, member as ClassElement)); // >> TODO.
importAdder.writeFixes(changeTracker);
function createMissingIndexSignatureDeclaration(type: InterfaceType, kind: IndexKind): void {
+11 -3
View File
@@ -7,7 +7,14 @@ namespace ts.codefix {
* @param importAdder If provided, type annotations will use identifier type references instead of ImportTypeNodes, and the missing imports will be added to the importAdder.
* @returns Empty string iff there are no member insertions.
*/
export function createMissingMemberNodes(classDeclaration: ClassLikeDeclaration, possiblyMissingSymbols: readonly Symbol[], sourceFile: SourceFile, context: TypeConstructionContext, preferences: UserPreferences, importAdder: ImportAdder | undefined, addClassElement: (node: ClassElement) => void): void {
export function createMissingMemberNodes(
classDeclaration: ClassLikeDeclaration,
possiblyMissingSymbols: readonly Symbol[],
sourceFile: SourceFile,
context: TypeConstructionContext,
preferences: UserPreferences,
importAdder: ImportAdder | undefined,
addClassElement: (node: AddNode) => void): void {
const classMembers = classDeclaration.symbol.members!;
for (const symbol of possiblyMissingSymbols) {
if (!classMembers.has(symbol.escapedName)) {
@@ -28,6 +35,8 @@ namespace ts.codefix {
host: LanguageServiceHost;
}
type AddNode = PropertyDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction;
/**
* `addClassElement` will not be called if we can't figure out a representation for `symbol` in `enclosingDeclaration`.
*/
@@ -38,8 +47,7 @@ namespace ts.codefix {
context: TypeConstructionContext,
preferences: UserPreferences,
importAdder: ImportAdder | undefined,
// addClassElement: (node: ClassElement | FunctionExpression | ArrowFunction) => void,
addClassElement: (node: PropertyDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | MethodDeclaration | FunctionExpression | ArrowFunction) => void,
addClassElement: (node: AddNode) => void,
): void {
const declarations = symbol.getDeclarations();
if (!(declarations && declarations.length)) {
+1 -2
View File
@@ -243,7 +243,6 @@ namespace ts.Completions {
// If the request is a continuation of an earlier `isIncomplete` response,
// we can continue it from the cached previous response.
const typeChecker = program.getTypeChecker();
const compilerOptions = program.getCompilerOptions();
const incompleteCompletionsCache = preferences.allowIncompleteCompletions ? host.getIncompleteCompletionsCache?.() : undefined;
if (incompleteCompletionsCache && completionKind === CompletionTriggerKind.TriggerForIncompleteCompletions && previousToken && isIdentifier(previousToken)) {
@@ -256,7 +255,7 @@ namespace ts.Completions {
incompleteCompletionsCache?.clear();
}
const stringCompletions = StringCompletions.getStringLiteralCompletions(sourceFile, position, previousToken, typeChecker, compilerOptions, host, log, preferences);
const stringCompletions = StringCompletions.getStringLiteralCompletions(sourceFile, position, previousToken, compilerOptions, host, program, log, preferences);
if (stringCompletions) {
return stringCompletions;
}
+23 -5
View File
@@ -1,18 +1,35 @@
/* @internal */
namespace ts.Completions.StringCompletions {
export function getStringLiteralCompletions(sourceFile: SourceFile, position: number, contextToken: Node | undefined, checker: TypeChecker, options: CompilerOptions, host: LanguageServiceHost, log: Log, preferences: UserPreferences): CompletionInfo | undefined {
export function getStringLiteralCompletions(
sourceFile: SourceFile,
position: number,
contextToken: Node | undefined,
options: CompilerOptions,
host: LanguageServiceHost,
program: Program,
log: Log,
preferences: UserPreferences): CompletionInfo | undefined {
if (isInReferenceComment(sourceFile, position)) {
const entries = getTripleSlashReferenceCompletion(sourceFile, position, options, host);
return entries && convertPathCompletions(entries);
}
if (isInString(sourceFile, position, contextToken)) {
if (!contextToken || !isStringLiteralLike(contextToken)) return undefined;
const entries = getStringLiteralCompletionEntries(sourceFile, contextToken, position, checker, options, host, preferences);
return convertStringLiteralCompletions(entries, contextToken, sourceFile, checker, log, options, preferences);
const entries = getStringLiteralCompletionEntries(sourceFile, contextToken, position, program.getTypeChecker(), options, host, preferences);
return convertStringLiteralCompletions(entries, contextToken, sourceFile, host, program, log, options, preferences);
}
}
function convertStringLiteralCompletions(completion: StringLiteralCompletion | undefined, contextToken: StringLiteralLike, sourceFile: SourceFile, checker: TypeChecker, log: Log, options: CompilerOptions, preferences: UserPreferences): CompletionInfo | undefined {
function convertStringLiteralCompletions(
completion: StringLiteralCompletion | undefined,
contextToken: StringLiteralLike,
sourceFile: SourceFile,
host: LanguageServiceHost,
program: Program,
log: Log,
options: CompilerOptions,
preferences: UserPreferences,
): CompletionInfo | undefined {
if (completion === undefined) {
return undefined;
}
@@ -29,7 +46,8 @@ namespace ts.Completions.StringCompletions {
contextToken,
sourceFile,
sourceFile,
checker,
host,
program,
ScriptTarget.ESNext,
log,
CompletionKind.String,