diff --git a/src/compiler/builder.ts b/src/compiler/builder.ts index 635855083c08d..34ca1bdf0e90a 100644 --- a/src/compiler/builder.ts +++ b/src/compiler/builder.ts @@ -77,7 +77,7 @@ namespace ts { } export interface BuilderOptions { - getCanonicalFileName: (fileName: string) => string; + getCanonicalFileName: GetCanonicalFileName; computeHash: (data: string) => string; } diff --git a/src/compiler/commandLineParser.ts b/src/compiler/commandLineParser.ts index 43ea77c802044..8cec21113c813 100644 --- a/src/compiler/commandLineParser.ts +++ b/src/compiler/commandLineParser.ts @@ -1540,7 +1540,7 @@ namespace ts { host: ParseConfigHost, basePath: string, configFileName: string, - getCanonicalFileName: (fileName: string) => string, + getCanonicalFileName: GetCanonicalFileName, resolutionStack: Path[], errors: Push, ): ParsedTsconfig { @@ -1588,7 +1588,7 @@ namespace ts { json: any, host: ParseConfigHost, basePath: string, - getCanonicalFileName: (fileName: string) => string, + getCanonicalFileName: GetCanonicalFileName, configFileName: string | undefined, errors: Push ): ParsedTsconfig { @@ -1619,7 +1619,7 @@ namespace ts { sourceFile: JsonSourceFile, host: ParseConfigHost, basePath: string, - getCanonicalFileName: (fileName: string) => string, + getCanonicalFileName: GetCanonicalFileName, configFileName: string | undefined, errors: Push ): ParsedTsconfig { @@ -1688,7 +1688,7 @@ namespace ts { extendedConfig: string, host: ParseConfigHost, basePath: string, - getCanonicalFileName: (fileName: string) => string, + getCanonicalFileName: GetCanonicalFileName, errors: Push, createDiagnostic: (message: DiagnosticMessage, arg1?: string) => Diagnostic) { extendedConfig = normalizeSlashes(extendedConfig); @@ -1713,7 +1713,7 @@ namespace ts { extendedConfigPath: Path, host: ts.ParseConfigHost, basePath: string, - getCanonicalFileName: (fileName: string) => string, + getCanonicalFileName: GetCanonicalFileName, resolutionStack: Path[], errors: Push, ): ParsedTsconfig | undefined { diff --git a/src/compiler/core.ts b/src/compiler/core.ts index f1322f109ccfe..3859dc27dd3bf 100644 --- a/src/compiler/core.ts +++ b/src/compiler/core.ts @@ -2033,7 +2033,7 @@ namespace ts { } } - export function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, getCanonicalFileName: (fileName: string) => string, isAbsolutePathAnUrl: boolean) { + export function getRelativePathToDirectoryOrUrl(directoryPathOrUrl: string, relativeOrAbsolutePath: string, currentDirectory: string, getCanonicalFileName: GetCanonicalFileName, isAbsolutePathAnUrl: boolean) { const pathComponents = getNormalizedPathOrUrlComponents(relativeOrAbsolutePath, currentDirectory); const directoryComponents = getNormalizedPathOrUrlComponents(directoryPathOrUrl, currentDirectory); if (directoryComponents.length > 1 && lastOrUndefined(directoryComponents) === "") { @@ -2808,7 +2808,8 @@ namespace ts { } } - export function createGetCanonicalFileName(useCaseSensitiveFileNames: boolean): (fileName: string) => string { + export type GetCanonicalFileName = (fileName: string) => string; + export function createGetCanonicalFileName(useCaseSensitiveFileNames: boolean): GetCanonicalFileName { return useCaseSensitiveFileNames ? ((fileName) => fileName) : ((fileName) => fileName.toLowerCase()); diff --git a/src/compiler/program.ts b/src/compiler/program.ts index cf7c03556f11c..6a8c88c3014b7 100755 --- a/src/compiler/program.ts +++ b/src/compiler/program.ts @@ -20,7 +20,7 @@ namespace ts { } /* @internal */ - export function computeCommonSourceDirectoryOfFilenames(fileNames: string[], currentDirectory: string, getCanonicalFileName: (fileName: string) => string): string { + export function computeCommonSourceDirectoryOfFilenames(fileNames: string[], currentDirectory: string, getCanonicalFileName: GetCanonicalFileName): string { let commonPathComponents: string[]; const failed = forEach(fileNames, sourceFile => { // Each file contributes into common source file path diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 2687a660ca8e4..6f08b900ec3c8 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -867,10 +867,10 @@ namespace FourSlash { }); } - public verifyCompletionListContains(entryId: ts.Completions.CompletionEntryIdentifier, text?: string, documentation?: string, kind?: string, spanIndex?: number, hasAction?: boolean, options?: ts.GetCompletionsAtPositionOptions) { + public verifyCompletionListContains(entryId: ts.Completions.CompletionEntryIdentifier, text?: string, documentation?: string, kind?: string, spanIndex?: number, hasAction?: boolean, options?: FourSlashInterface.VerifyCompletionListContainsOptions) { const completions = this.getCompletionListAtCaret(options); if (completions) { - this.assertItemInCompletionList(completions.entries, entryId, text, documentation, kind, spanIndex, hasAction); + this.assertItemInCompletionList(completions.entries, entryId, text, documentation, kind, spanIndex, hasAction, options); } else { this.raiseError(`No completions at position '${this.currentCaretPosition}' when looking for '${JSON.stringify(entryId)}'.`); @@ -3071,6 +3071,7 @@ Actual: ${stringify(fullActual)}`); kind: string | undefined, spanIndex: number | undefined, hasAction: boolean | undefined, + options: FourSlashInterface.VerifyCompletionListContainsOptions | undefined, ) { for (const item of items) { if (item.name === entryId.name && item.source === entryId.source) { @@ -3084,7 +3085,12 @@ Actual: ${stringify(fullActual)}`); assert.equal(ts.displayPartsToString(details.displayParts), text, this.assertionMessageAtLastKnownMarker("completion item detail text for " + entryId)); } - assert.deepEqual(details.source, entryId.source === undefined ? undefined : [ts.textPart(entryId.source)]); + if (entryId.source === undefined) { + assert.equal(options && options.sourceDisplay, undefined); + } + else { + assert.deepEqual(details.source, [ts.textPart(options!.sourceDisplay)]); + } } if (kind !== undefined) { @@ -3811,7 +3817,7 @@ 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, options?: ts.GetCompletionsAtPositionOptions) { + public completionListContains(entryId: string | ts.Completions.CompletionEntryIdentifier, text?: string, documentation?: string, kind?: string, spanIndex?: number, hasAction?: boolean, options?: VerifyCompletionListContainsOptions) { if (typeof entryId === "string") { entryId = { name: entryId, source: undefined }; } @@ -4547,6 +4553,10 @@ namespace FourSlashInterface { isNewIdentifierLocation?: boolean; } + export interface VerifyCompletionListContainsOptions extends ts.GetCompletionsAtPositionOptions { + sourceDisplay: string; + } + export interface NewContentOptions { // Exactly one of these should be defined. newFileContent?: string; diff --git a/src/services/codefixes/importFixes.ts b/src/services/codefixes/importFixes.ts index 838e19fa35de1..8971d1aa75ecf 100644 --- a/src/services/codefixes/importFixes.ts +++ b/src/services/codefixes/importFixes.ts @@ -34,7 +34,7 @@ namespace ts.codefix { host: LanguageServiceHost; checker: TypeChecker; compilerOptions: CompilerOptions; - getCanonicalFileName(fileName: string): string; + getCanonicalFileName: GetCanonicalFileName; cachedImportDeclarations?: ImportDeclarationMap; } @@ -313,7 +313,7 @@ namespace ts.codefix { } } - function getModuleSpecifierForNewImport(sourceFile: SourceFile, moduleSymbol: Symbol, options: CompilerOptions, getCanonicalFileName: (file: string) => string, host: LanguageServiceHost): string | undefined { + export function getModuleSpecifierForNewImport(sourceFile: SourceFile, moduleSymbol: Symbol, options: CompilerOptions, getCanonicalFileName: (file: string) => string, host: LanguageServiceHost): string | undefined { const moduleFileName = moduleSymbol.valueDeclaration.getSourceFile().fileName; const sourceDirectory = getDirectoryPath(sourceFile.fileName); @@ -523,7 +523,7 @@ namespace ts.codefix { return state > States.NodeModules ? { topLevelNodeModulesIndex, topLevelPackageNameIndex, packageRootIndex, fileNameIndex } : undefined; } - function getPathRelativeToRootDirs(path: string, rootDirs: ReadonlyArray, getCanonicalFileName: (fileName: string) => string): string | undefined { + function getPathRelativeToRootDirs(path: string, rootDirs: ReadonlyArray, getCanonicalFileName: GetCanonicalFileName): string | undefined { return firstDefined(rootDirs, rootDir => getRelativePathIfInDirectory(path, rootDir, getCanonicalFileName)); } @@ -535,12 +535,12 @@ namespace ts.codefix { return fileName; } - function getRelativePathIfInDirectory(path: string, directoryPath: string, getCanonicalFileName: (fileName: string) => string): string | undefined { + function getRelativePathIfInDirectory(path: string, directoryPath: string, getCanonicalFileName: GetCanonicalFileName): string | undefined { const relativePath = getRelativePathToDirectoryOrUrl(directoryPath, path, directoryPath, getCanonicalFileName, /*isAbsolutePathAnUrl*/ false); return isRootedDiskPath(relativePath) || startsWith(relativePath, "..") ? undefined : relativePath; } - function getRelativePath(path: string, directoryPath: string, getCanonicalFileName: (fileName: string) => string) { + function getRelativePath(path: string, directoryPath: string, getCanonicalFileName: GetCanonicalFileName) { const relativePath = getRelativePathToDirectoryOrUrl(directoryPath, path, directoryPath, getCanonicalFileName, /*isAbsolutePathAnUrl*/ false); return !pathIsRelative(relativePath) ? "./" + relativePath : relativePath; } diff --git a/src/services/completions.ts b/src/services/completions.ts index 6a9af1e194156..423919f535360 100644 --- a/src/services/completions.ts +++ b/src/services/completions.ts @@ -422,8 +422,9 @@ namespace ts.Completions { allSourceFiles: ReadonlyArray, host: LanguageServiceHost, formatContext: formatting.FormatContext, + getCanonicalFileName: GetCanonicalFileName, ): CompletionEntryDetails { - const { name, source } = entryId; + const { name } = entryId; // Compute all the completion symbols again. const symbolCompletion = getSymbolCompletionFromEntryId(typeChecker, log, compilerOptions, sourceFile, position, entryId, allSourceFiles); switch (symbolCompletion.type) { @@ -442,10 +443,10 @@ namespace ts.Completions { } case "symbol": { const { symbol, location, symbolToOriginInfoMap } = symbolCompletion; - const codeActions = getCompletionEntryCodeActions(symbolToOriginInfoMap, symbol, typeChecker, host, compilerOptions, sourceFile, formatContext); + const { codeActions, sourceDisplay } = getCompletionEntryCodeActionsAndSourceDisplay(symbolToOriginInfoMap, symbol, typeChecker, host, compilerOptions, sourceFile, formatContext, getCanonicalFileName); const kindModifiers = SymbolDisplay.getSymbolModifiers(symbol); const { displayParts, documentation, symbolKind, tags } = SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, location, location, SemanticMeaning.All); - return { name, kindModifiers, kind: symbolKind, displayParts, documentation, tags, codeActions, source: source === undefined ? undefined : [textPart(source)] }; + return { name, kindModifiers, kind: symbolKind, displayParts, documentation, tags, codeActions, source: sourceDisplay }; } case "none": { // Didn't find a symbol with this name. See if we can find a keyword instead. @@ -466,7 +467,7 @@ namespace ts.Completions { } } - function getCompletionEntryCodeActions( + function getCompletionEntryCodeActionsAndSourceDisplay( symbolToOriginInfoMap: SymbolOriginInfoMap, symbol: Symbol, checker: TypeChecker, @@ -474,14 +475,17 @@ namespace ts.Completions { compilerOptions: CompilerOptions, sourceFile: SourceFile, formatContext: formatting.FormatContext, - ): CodeAction[] | undefined { + getCanonicalFileName: GetCanonicalFileName, + ): { codeActions: CodeAction[] | undefined, sourceDisplay: SymbolDisplayPart[] | undefined } { const symbolOriginInfo = symbolToOriginInfoMap[getSymbolId(symbol)]; if (!symbolOriginInfo) { - return undefined; + return { codeActions: undefined, sourceDisplay: undefined }; } const { moduleSymbol, isDefaultExport } = symbolOriginInfo; - return codefix.getCodeActionForImport(moduleSymbol, { + + const sourceDisplay = [textPart(codefix.getModuleSpecifierForNewImport(sourceFile, moduleSymbol, compilerOptions, getCanonicalFileName, host))]; + const codeActions = codefix.getCodeActionForImport(moduleSymbol, { host, checker, newLineCharacter: host.getNewLine(), @@ -489,10 +493,11 @@ namespace ts.Completions { sourceFile, formatContext, symbolName: getSymbolName(symbol, symbolOriginInfo, compilerOptions.target), - getCanonicalFileName: createGetCanonicalFileName(host.useCaseSensitiveFileNames ? host.useCaseSensitiveFileNames() : false), + getCanonicalFileName, symbolToken: undefined, kind: isDefaultExport ? codefix.ImportKind.Default : codefix.ImportKind.Named, }); + return { sourceDisplay, codeActions }; } export function getCompletionEntrySymbol( diff --git a/src/services/rename.ts b/src/services/rename.ts index 8411e8200a371..cfe79679fba0a 100644 --- a/src/services/rename.ts +++ b/src/services/rename.ts @@ -1,6 +1,6 @@ /* @internal */ namespace ts.Rename { - export function getRenameInfo(typeChecker: TypeChecker, defaultLibFileName: string, getCanonicalFileName: (fileName: string) => string, sourceFile: SourceFile, position: number): RenameInfo { + export function getRenameInfo(typeChecker: TypeChecker, defaultLibFileName: string, getCanonicalFileName: GetCanonicalFileName, sourceFile: SourceFile, position: number): RenameInfo { const getCanonicalDefaultLibName = memoize(() => getCanonicalFileName(ts.normalizePath(defaultLibFileName))); const node = getTouchingWord(sourceFile, position, /*includeJsDocComment*/ true); const renameInfo = node && nodeIsEligibleForRename(node) diff --git a/src/services/services.ts b/src/services/services.ts index 06358d3a720b7..9eb29a6cd0633 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -920,7 +920,7 @@ namespace ts { private _compilationSettings: CompilerOptions; private currentDirectory: string; - constructor(private host: LanguageServiceHost, getCanonicalFileName: (fileName: string) => string) { + constructor(private host: LanguageServiceHost, getCanonicalFileName: GetCanonicalFileName) { // script id => script index this.currentDirectory = host.getCurrentDirectory(); this.fileNameToEntry = createMap(); @@ -1429,7 +1429,8 @@ namespace ts { { name, source }, program.getSourceFiles(), host, - formattingOptions && formatting.getFormatContext(formattingOptions)); + formattingOptions && formatting.getFormatContext(formattingOptions), + getCanonicalFileName); } function getCompletionEntrySymbol(fileName: string, position: number, name: string, source?: string): Symbol { diff --git a/tests/cases/fourslash/completionsImport_default_addToNamedImports.ts b/tests/cases/fourslash/completionsImport_default_addToNamedImports.ts index 7a7a220ca77e5..fb561355c3693 100644 --- a/tests/cases/fourslash/completionsImport_default_addToNamedImports.ts +++ b/tests/cases/fourslash/completionsImport_default_addToNamedImports.ts @@ -9,7 +9,10 @@ ////f/**/; goTo.marker(""); -verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { includeExternalModuleExports: true }); +verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { + includeExternalModuleExports: true, + sourceDisplay: "./a", +}); verify.applyCodeActionFromCompletion("", { name: "foo", diff --git a/tests/cases/fourslash/completionsImport_default_addToNamespaceImport.ts b/tests/cases/fourslash/completionsImport_default_addToNamespaceImport.ts index 43e3854c5e356..986c255057211 100644 --- a/tests/cases/fourslash/completionsImport_default_addToNamespaceImport.ts +++ b/tests/cases/fourslash/completionsImport_default_addToNamespaceImport.ts @@ -8,7 +8,10 @@ ////f/**/; goTo.marker(""); -verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { includeExternalModuleExports: true }); +verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { + includeExternalModuleExports: true, + sourceDisplay: "./a", +}); verify.applyCodeActionFromCompletion("", { name: "foo", diff --git a/tests/cases/fourslash/completionsImport_default_alreadyExistedWithRename.ts b/tests/cases/fourslash/completionsImport_default_alreadyExistedWithRename.ts index ed34d5e4e9cd4..d8cb53167f5e4 100644 --- a/tests/cases/fourslash/completionsImport_default_alreadyExistedWithRename.ts +++ b/tests/cases/fourslash/completionsImport_default_alreadyExistedWithRename.ts @@ -8,7 +8,10 @@ ////f/**/; goTo.marker(""); -verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { includeExternalModuleExports: true }); +verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { + includeExternalModuleExports: true, + sourceDisplay: "./a", +}); verify.applyCodeActionFromCompletion("", { name: "foo", diff --git a/tests/cases/fourslash/completionsImport_default_anonymous.ts b/tests/cases/fourslash/completionsImport_default_anonymous.ts index 7c0697584f9dc..4be0184d9faf8 100644 --- a/tests/cases/fourslash/completionsImport_default_anonymous.ts +++ b/tests/cases/fourslash/completionsImport_default_anonymous.ts @@ -10,10 +10,14 @@ ////fooB/*1*/ goTo.marker("0"); -verify.not.completionListContains({ name: "default", source: "/src/foo-bar" }, undefined, undefined, undefined, undefined, undefined, { includeExternalModuleExports: true }); +const options = { + includeExternalModuleExports: true, + sourceDisplay: "./foo-bar", +}; +verify.not.completionListContains({ name: "default", source: "/src/foo-bar" }, undefined, undefined, undefined, undefined, undefined, options); goTo.marker("1"); -verify.completionListContains({ name: "fooBar", source: "/src/foo-bar" }, "(property) default: 0", "", "property", /*spanIndex*/ undefined, /*hasAction*/ true, { includeExternalModuleExports: true }); +verify.completionListContains({ name: "fooBar", source: "/src/foo-bar" }, "(property) default: 0", "", "property", /*spanIndex*/ undefined, /*hasAction*/ true, options); verify.applyCodeActionFromCompletion("1", { name: "fooBar", source: "/src/foo-bar", diff --git a/tests/cases/fourslash/completionsImport_default_didNotExistBefore.ts b/tests/cases/fourslash/completionsImport_default_didNotExistBefore.ts index 82b8e92a57030..a36e4336e61f1 100644 --- a/tests/cases/fourslash/completionsImport_default_didNotExistBefore.ts +++ b/tests/cases/fourslash/completionsImport_default_didNotExistBefore.ts @@ -7,7 +7,10 @@ ////f/**/; goTo.marker(""); -verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { includeExternalModuleExports: true }); +verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { + includeExternalModuleExports: true, + sourceDisplay: "./a", +}); verify.applyCodeActionFromCompletion("", { name: "foo", diff --git a/tests/cases/fourslash/completionsImport_matching.ts b/tests/cases/fourslash/completionsImport_matching.ts index f5f9108fa6ce0..d8979e18bd9e6 100644 --- a/tests/cases/fourslash/completionsImport_matching.ts +++ b/tests/cases/fourslash/completionsImport_matching.ts @@ -14,7 +14,7 @@ goTo.marker(""); -const options = { includeExternalModuleExports: true }; +const options = { includeExternalModuleExports: true, sourceDisplay: "./a" }; 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); diff --git a/tests/cases/fourslash/completionsImport_multipleWithSameName.ts b/tests/cases/fourslash/completionsImport_multipleWithSameName.ts index c9bb33d6c79d6..81a054e3d236a 100644 --- a/tests/cases/fourslash/completionsImport_multipleWithSameName.ts +++ b/tests/cases/fourslash/completionsImport_multipleWithSameName.ts @@ -14,10 +14,10 @@ ////fo/**/ goTo.marker(""); -const options = { includeExternalModuleExports: true }; +const options = { includeExternalModuleExports: true, sourceDisplay: undefined }; 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.completionListContains({ name: "foo", source: "/a" }, "const foo: 0", "", "const", /*spanIndex*/ undefined, /*hasAction*/ true, { ...options, sourceDisplay: "./a" }); +verify.completionListContains({ name: "foo", source: "/b" }, "const foo: 1", "", "const", /*spanIndex*/ undefined, /*hasAction*/ true, { ...options, sourceDisplay: "./b" }); verify.applyCodeActionFromCompletion("", { name: "foo", diff --git a/tests/cases/fourslash/completionsImport_named_addToNamedImports.ts b/tests/cases/fourslash/completionsImport_named_addToNamedImports.ts index b11552d032794..8c0beb058fb99 100644 --- a/tests/cases/fourslash/completionsImport_named_addToNamedImports.ts +++ b/tests/cases/fourslash/completionsImport_named_addToNamedImports.ts @@ -9,7 +9,10 @@ ////f/**/; goTo.marker(""); -verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { includeExternalModuleExports: true }); +verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { + includeExternalModuleExports: true, + sourceDisplay: "./a", +}); verify.applyCodeActionFromCompletion("", { name: "foo", diff --git a/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts b/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts index 9397ee004c297..c13fb27f16b64 100644 --- a/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts +++ b/tests/cases/fourslash/completionsImport_named_didNotExistBefore.ts @@ -9,8 +9,8 @@ ////t/**/ goTo.marker(""); -const options = { includeExternalModuleExports: true }; -verify.completionListContains({ name: "Test1", source: "/a" }, "function Test1(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, options); +const options = { includeExternalModuleExports: true, sourceDisplay: undefined }; +verify.completionListContains({ name: "Test1", source: "/a" }, "function Test1(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { ...options, sourceDisplay: "./a" }); verify.completionListContains("Test2", "import Test2", "", "alias", /*spanIndex*/ undefined, /*hasAction*/ undefined, options); verify.not.completionListContains({ name: "Test2", source: "/a" }, undefined, undefined, undefined, undefined, undefined, options); diff --git a/tests/cases/fourslash/completionsImport_named_namespaceImportExists.ts b/tests/cases/fourslash/completionsImport_named_namespaceImportExists.ts index d46027952808c..17b909b48edfd 100644 --- a/tests/cases/fourslash/completionsImport_named_namespaceImportExists.ts +++ b/tests/cases/fourslash/completionsImport_named_namespaceImportExists.ts @@ -8,7 +8,10 @@ ////f/**/; goTo.marker(""); -verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { includeExternalModuleExports: true }); +verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { + includeExternalModuleExports: true, + sourceDisplay: "./a", +}); verify.applyCodeActionFromCompletion("", { name: "foo", diff --git a/tests/cases/fourslash/completionsImport_ofAlias.ts b/tests/cases/fourslash/completionsImport_ofAlias.ts index e7cdb3664974e..69c5041f94fd1 100644 --- a/tests/cases/fourslash/completionsImport_ofAlias.ts +++ b/tests/cases/fourslash/completionsImport_ofAlias.ts @@ -15,7 +15,7 @@ ////fo/**/ goTo.marker(""); -const options = { includeExternalModuleExports: true }; +const options = { includeExternalModuleExports: true, sourceDisplay: "./a" }; // 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); diff --git a/tests/cases/fourslash/completionsImport_previousTokenIsSemicolon.ts b/tests/cases/fourslash/completionsImport_previousTokenIsSemicolon.ts index 93c2cc01b0b44..06fb93283eed7 100644 --- a/tests/cases/fourslash/completionsImport_previousTokenIsSemicolon.ts +++ b/tests/cases/fourslash/completionsImport_previousTokenIsSemicolon.ts @@ -8,4 +8,7 @@ /////**/ goTo.marker(""); -verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { includeExternalModuleExports: true }); +verify.completionListContains({ name: "foo", source: "/a" }, "function foo(): void", "", "function", /*spanIndex*/ undefined, /*hasAction*/ true, { + includeExternalModuleExports: true, + sourceDisplay: "./a", +}); diff --git a/tests/cases/fourslash/completionsImport_require.ts b/tests/cases/fourslash/completionsImport_require.ts index e0a6b00d4622c..8ec750d2c489a 100644 --- a/tests/cases/fourslash/completionsImport_require.ts +++ b/tests/cases/fourslash/completionsImport_require.ts @@ -14,7 +14,10 @@ ////fo/*c*/ goTo.marker("b"); -verify.completionListContains({ name: "foo", source: "/a" }, "const foo: 0", "", "const", /*spanIndex*/ undefined, /*hasAction*/ true, { includeExternalModuleExports: true }); +verify.completionListContains({ name: "foo", source: "/a" }, "const foo: 0", "", "const", /*spanIndex*/ undefined, /*hasAction*/ true, { + includeExternalModuleExports: true, + sourceDisplay: "./a", +}); verify.applyCodeActionFromCompletion("b", { name: "foo", @@ -28,7 +31,10 @@ fo`, }); goTo.marker("c"); -verify.completionListContains({ name: "foo", source: "/a" }, "const foo: 0", "", "const", /*spanIndex*/ undefined, /*hasAction*/ true, { includeExternalModuleExports: true }); +verify.completionListContains({ name: "foo", source: "/a" }, "const foo: 0", "", "const", /*spanIndex*/ undefined, /*hasAction*/ true, { + includeExternalModuleExports: true, + sourceDisplay: "./a", +}); verify.applyCodeActionFromCompletion("c", { name: "foo", diff --git a/tests/cases/fourslash/completionsImport_shadowedByLocal.ts b/tests/cases/fourslash/completionsImport_shadowedByLocal.ts index 20e8c4a4bc812..622f21a2fc77f 100644 --- a/tests/cases/fourslash/completionsImport_shadowedByLocal.ts +++ b/tests/cases/fourslash/completionsImport_shadowedByLocal.ts @@ -8,6 +8,6 @@ ////fo/**/ goTo.marker(""); -const options = { includeExternalModuleExports: true }; +const options = { includeExternalModuleExports: true, sourceDisplay: undefined }; 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 a0ee392a82eba..f5984712648e3 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -148,7 +148,7 @@ declare namespace FourSlashInterface { kind?: string, spanIndex?: number, hasAction?: boolean, - options?: { includeExternalModuleExports: boolean }, + options?: { includeExternalModuleExports: boolean, sourceDisplay: string }, ): void; completionListItemsCountIsGreaterThan(count: number): void; completionListIsEmpty(): void;