mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-12-12 03:20:56 -06:00
Allow autoImportFileExcludePatterns to match anywhere in the file path (#57090)
This commit is contained in:
parent
6cb6fc94ae
commit
9ba8c7a51c
@ -9140,7 +9140,8 @@ export const commonPackageFolders: readonly string[] = ["node_modules", "bower_c
|
||||
|
||||
const implicitExcludePathRegexPattern = `(?!(${commonPackageFolders.join("|")})(/|$))`;
|
||||
|
||||
interface WildcardMatcher {
|
||||
/** @internal */
|
||||
export interface WildcardMatcher {
|
||||
singleAsteriskRegexFragment: string;
|
||||
doubleAsteriskRegexFragment: string;
|
||||
replaceWildcardCharacter: (match: string) => string;
|
||||
@ -9222,7 +9223,13 @@ export function getPatternFromSpec(spec: string, basePath: string, usage: "files
|
||||
return pattern && `^(${pattern})${usage === "exclude" ? "($|/)" : "$"}`;
|
||||
}
|
||||
|
||||
function getSubPatternFromSpec(spec: string, basePath: string, usage: "files" | "directories" | "exclude", { singleAsteriskRegexFragment, doubleAsteriskRegexFragment, replaceWildcardCharacter }: WildcardMatcher): string | undefined {
|
||||
/** @internal */
|
||||
export function getSubPatternFromSpec(
|
||||
spec: string,
|
||||
basePath: string,
|
||||
usage: "files" | "directories" | "exclude",
|
||||
{ singleAsteriskRegexFragment, doubleAsteriskRegexFragment, replaceWildcardCharacter }: WildcardMatcher = wildcardMatchers[usage],
|
||||
): string | undefined {
|
||||
let subpattern = "";
|
||||
let hasWrittenComponent = false;
|
||||
const components = getNormalizedPathComponents(spec, basePath);
|
||||
|
||||
@ -21,8 +21,8 @@ import {
|
||||
getNamesForExportedSymbol,
|
||||
getNodeModulePathParts,
|
||||
getPackageNameFromTypesPackageName,
|
||||
getPatternFromSpec,
|
||||
getRegexFromPattern,
|
||||
getSubPatternFromSpec,
|
||||
getSymbolId,
|
||||
hostGetCanonicalFileName,
|
||||
hostUsesCaseSensitiveFileNames,
|
||||
@ -425,7 +425,7 @@ export function forEachExternalModuleToImportFrom(
|
||||
const excludePatterns = preferences.autoImportFileExcludePatterns && mapDefined(preferences.autoImportFileExcludePatterns, spec => {
|
||||
// The client is expected to send rooted path specs since we don't know
|
||||
// what directory a relative path is relative to.
|
||||
const pattern = getPatternFromSpec(spec, "", "exclude");
|
||||
const pattern = getSubPatternFromSpec(spec, "", "exclude");
|
||||
return pattern ? getRegexFromPattern(pattern, useCaseSensitiveFileNames) : undefined;
|
||||
});
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,31 @@
|
||||
/// <reference path="../fourslash.ts"/>
|
||||
|
||||
// @module: commonjs
|
||||
|
||||
// @Filename: /project/node_modules/aws-sdk/package.json
|
||||
//// { "name": "aws-sdk", "version": "2.0.0", "main": "index.js" }
|
||||
|
||||
// @Filename: /project/node_modules/aws-sdk/index.d.ts
|
||||
//// export * from "./clients/s3";
|
||||
|
||||
// @Filename: /project/node_modules/aws-sdk/clients/s3.d.ts
|
||||
//// export declare class S3 {}
|
||||
|
||||
// @Filename: /project/package.json
|
||||
//// { "dependencies": { "aws-sdk": "*" } }
|
||||
|
||||
// @Filename: /project/index.ts
|
||||
//// S3/**/
|
||||
|
||||
const autoImportFileExcludePatterns = ["**/node_modules/aws-sdk"];
|
||||
|
||||
verify.completions({
|
||||
marker: "",
|
||||
excludes: "S3",
|
||||
preferences: {
|
||||
includeCompletionsForModuleExports: true,
|
||||
autoImportFileExcludePatterns,
|
||||
}
|
||||
});
|
||||
|
||||
verify.importFixAtPosition([], /*errorCode*/ undefined, { autoImportFileExcludePatterns });
|
||||
@ -0,0 +1,31 @@
|
||||
/// <reference path="../fourslash.ts"/>
|
||||
|
||||
// @module: commonjs
|
||||
|
||||
// @Filename: //tsclient/project/node_modules/aws-sdk/package.json
|
||||
//// { "name": "aws-sdk", "version": "2.0.0", "main": "index.js" }
|
||||
|
||||
// @Filename: //tsclient/project/node_modules/aws-sdk/index.d.ts
|
||||
//// export * from "./clients/s3";
|
||||
|
||||
// @Filename: //tsclient/project/node_modules/aws-sdk/clients/s3.d.ts
|
||||
//// export declare class S3 {}
|
||||
|
||||
// @Filename: //tsclient/project/package.json
|
||||
//// { "dependencies": { "aws-sdk": "*" } }
|
||||
|
||||
// @Filename: //tsclient/project/index.ts
|
||||
//// S3/**/
|
||||
|
||||
const autoImportFileExcludePatterns = ["\\\\tsclient\\project\\node_modules\\aws-sdk"];
|
||||
|
||||
verify.completions({
|
||||
marker: "",
|
||||
excludes: "S3",
|
||||
preferences: {
|
||||
includeCompletionsForModuleExports: true,
|
||||
autoImportFileExcludePatterns,
|
||||
}
|
||||
});
|
||||
|
||||
verify.importFixAtPosition([], /*errorCode*/ undefined, { autoImportFileExcludePatterns });
|
||||
@ -0,0 +1,31 @@
|
||||
/// <reference path="../fourslash.ts"/>
|
||||
|
||||
// @module: commonjs
|
||||
|
||||
// @Filename: c:/project/node_modules/aws-sdk/package.json
|
||||
//// { "name": "aws-sdk", "version": "2.0.0", "main": "index.js" }
|
||||
|
||||
// @Filename: c:/project/node_modules/aws-sdk/index.d.ts
|
||||
//// export * from "./clients/s3";
|
||||
|
||||
// @Filename: c:/project/node_modules/aws-sdk/clients/s3.d.ts
|
||||
//// export declare class S3 {}
|
||||
|
||||
// @Filename: c:/project/package.json
|
||||
//// { "dependencies": { "aws-sdk": "*" } }
|
||||
|
||||
// @Filename: c:/project/index.ts
|
||||
//// S3/**/
|
||||
|
||||
const autoImportFileExcludePatterns = ["**\\node_modules\\aws-sdk"];
|
||||
|
||||
verify.completions({
|
||||
marker: "",
|
||||
excludes: "S3",
|
||||
preferences: {
|
||||
includeCompletionsForModuleExports: true,
|
||||
autoImportFileExcludePatterns,
|
||||
}
|
||||
});
|
||||
|
||||
verify.importFixAtPosition([], /*errorCode*/ undefined, { autoImportFileExcludePatterns });
|
||||
Loading…
x
Reference in New Issue
Block a user