From e2c6db2e206211a30bf8770ec5d683fb7e02b00d Mon Sep 17 00:00:00 2001 From: Andy Date: Fri, 3 Nov 2017 16:38:35 -0700 Subject: [PATCH] For getCompletionsAtPosition, require a flag to provide completions with code actions (#19687) (#19731) * For getCompletionsAtPosition, require a flag to provide completions with code actions * Change name * Increase API version * Update API baselines * Add comment * Update API baseline --- src/harness/fourslash.ts | 24 +++++++++---------- src/harness/harnessLanguageService.ts | 4 ++-- .../unittests/tsserverProjectSystem.ts | 12 +++++----- src/server/client.ts | 4 ++-- src/server/protocol.ts | 5 ++++ src/server/session.ts | 8 +++---- src/services/completions.ts | 10 +++++--- src/services/services.ts | 14 ++++++++--- src/services/shims.ts | 8 +++---- src/services/types.ts | 6 ++++- .../reference/api/tsserverlibrary.d.ts | 12 ++++++++-- tests/baselines/reference/api/typescript.d.ts | 7 ++++-- ...letionsImport_default_addToNamedImports.ts | 2 +- ...ionsImport_default_addToNamespaceImport.ts | 2 +- ...Import_default_alreadyExistedWithRename.ts | 2 +- ...letionsImport_default_didNotExistBefore.ts | 2 +- .../fourslash/completionsImport_matching.ts | 11 +++++---- .../completionsImport_multipleWithSameName.ts | 7 +++--- ...mpletionsImport_named_addToNamedImports.ts | 2 +- ...mpletionsImport_named_didNotExistBefore.ts | 7 +++--- ...tionsImport_named_namespaceImportExists.ts | 2 +- .../fourslash/completionsImport_ofAlias.ts | 7 +++--- ...pletionsImport_previousTokenIsSemicolon.ts | 2 +- .../completionsImport_shadowedByLocal.ts | 5 ++-- tests/cases/fourslash/fourslash.ts | 1 + 25 files changed, 102 insertions(+), 64 deletions(-) diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 7ba4e94902d..068356605a3 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -783,8 +783,8 @@ namespace FourSlash { }); } - public verifyCompletionListContains(entryId: ts.Completions.CompletionEntryIdentifier, text?: string, documentation?: string, kind?: string, spanIndex?: number, hasAction?: boolean) { - const completions = this.getCompletionListAtCaret(); + public verifyCompletionListContains(entryId: ts.Completions.CompletionEntryIdentifier, text?: string, documentation?: string, kind?: string, spanIndex?: number, hasAction?: boolean, options?: ts.GetCompletionsAtPositionOptions) { + const completions = this.getCompletionListAtCaret(options); if (completions) { this.assertItemInCompletionList(completions.entries, entryId, text, documentation, kind, spanIndex, hasAction); } @@ -804,7 +804,7 @@ namespace FourSlash { * @param expectedKind the kind of symbol (see ScriptElementKind) * @param spanIndex the index of the range that the completion item's replacement text span should match */ - public verifyCompletionListDoesNotContain(entryId: ts.Completions.CompletionEntryIdentifier, expectedText?: string, expectedDocumentation?: string, expectedKind?: string, spanIndex?: number) { + public verifyCompletionListDoesNotContain(entryId: ts.Completions.CompletionEntryIdentifier, expectedText?: string, expectedDocumentation?: string, expectedKind?: string, spanIndex?: number, options?: ts.GetCompletionsAtPositionOptions) { const that = this; let replacementSpan: ts.TextSpan; if (spanIndex !== undefined) { @@ -831,7 +831,7 @@ namespace FourSlash { return true; } - const completions = this.getCompletionListAtCaret(); + const completions = this.getCompletionListAtCaret(options); if (completions) { let filterCompletions = completions.entries.filter(e => e.name === entryId.name && e.source === entryId.source); filterCompletions = expectedKind ? filterCompletions.filter(e => e.kind === expectedKind) : filterCompletions; @@ -1126,11 +1126,11 @@ Actual: ${stringify(fullActual)}`); this.raiseError(`verifyReferencesAtPositionListContains failed - could not find the item: ${stringify(missingItem)} in the returned list: (${stringify(references)})`); } - private getCompletionListAtCaret() { - return this.languageService.getCompletionsAtPosition(this.activeFile.fileName, this.currentCaretPosition); + private getCompletionListAtCaret(options?: ts.GetCompletionsAtPositionOptions): ts.CompletionInfo { + return this.languageService.getCompletionsAtPosition(this.activeFile.fileName, this.currentCaretPosition, options); } - private getCompletionEntryDetails(entryName: string, source?: string) { + private getCompletionEntryDetails(entryName: string, source?: string): ts.CompletionEntryDetails { return this.languageService.getCompletionEntryDetails(this.activeFile.fileName, this.currentCaretPosition, entryName, this.formatCodeSettings, source); } @@ -1721,7 +1721,7 @@ Actual: ${stringify(fullActual)}`); } else if (prevChar === " " && /A-Za-z_/.test(ch)) { /* Completions */ - this.languageService.getCompletionsAtPosition(this.activeFile.fileName, offset); + this.languageService.getCompletionsAtPosition(this.activeFile.fileName, offset, { includeExternalModuleExports: false }); } if (i % checkCadence === 0) { @@ -2296,7 +2296,7 @@ Actual: ${stringify(fullActual)}`); public applyCodeActionFromCompletion(markerName: string, options: FourSlashInterface.VerifyCompletionActionOptions) { this.goToMarker(markerName); - const actualCompletion = this.getCompletionListAtCaret().entries.find(e => e.name === options.name && e.source === options.source); + const actualCompletion = this.getCompletionListAtCaret({ includeExternalModuleExports: true }).entries.find(e => e.name === options.name && e.source === options.source); if (!actualCompletion.hasAction) { this.raiseError(`Completion for ${options.name} does not have an associated action.`); @@ -3734,15 +3734,15 @@ namespace FourSlashInterface { // Verifies the completion list contains the specified symbol. The // completion list is brought up if necessary - public completionListContains(entryId: string | ts.Completions.CompletionEntryIdentifier, text?: string, documentation?: string, kind?: string, spanIndex?: number, hasAction?: boolean) { + public completionListContains(entryId: string | ts.Completions.CompletionEntryIdentifier, text?: string, documentation?: string, kind?: string, spanIndex?: number, hasAction?: boolean, options?: ts.GetCompletionsAtPositionOptions) { if (typeof entryId === "string") { entryId = { name: entryId, source: undefined }; } if (this.negative) { - this.state.verifyCompletionListDoesNotContain(entryId, text, documentation, kind, spanIndex); + this.state.verifyCompletionListDoesNotContain(entryId, text, documentation, kind, spanIndex, options); } else { - this.state.verifyCompletionListContains(entryId, text, documentation, kind, spanIndex, hasAction); + this.state.verifyCompletionListContains(entryId, text, documentation, kind, spanIndex, hasAction, options); } } diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 87827d0c14a..cfca4db6439 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -413,8 +413,8 @@ namespace Harness.LanguageService { getEncodedSemanticClassifications(fileName: string, span: ts.TextSpan): ts.Classifications { return unwrapJSONCallResult(this.shim.getEncodedSemanticClassifications(fileName, span.start, span.length)); } - getCompletionsAtPosition(fileName: string, position: number): ts.CompletionInfo { - return unwrapJSONCallResult(this.shim.getCompletionsAtPosition(fileName, position)); + getCompletionsAtPosition(fileName: string, position: number, options: ts.GetCompletionsAtPositionOptions | undefined): ts.CompletionInfo { + return unwrapJSONCallResult(this.shim.getCompletionsAtPosition(fileName, position, options)); } getCompletionEntryDetails(fileName: string, position: number, entryName: string, options: ts.FormatCodeOptions | undefined, source: string | undefined): ts.CompletionEntryDetails { return unwrapJSONCallResult(this.shim.getCompletionEntryDetails(fileName, position, entryName, JSON.stringify(options), source)); diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index 87a4329a92a..75a9c847e5f 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -1248,13 +1248,13 @@ namespace ts.projectSystem { service.checkNumberOfProjects({ externalProjects: 1 }); checkProjectActualFiles(service.externalProjects[0], [f1.path, f2.path, libFile.path]); - const completions1 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 2); + const completions1 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 2, { includeExternalModuleExports: false }); // should contain completions for string assert.isTrue(completions1.entries.some(e => e.name === "charAt"), "should contain 'charAt'"); assert.isFalse(completions1.entries.some(e => e.name === "toExponential"), "should not contain 'toExponential'"); service.closeClientFile(f2.path); - const completions2 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 2); + const completions2 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 2, { includeExternalModuleExports: false }); // should contain completions for string assert.isFalse(completions2.entries.some(e => e.name === "charAt"), "should not contain 'charAt'"); assert.isTrue(completions2.entries.some(e => e.name === "toExponential"), "should contain 'toExponential'"); @@ -1280,11 +1280,11 @@ namespace ts.projectSystem { service.checkNumberOfProjects({ externalProjects: 1 }); checkProjectActualFiles(service.externalProjects[0], [f1.path, f2.path, libFile.path]); - const completions1 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 0); + const completions1 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 0, { includeExternalModuleExports: false }); assert.isTrue(completions1.entries.some(e => e.name === "somelongname"), "should contain 'somelongname'"); service.closeClientFile(f2.path); - const completions2 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 0); + const completions2 = service.externalProjects[0].getLanguageService().getCompletionsAtPosition(f1.path, 0, { includeExternalModuleExports: false }); assert.isFalse(completions2.entries.some(e => e.name === "somelongname"), "should not contain 'somelongname'"); const sf2 = service.externalProjects[0].getLanguageService().getProgram().getSourceFile(f2.path); assert.equal(sf2.text, ""); @@ -1845,7 +1845,7 @@ namespace ts.projectSystem { // Check identifiers defined in HTML content are available in .ts file const project = configuredProjectAt(projectService, 0); - let completions = project.getLanguageService().getCompletionsAtPosition(file1.path, 1); + let completions = project.getLanguageService().getCompletionsAtPosition(file1.path, 1, { includeExternalModuleExports: false }); assert(completions && completions.entries[0].name === "hello", `expected entry hello to be in completion list`); // Close HTML file @@ -1859,7 +1859,7 @@ namespace ts.projectSystem { checkProjectActualFiles(configuredProjectAt(projectService, 0), [file1.path, file2.path, config.path]); // Check identifiers defined in HTML content are not available in .ts file - completions = project.getLanguageService().getCompletionsAtPosition(file1.path, 5); + completions = project.getLanguageService().getCompletionsAtPosition(file1.path, 5, { includeExternalModuleExports: false }); assert(completions && completions.entries[0].name !== "hello", `unexpected hello entry in completion list`); }); diff --git a/src/server/client.ts b/src/server/client.ts index 2781d7cf20a..32774ad2ad3 100644 --- a/src/server/client.ts +++ b/src/server/client.ts @@ -170,8 +170,8 @@ namespace ts.server { }; } - getCompletionsAtPosition(fileName: string, position: number): CompletionInfo { - const args: protocol.CompletionsRequestArgs = this.createFileLocationRequestArgs(fileName, position); + getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined): CompletionInfo { + const args: protocol.CompletionsRequestArgs = { ...this.createFileLocationRequestArgs(fileName, position), ...options }; const request = this.processRequest(CommandNames.Completions, args); const response = this.processResponse(request); diff --git a/src/server/protocol.ts b/src/server/protocol.ts index c94cd582660..de1e0fa769a 100644 --- a/src/server/protocol.ts +++ b/src/server/protocol.ts @@ -1607,6 +1607,11 @@ namespace ts.server.protocol { * Optional prefix to apply to possible completions. */ prefix?: string; + /** + * If enabled, TypeScript will search through all external modules' exports and add them to the completions list. + * This affects lone identifier completions but not completions on the right hand side of `obj.`. + */ + includeExternalModuleExports: boolean; } /** diff --git a/src/server/session.ts b/src/server/session.ts index 80a39e4a0a5..5284d38dc0f 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -1184,10 +1184,10 @@ namespace ts.server { const scriptInfo = this.projectService.getScriptInfoForNormalizedPath(file); const position = this.getPosition(args, scriptInfo); - const completions = project.getLanguageService().getCompletionsAtPosition(file, position); + const completions = project.getLanguageService().getCompletionsAtPosition(file, position, args); if (simplifiedResult) { return mapDefined(completions && completions.entries, entry => { - if (completions.isMemberCompletion || (entry.name.toLowerCase().indexOf(prefix.toLowerCase()) === 0)) { + if (completions.isMemberCompletion || startsWith(entry.name.toLowerCase(), prefix.toLowerCase())) { const { name, kind, kindModifiers, sortText, replacementSpan, hasAction, source } = entry; const convertedSpan = replacementSpan ? this.decorateSpan(replacementSpan, scriptInfo) : undefined; // Use `hasAction || undefined` to avoid serializing `false`. @@ -1811,10 +1811,10 @@ namespace ts.server { [CommandNames.FormatRangeFull]: (request: protocol.FormatRequest) => { return this.requiredResponse(this.getFormattingEditsForRangeFull(request.arguments)); }, - [CommandNames.Completions]: (request: protocol.CompletionDetailsRequest) => { + [CommandNames.Completions]: (request: protocol.CompletionsRequest) => { return this.requiredResponse(this.getCompletions(request.arguments, /*simplifiedResult*/ true)); }, - [CommandNames.CompletionsFull]: (request: protocol.CompletionDetailsRequest) => { + [CommandNames.CompletionsFull]: (request: protocol.CompletionsRequest) => { return this.requiredResponse(this.getCompletions(request.arguments, /*simplifiedResult*/ false)); }, [CommandNames.CompletionDetails]: (request: protocol.CompletionDetailsRequest) => { diff --git a/src/services/completions.ts b/src/services/completions.ts index 562cdd5cbb2..101715e743c 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -28,6 +28,7 @@ namespace ts.Completions { sourceFile: SourceFile, position: number, allSourceFiles: ReadonlyArray, + options: GetCompletionsAtPositionOptions, ): CompletionInfo | undefined { if (isInReferenceComment(sourceFile, position)) { return PathCompletions.getTripleSlashReferenceCompletion(sourceFile, position, compilerOptions, host); @@ -37,7 +38,7 @@ namespace ts.Completions { return getStringLiteralCompletionEntries(sourceFile, position, typeChecker, compilerOptions, host, log); } - const completionData = getCompletionData(typeChecker, log, sourceFile, position, allSourceFiles); + const completionData = getCompletionData(typeChecker, log, sourceFile, position, allSourceFiles, options); if (!completionData) { return undefined; } @@ -362,7 +363,7 @@ namespace ts.Completions { { name, source }: CompletionEntryIdentifier, allSourceFiles: ReadonlyArray, ): { type: "symbol", symbol: Symbol, location: Node, symbolToOriginInfoMap: SymbolOriginInfoMap } | { type: "request", request: Request } | { type: "none" } { - const completionData = getCompletionData(typeChecker, log, sourceFile, position, allSourceFiles); + const completionData = getCompletionData(typeChecker, log, sourceFile, position, allSourceFiles, { includeExternalModuleExports: true }); if (!completionData) { return { type: "none" }; } @@ -503,6 +504,7 @@ namespace ts.Completions { sourceFile: SourceFile, position: number, allSourceFiles: ReadonlyArray, + options: GetCompletionsAtPositionOptions, ): CompletionData | undefined { const isJavaScriptFile = isSourceFileJavaScript(sourceFile); @@ -900,7 +902,9 @@ namespace ts.Completions { const symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace | SymbolFlags.Alias; symbols = typeChecker.getSymbolsInScope(scopeNode, symbolMeanings); - getSymbolsFromOtherSourceFileExports(symbols, previousToken && isIdentifier(previousToken) ? previousToken.text : ""); + if (options.includeExternalModuleExports) { + getSymbolsFromOtherSourceFileExports(symbols, previousToken && isIdentifier(previousToken) ? previousToken.text : ""); + } filterGlobalCompletion(symbols); return true; diff --git a/src/services/services.ts b/src/services/services.ts index 100e90529e8..92c06055e80 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -31,7 +31,7 @@ namespace ts { /** The version of the language service API */ - export const servicesVersion = "0.6"; + export const servicesVersion = "0.7"; /* @internal */ let ruleProvider: formatting.RulesProvider; @@ -1322,9 +1322,17 @@ namespace ts { return [...program.getOptionsDiagnostics(cancellationToken), ...program.getGlobalDiagnostics(cancellationToken)]; } - function getCompletionsAtPosition(fileName: string, position: number): CompletionInfo { + function getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions = { includeExternalModuleExports: false }): CompletionInfo { synchronizeHostData(); - return Completions.getCompletionsAtPosition(host, program.getTypeChecker(), log, program.getCompilerOptions(), getValidSourceFile(fileName), position, program.getSourceFiles()); + return Completions.getCompletionsAtPosition( + host, + program.getTypeChecker(), + log, + program.getCompilerOptions(), + getValidSourceFile(fileName), + position, + program.getSourceFiles(), + options); } function getCompletionEntryDetails(fileName: string, position: number, name: string, formattingOptions?: FormatCodeSettings, source?: string): CompletionEntryDetails { diff --git a/src/services/shims.ts b/src/services/shims.ts index c64c86b841b..8d5d5011e98 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -140,7 +140,7 @@ namespace ts { getEncodedSyntacticClassifications(fileName: string, start: number, length: number): string; getEncodedSemanticClassifications(fileName: string, start: number, length: number): string; - getCompletionsAtPosition(fileName: string, position: number): string; + getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined): string; getCompletionEntryDetails(fileName: string, position: number, entryName: string, options: string/*Services.FormatCodeOptions*/, source: string | undefined): string; getQuickInfoAtPosition(fileName: string, position: number): string; @@ -885,10 +885,10 @@ namespace ts { * to provide at the given source position and providing a member completion * list if requested. */ - public getCompletionsAtPosition(fileName: string, position: number) { + public getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined) { return this.forwardJSONCall( - `getCompletionsAtPosition('${fileName}', ${position})`, - () => this.languageService.getCompletionsAtPosition(fileName, position) + `getCompletionsAtPosition('${fileName}', ${position}, ${options})`, + () => this.languageService.getCompletionsAtPosition(fileName, position, options) ); } diff --git a/src/services/types.ts b/src/services/types.ts index 3bb65b808fd..1ef1c39bc95 100644 --- a/src/services/types.ts +++ b/src/services/types.ts @@ -236,7 +236,7 @@ namespace ts { getEncodedSyntacticClassifications(fileName: string, span: TextSpan): Classifications; getEncodedSemanticClassifications(fileName: string, span: TextSpan): Classifications; - getCompletionsAtPosition(fileName: string, position: number): CompletionInfo; + getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined): CompletionInfo; // "options" and "source" are optional only for backwards-compatibility getCompletionEntryDetails( fileName: string, @@ -308,6 +308,10 @@ namespace ts { dispose(): void; } + export interface GetCompletionsAtPositionOptions { + includeExternalModuleExports: boolean; + } + export interface ApplyCodeActionCommandResult { successMessage: string; } diff --git a/tests/baselines/reference/api/tsserverlibrary.d.ts b/tests/baselines/reference/api/tsserverlibrary.d.ts index a512d934593..ce37e446884 100644 --- a/tests/baselines/reference/api/tsserverlibrary.d.ts +++ b/tests/baselines/reference/api/tsserverlibrary.d.ts @@ -3914,7 +3914,7 @@ declare namespace ts { getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[]; getEncodedSyntacticClassifications(fileName: string, span: TextSpan): Classifications; getEncodedSemanticClassifications(fileName: string, span: TextSpan): Classifications; - getCompletionsAtPosition(fileName: string, position: number): CompletionInfo; + getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined): CompletionInfo; getCompletionEntryDetails(fileName: string, position: number, name: string, options: FormatCodeOptions | FormatCodeSettings | undefined, source: string | undefined): CompletionEntryDetails; getCompletionEntrySymbol(fileName: string, position: number, name: string, source: string | undefined): Symbol; getQuickInfoAtPosition(fileName: string, position: number): QuickInfo; @@ -3952,6 +3952,9 @@ declare namespace ts { getProgram(): Program; dispose(): void; } + interface GetCompletionsAtPositionOptions { + includeExternalModuleExports: boolean; + } interface ApplyCodeActionCommandResult { successMessage: string; } @@ -4598,7 +4601,7 @@ declare namespace ts { } declare namespace ts { /** The version of the language service API */ - const servicesVersion = "0.6"; + const servicesVersion = "0.7"; interface DisplayPartsSymbolWriter extends SymbolWriter { displayParts(): SymbolDisplayPart[]; } @@ -6015,6 +6018,11 @@ declare namespace ts.server.protocol { * Optional prefix to apply to possible completions. */ prefix?: string; + /** + * If enabled, TypeScript will search through all external modules' exports and add them to the completions list. + * This affects lone identifier completions but not completions on the right hand side of `obj.`. + */ + includeExternalModuleExports: boolean; } /** * Completions request; value of command field is "completions". diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 095606d7ef2..cef3b185583 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -3914,7 +3914,7 @@ declare namespace ts { getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[]; getEncodedSyntacticClassifications(fileName: string, span: TextSpan): Classifications; getEncodedSemanticClassifications(fileName: string, span: TextSpan): Classifications; - getCompletionsAtPosition(fileName: string, position: number): CompletionInfo; + getCompletionsAtPosition(fileName: string, position: number, options: GetCompletionsAtPositionOptions | undefined): CompletionInfo; getCompletionEntryDetails(fileName: string, position: number, name: string, options: FormatCodeOptions | FormatCodeSettings | undefined, source: string | undefined): CompletionEntryDetails; getCompletionEntrySymbol(fileName: string, position: number, name: string, source: string | undefined): Symbol; getQuickInfoAtPosition(fileName: string, position: number): QuickInfo; @@ -3952,6 +3952,9 @@ declare namespace ts { getProgram(): Program; dispose(): void; } + interface GetCompletionsAtPositionOptions { + includeExternalModuleExports: boolean; + } interface ApplyCodeActionCommandResult { successMessage: string; } @@ -4598,7 +4601,7 @@ declare namespace ts { } declare namespace ts { /** The version of the language service API */ - const servicesVersion = "0.6"; + const servicesVersion = "0.7"; interface DisplayPartsSymbolWriter extends SymbolWriter { displayParts(): SymbolDisplayPart[]; } diff --git a/tests/cases/fourslash/completionsImport_default_addToNamedImports.ts b/tests/cases/fourslash/completionsImport_default_addToNamedImports.ts index 734b3ff0f66..7a7a220ca77 100644 --- a/tests/cases/fourslash/completionsImport_default_addToNamedImports.ts +++ b/tests/cases/fourslash/completionsImport_default_addToNamedImports.ts @@ -9,7 +9,7 @@ ////f/**/; goTo.marker(""); -verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true); +verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { includeExternalModuleExports: true }); verify.applyCodeActionFromCompletion("", { name: "foo", diff --git a/tests/cases/fourslash/completionsImport_default_addToNamespaceImport.ts b/tests/cases/fourslash/completionsImport_default_addToNamespaceImport.ts index d4a81bc5272..43e3854c5e3 100644 --- a/tests/cases/fourslash/completionsImport_default_addToNamespaceImport.ts +++ b/tests/cases/fourslash/completionsImport_default_addToNamespaceImport.ts @@ -8,7 +8,7 @@ ////f/**/; goTo.marker(""); -verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true); +verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { includeExternalModuleExports: true }); verify.applyCodeActionFromCompletion("", { name: "foo", diff --git a/tests/cases/fourslash/completionsImport_default_alreadyExistedWithRename.ts b/tests/cases/fourslash/completionsImport_default_alreadyExistedWithRename.ts index f49f5850043..ed34d5e4e9c 100644 --- a/tests/cases/fourslash/completionsImport_default_alreadyExistedWithRename.ts +++ b/tests/cases/fourslash/completionsImport_default_alreadyExistedWithRename.ts @@ -8,7 +8,7 @@ ////f/**/; goTo.marker(""); -verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true); +verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { includeExternalModuleExports: true }); verify.applyCodeActionFromCompletion("", { name: "foo", diff --git a/tests/cases/fourslash/completionsImport_default_didNotExistBefore.ts b/tests/cases/fourslash/completionsImport_default_didNotExistBefore.ts index fb4d65a1c52..82b8e92a570 100644 --- a/tests/cases/fourslash/completionsImport_default_didNotExistBefore.ts +++ b/tests/cases/fourslash/completionsImport_default_didNotExistBefore.ts @@ -7,7 +7,7 @@ ////f/**/; goTo.marker(""); -verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true); +verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { includeExternalModuleExports: true }); verify.applyCodeActionFromCompletion("", { name: "foo", diff --git a/tests/cases/fourslash/completionsImport_matching.ts b/tests/cases/fourslash/completionsImport_matching.ts index edecf3592cd..f5f9108fa6c 100644 --- a/tests/cases/fourslash/completionsImport_matching.ts +++ b/tests/cases/fourslash/completionsImport_matching.ts @@ -14,9 +14,10 @@ goTo.marker(""); -verify.not.completionListContains({ name: "abcde", source: "/a" }); -verify.not.completionListContains({ name: "dbf", source: "/a" }); +const options = { includeExternalModuleExports: true }; +verify.not.completionListContains({ name: "abcde", source: "/a" }, undefined, undefined, undefined, undefined, undefined, options); +verify.not.completionListContains({ name: "dbf", source: "/a" }, undefined, undefined, undefined, undefined, undefined, options); -verify.completionListContains({ name: "bdf", source: "/a" }, "function bdf(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true); -verify.completionListContains({ name: "abcdef", source: "/a" }, "function abcdef(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true); -verify.completionListContains({ name: "BDF", source: "/a" }, "function BDF(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true); +verify.completionListContains({ name: "bdf", source: "/a" }, "function bdf(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, options); +verify.completionListContains({ name: "abcdef", source: "/a" }, "function abcdef(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, options); +verify.completionListContains({ name: "BDF", source: "/a" }, "function BDF(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, options); diff --git a/tests/cases/fourslash/completionsImport_multipleWithSameName.ts b/tests/cases/fourslash/completionsImport_multipleWithSameName.ts index 825a4ca0a97..c9bb33d6c79 100644 --- a/tests/cases/fourslash/completionsImport_multipleWithSameName.ts +++ b/tests/cases/fourslash/completionsImport_multipleWithSameName.ts @@ -14,9 +14,10 @@ ////fo/**/ goTo.marker(""); -verify.completionListContains("foo", "var foo: number", "", "var"); -verify.completionListContains({ name: "foo", source: "/a" }, "const foo: 0", "", "const", /*spanIndex*/ undefined, /*hasAction*/ true); -verify.completionListContains({ name: "foo", source: "/b" }, "const foo: 1", "", "const", /*spanIndex*/ undefined, /*hasAction*/ true); +const options = { includeExternalModuleExports: true }; +verify.completionListContains("foo", "var foo: number", "", "var", undefined, undefined, options); +verify.completionListContains({ name: "foo", source: "/a" }, "const foo: 0", "", "const", /*spanIndex*/ undefined, /*hasAction*/ true, options); +verify.completionListContains({ name: "foo", source: "/b" }, "const foo: 1", "", "const", /*spanIndex*/ undefined, /*hasAction*/ true, options); verify.applyCodeActionFromCompletion("", { name: "foo", diff --git a/tests/cases/fourslash/completionsImport_named_addToNamedImports.ts b/tests/cases/fourslash/completionsImport_named_addToNamedImports.ts index 5444b25692a..b11552d0327 100644 --- a/tests/cases/fourslash/completionsImport_named_addToNamedImports.ts +++ b/tests/cases/fourslash/completionsImport_named_addToNamedImports.ts @@ -9,7 +9,7 @@ ////f/**/; goTo.marker(""); -verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true); +verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { includeExternalModuleExports: true }); verify.applyCodeActionFromCompletion("", { name: "foo", diff --git a/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts b/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts index 809e40e7cf2..9397ee004c2 100644 --- a/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts +++ b/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts @@ -9,9 +9,10 @@ ////t/**/ goTo.marker(""); -verify.completionListContains({ name: "Test1", source: "/a" }, "function Test1(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true); -verify.completionListContains("Test2", "import Test2", "", "alias", /*spanIndex*/ undefined, /*hasAction*/ undefined); -verify.not.completionListContains({ name: "Test2", source: "/a" }); +const options = { includeExternalModuleExports: true }; +verify.completionListContains({ name: "Test1", source: "/a" }, "function Test1(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, options); +verify.completionListContains("Test2", "import Test2", "", "alias", /*spanIndex*/ undefined, /*hasAction*/ undefined, options); +verify.not.completionListContains({ name: "Test2", source: "/a" }, undefined, undefined, undefined, undefined, undefined, options); verify.applyCodeActionFromCompletion("", { name: "Test1", diff --git a/tests/cases/fourslash/completionsImport_named_namespaceImportExists.ts b/tests/cases/fourslash/completionsImport_named_namespaceImportExists.ts index 70cd75a4e41..d4602795280 100644 --- a/tests/cases/fourslash/completionsImport_named_namespaceImportExists.ts +++ b/tests/cases/fourslash/completionsImport_named_namespaceImportExists.ts @@ -8,7 +8,7 @@ ////f/**/; goTo.marker(""); -verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true); +verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { includeExternalModuleExports: true }); verify.applyCodeActionFromCompletion("", { name: "foo", diff --git a/tests/cases/fourslash/completionsImport_ofAlias.ts b/tests/cases/fourslash/completionsImport_ofAlias.ts index 27bc29fa210..e7cdb366497 100644 --- a/tests/cases/fourslash/completionsImport_ofAlias.ts +++ b/tests/cases/fourslash/completionsImport_ofAlias.ts @@ -15,9 +15,10 @@ ////fo/**/ goTo.marker(""); -// https://github.com/Microsoft/TypeScript/issues/14003 -verify.completionListContains({ name: "foo", source: "/a" }, "import foo", "", "alias", /*spanIndex*/ undefined, /*hasAction*/ true); -verify.not.completionListContains({ name: "foo", source: "/a_reexport" }); +const options = { includeExternalModuleExports: true }; +// TODO: https://github.com/Microsoft/TypeScript/issues/14003 +verify.completionListContains({ name: "foo", source: "/a" }, "import foo", "", "alias", /*spanIndex*/ undefined, /*hasAction*/ true, options); +verify.not.completionListContains({ name: "foo", source: "/a_reexport" }, undefined, undefined, undefined, undefined, undefined, options); verify.applyCodeActionFromCompletion("", { name: "foo", diff --git a/tests/cases/fourslash/completionsImport_previousTokenIsSemicolon.ts b/tests/cases/fourslash/completionsImport_previousTokenIsSemicolon.ts index 5eddb5037c1..93c2cc01b0b 100644 --- a/tests/cases/fourslash/completionsImport_previousTokenIsSemicolon.ts +++ b/tests/cases/fourslash/completionsImport_previousTokenIsSemicolon.ts @@ -8,4 +8,4 @@ /////**/ goTo.marker(""); -verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true); +verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { includeExternalModuleExports: true }); diff --git a/tests/cases/fourslash/completionsImport_shadowedByLocal.ts b/tests/cases/fourslash/completionsImport_shadowedByLocal.ts index d35a021acc7..20e8c4a4bc8 100644 --- a/tests/cases/fourslash/completionsImport_shadowedByLocal.ts +++ b/tests/cases/fourslash/completionsImport_shadowedByLocal.ts @@ -8,5 +8,6 @@ ////fo/**/ goTo.marker(""); -verify.completionListContains("foo", "const foo: 1", "", "const"); -verify.not.completionListContains({ name: "foo", source: "/a" }); +const options = { includeExternalModuleExports: true }; +verify.completionListContains("foo", "const foo: 1", "", "const", undefined, undefined, options); +verify.not.completionListContains({ name: "foo", source: "/a" }, undefined, undefined, undefined, undefined, undefined, options); diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 1dd1675b513..c63de6d175e 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -148,6 +148,7 @@ declare namespace FourSlashInterface { kind?: string, spanIndex?: number, hasAction?: boolean, + options?: { includeExternalModuleExports: boolean }, ): void; completionListItemsCountIsGreaterThan(count: number): void; completionListIsEmpty(): void;