Merge pull request #13287 from zhengbli/importFixExtendedTsconfig
For `path` ending with `index`, use the `path` pattern for the import quick fix
This commit is contained in:
commit
9a62db2b5c
|
@ -262,23 +262,12 @@ namespace FourSlash {
|
|||
// Initialize the language service with all the scripts
|
||||
let startResolveFileRef: FourSlashFile;
|
||||
|
||||
let configFileName: string;
|
||||
ts.forEach(testData.files, file => {
|
||||
// Create map between fileName and its content for easily looking up when resolveReference flag is specified
|
||||
this.inputFiles[file.fileName] = file.content;
|
||||
|
||||
if (ts.getBaseFileName(file.fileName).toLowerCase() === "tsconfig.json") {
|
||||
const configJson = ts.parseConfigFileTextToJson(file.fileName, file.content);
|
||||
assert.isTrue(configJson.config !== undefined);
|
||||
|
||||
// Extend our existing compiler options so that we can also support tsconfig only options
|
||||
if (configJson.config.compilerOptions) {
|
||||
const baseDirectory = ts.normalizePath(ts.getDirectoryPath(file.fileName));
|
||||
const tsConfig = ts.convertCompilerOptionsFromJson(configJson.config.compilerOptions, baseDirectory, file.fileName);
|
||||
|
||||
if (!tsConfig.errors || !tsConfig.errors.length) {
|
||||
compilationOptions = ts.extend(compilationOptions, tsConfig.options);
|
||||
}
|
||||
}
|
||||
configFileName = file.fileName;
|
||||
}
|
||||
|
||||
if (!startResolveFileRef && file.fileOptions[metadataOptionNames.resolveReference] === "true") {
|
||||
|
@ -290,6 +279,21 @@ namespace FourSlash {
|
|||
}
|
||||
});
|
||||
|
||||
if (configFileName) {
|
||||
const baseDir = ts.normalizePath(ts.getDirectoryPath(configFileName));
|
||||
const host = new Utils.MockParseConfigHost(baseDir, /*ignoreCase*/ false, this.inputFiles);
|
||||
|
||||
const configJsonObj = ts.parseConfigFileTextToJson(configFileName, this.inputFiles[configFileName]);
|
||||
assert.isTrue(configJsonObj.config !== undefined);
|
||||
|
||||
const { options, errors } = ts.parseJsonConfigFileContent(configJsonObj.config, host, baseDir);
|
||||
|
||||
// Extend our existing compiler options so that we can also support tsconfig only options
|
||||
if (!errors || errors.length === 0) {
|
||||
compilationOptions = ts.extend(compilationOptions, options);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (compilationOptions.typeRoots) {
|
||||
compilationOptions.typeRoots = compilationOptions.typeRoots.map(p => ts.getNormalizedAbsolutePath(p, this.basePath));
|
||||
|
|
|
@ -443,6 +443,7 @@ namespace ts.codefix {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
const relativeNameWithIndex = removeFileExtension(relativeName);
|
||||
relativeName = removeExtensionAndIndexPostFix(relativeName);
|
||||
|
||||
if (options.paths) {
|
||||
|
@ -462,7 +463,7 @@ namespace ts.codefix {
|
|||
return key.replace("\*", matchedStar);
|
||||
}
|
||||
}
|
||||
else if (pattern === relativeName) {
|
||||
else if (pattern === relativeName || pattern === relativeNameWithIndex) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
|
28
tests/cases/fourslash/importNameCodeFixNewImportPaths2.ts
Normal file
28
tests/cases/fourslash/importNameCodeFixNewImportPaths2.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
/// <reference path="fourslash.ts" />
|
||||
|
||||
//// [|foo/*0*/();|]
|
||||
|
||||
// @Filename: folder_b/index.ts
|
||||
//// export function foo() {};
|
||||
|
||||
// @Filename: tsconfig.path.json
|
||||
//// {
|
||||
//// "compilerOptions": {
|
||||
//// "baseUrl": ".",
|
||||
//// "paths": {
|
||||
//// "b": [ "folder_b/index" ]
|
||||
//// }
|
||||
//// }
|
||||
//// }
|
||||
|
||||
// @Filename: tsconfig.json
|
||||
//// {
|
||||
//// "extends": "./tsconfig.path",
|
||||
//// "compilerOptions": { }
|
||||
//// }
|
||||
|
||||
verify.importFixAtPosition([
|
||||
`import { foo } from "b";
|
||||
|
||||
foo();`
|
||||
]);
|
Loading…
Reference in a new issue