Skip to content

Commit 5b86055

Browse files
author
Armando Aguirre
committed
Excluded the default library from rename service.
1 parent 80a7ed9 commit 5b86055

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

src/compiler/program.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ namespace ts {
555555
getFileProcessingDiagnostics: () => fileProcessingDiagnostics,
556556
getResolvedTypeReferenceDirectives: () => resolvedTypeReferenceDirectives,
557557
isSourceFileFromExternalLibrary,
558+
isSourceFileDefaultLibrary,
558559
dropDiagnosticsProducingTypeChecker,
559560
getSourceFileFromReference,
560561
sourceFileToPackageName,
@@ -975,6 +976,10 @@ namespace ts {
975976
return sourceFilesFoundSearchingNodeModules.get(file.path);
976977
}
977978

979+
function isSourceFileDefaultLibrary(file: SourceFile): boolean {
980+
return file.fileName === host.getDefaultLibFileName(options);
981+
}
982+
978983
function getDiagnosticsProducingTypeChecker() {
979984
return diagnosticsProducingTypeChecker || (diagnosticsProducingTypeChecker = createTypeChecker(program, /*produceDiagnostics:*/ true));
980985
}

src/compiler/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2452,6 +2452,7 @@ namespace ts {
24522452
/* @internal */ getFileProcessingDiagnostics(): DiagnosticCollection;
24532453
/* @internal */ getResolvedTypeReferenceDirectives(): Map<ResolvedTypeReferenceDirective>;
24542454
/* @internal */ isSourceFileFromExternalLibrary(file: SourceFile): boolean;
2455+
/* @internal */ isSourceFileDefaultLibrary(file: SourceFile): boolean;
24552456
// For testing purposes only.
24562457
/* @internal */ structureIsReused?: StructureIsReused;
24572458

src/services/services.ts

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ namespace ts {
670670
if (!hasModifier(node, ModifierFlags.ParameterPropertyModifier)) {
671671
break;
672672
}
673-
// falls through
673+
// falls through
674674
case SyntaxKind.VariableDeclaration:
675675
case SyntaxKind.BindingElement: {
676676
const decl = <VariableDeclaration>node;
@@ -682,7 +682,7 @@ namespace ts {
682682
visit(decl.initializer);
683683
}
684684
}
685-
// falls through
685+
// falls through
686686
case SyntaxKind.EnumMember:
687687
case SyntaxKind.PropertyDeclaration:
688688
case SyntaxKind.PropertySignature:
@@ -729,7 +729,7 @@ namespace ts {
729729

730730
class SourceMapSourceObject implements SourceMapSource {
731731
lineMap: number[];
732-
constructor (public fileName: string, public text: string, public skipTrivia?: (pos: number) => number) {}
732+
constructor(public fileName: string, public text: string, public skipTrivia?: (pos: number) => number) { }
733733

734734
public getLineAndCharacterOfPosition(pos: number): LineAndCharacter {
735735
return ts.getLineAndCharacterOfPosition(this, pos);
@@ -1130,14 +1130,14 @@ namespace ts {
11301130
const newSettings = hostCache.compilationSettings();
11311131
const shouldCreateNewSourceFiles = oldSettings &&
11321132
(oldSettings.target !== newSettings.target ||
1133-
oldSettings.module !== newSettings.module ||
1134-
oldSettings.moduleResolution !== newSettings.moduleResolution ||
1135-
oldSettings.noResolve !== newSettings.noResolve ||
1136-
oldSettings.jsx !== newSettings.jsx ||
1137-
oldSettings.allowJs !== newSettings.allowJs ||
1138-
oldSettings.disableSizeLimit !== oldSettings.disableSizeLimit ||
1139-
oldSettings.baseUrl !== newSettings.baseUrl ||
1140-
!equalOwnProperties(oldSettings.paths, newSettings.paths));
1133+
oldSettings.module !== newSettings.module ||
1134+
oldSettings.moduleResolution !== newSettings.moduleResolution ||
1135+
oldSettings.noResolve !== newSettings.noResolve ||
1136+
oldSettings.jsx !== newSettings.jsx ||
1137+
oldSettings.allowJs !== newSettings.allowJs ||
1138+
oldSettings.disableSizeLimit !== oldSettings.disableSizeLimit ||
1139+
oldSettings.baseUrl !== newSettings.baseUrl ||
1140+
!equalOwnProperties(oldSettings.paths, newSettings.paths));
11411141

11421142
// Now create a new compiler
11431143
const compilerHost: CompilerHost = {
@@ -1365,7 +1365,7 @@ namespace ts {
13651365
function getCompilerOptionsDiagnostics() {
13661366
synchronizeHostData();
13671367
return program.getOptionsDiagnostics(cancellationToken).concat(
1368-
program.getGlobalDiagnostics(cancellationToken));
1368+
program.getGlobalDiagnostics(cancellationToken));
13691369
}
13701370

13711371
function getCompletionsAtPosition(fileName: string, position: number): CompletionInfo {
@@ -1510,7 +1510,20 @@ namespace ts {
15101510

15111511
function getReferences(fileName: string, position: number, options?: FindAllReferences.Options) {
15121512
synchronizeHostData();
1513-
return FindAllReferences.findReferencedEntries(program, cancellationToken, program.getSourceFiles(), getValidSourceFile(fileName), position, options);
1513+
1514+
//Exclude default library when renaming as commonly user don't want to change that file.
1515+
let sourceFiles: SourceFile[] = [];
1516+
if (options.isForRename) {
1517+
for (let sourceFile of program.getSourceFiles()) {
1518+
if (!program.isSourceFileDefaultLibrary(sourceFile)) {
1519+
sourceFiles.push(sourceFile);
1520+
}
1521+
}
1522+
} else {
1523+
sourceFiles = program.getSourceFiles();
1524+
}
1525+
1526+
return FindAllReferences.findReferencedEntries(program, cancellationToken, sourceFiles, getValidSourceFile(fileName), position, options);
15141527
}
15151528

15161529
function findReferences(fileName: string, position: number): ReferencedSymbol[] {
@@ -2100,7 +2113,7 @@ namespace ts {
21002113
isLiteralComputedPropertyDeclarationName(node);
21012114
}
21022115

2103-
function isObjectLiteralElement(node: Node): node is ObjectLiteralElement {
2116+
function isObjectLiteralElement(node: Node): node is ObjectLiteralElement {
21042117
switch (node.kind) {
21052118
case SyntaxKind.JsxAttribute:
21062119
case SyntaxKind.JsxSpreadAttribute:
@@ -2125,7 +2138,7 @@ namespace ts {
21252138
if (node.parent.kind === SyntaxKind.ComputedPropertyName) {
21262139
return isObjectLiteralElement(node.parent.parent) ? node.parent.parent : undefined;
21272140
}
2128-
// falls through
2141+
// falls through
21292142
case SyntaxKind.Identifier:
21302143
return isObjectLiteralElement(node.parent) &&
21312144
(node.parent.parent.kind === SyntaxKind.ObjectLiteralExpression || node.parent.parent.kind === SyntaxKind.JsxAttributes) &&

0 commit comments

Comments
 (0)