Skip to content

Set hasAddedOrRemovedSymlinks when discovering an existing file by its link #46569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/compiler/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1674,8 +1674,8 @@ namespace ts {
const typesReferenceDirectives = map(newSourceFile.typeReferenceDirectives, ref => toFileNameLowerCase(ref.fileName));
const typeReferenceResolutions = resolveTypeReferenceDirectiveNamesWorker(typesReferenceDirectives, newSourceFile);
// ensure that types resolutions are still correct
const typeReferenceEesolutionsChanged = hasChangesInResolutions(typesReferenceDirectives, typeReferenceResolutions, oldSourceFile.resolvedTypeReferenceDirectiveNames, oldSourceFile, typeDirectiveIsEqualTo);
if (typeReferenceEesolutionsChanged) {
const typeReferenceResolutionsChanged = hasChangesInResolutions(typesReferenceDirectives, typeReferenceResolutions, oldSourceFile.resolvedTypeReferenceDirectiveNames, oldSourceFile, typeDirectiveIsEqualTo);
if (typeReferenceResolutionsChanged) {
structureIsReused = StructureIsReused.SafeModules;
newSourceFile.resolvedTypeReferenceDirectiveNames = zipToModeAwareCache(newSourceFile, typesReferenceDirectives, typeReferenceResolutions);
}
Expand Down
11 changes: 11 additions & 0 deletions src/compiler/resolutionCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ namespace ts {
getCurrentProgram(): Program | undefined;
fileIsOpen(filePath: Path): boolean;
getCompilerHost?(): CompilerHost | undefined;
onDiscoveredSymlink?(): void;
}

interface DirectoryWatchesOfFailedLookup {
Expand Down Expand Up @@ -431,6 +432,9 @@ namespace ts {
else {
resolution = loader(name, containingFile, compilerOptions, resolutionHost.getCompilerHost?.() || resolutionHost, redirectedReference, containingSourceFile);
perDirectoryResolution.set(name, mode, resolution);
if (resolutionHost.onDiscoveredSymlink && resolutionIsSymlink(resolution)) {
resolutionHost.onDiscoveredSymlink();
}
}
resolutionsInFile.set(name, mode, resolution);
watchFailedLookupLocationsOfExternalModuleResolutions(name, resolution, path, getResolutionWithResolvedFileName);
Expand Down Expand Up @@ -965,4 +969,11 @@ namespace ts {
return dirPath === rootPath || canWatchDirectory(dirPath);
}
}

function resolutionIsSymlink(resolution: ResolutionWithFailedLookupLocations) {
return !!(
(resolution as ResolvedModuleWithFailedLookupLocations).resolvedModule?.originalPath ||
(resolution as ResolvedTypeReferenceDirectiveWithFailedLookupLocations).resolvedTypeReferenceDirective?.originalPath
);
}
}
5 changes: 5 additions & 0 deletions src/server/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,11 @@ namespace ts.server {
}
}

/* @internal */
onDiscoveredSymlink() {
this.hasAddedOrRemovedSymlinks = true;
}

/**
* Updates set of files that contribute to this project
* @returns: true if set of files in the project stays the same and false - otherwise.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/// <reference path="../fourslash.ts" />

// Notable lack of package.json referencing `mylib` as dependency here.
// This is not accurate to the original repro, but I think that's a separate
// bug, which, if fixed, would prevent the later crash.
Comment on lines +3 to +5
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to follow up on this separately

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe link to the repro? Or provide an issue #.


// @Filename: /tsconfig.json
//// { "compilerOptions": { "module": "commonjs" } }

// @Filename: /packages/mylib/package.json
//// { "name": "mylib", "version": "1.0.0", "main": "index.js" }

// @Filename: /packages/mylib/index.ts
//// export * from "./mySubDir";

// @Filename: /packages/mylib/mySubDir/index.ts
//// export * from "./myClass";
//// export * from "./myClass2";

// @Filename: /packages/mylib/mySubDir/myClass.ts
//// export class MyClass {}

// @Filename: /packages/mylib/mySubDir/myClass2.ts
//// export class MyClass2 {}

// @link: /packages/mylib -> /node_modules/mylib

// @Filename: /src/index.ts
////
//// const a = new MyClass/*1*/();
//// const b = new MyClass2/*2*/();

goTo.marker("1");
format.setOption("newLineCharacter", "\n");

verify.completions({
marker: "1",
includes: [{
name: "MyClass",
source: "../packages/mylib",
sourceDisplay: "../packages/mylib",
hasAction: true,
sortText: completion.SortText.AutoImportSuggestions,
}],
preferences: {
includeCompletionsForModuleExports: true,
includeInsertTextCompletions: true,
allowIncompleteCompletions: true,
}
});

verify.applyCodeActionFromCompletion("1", {
name: "MyClass",
source: "../packages/mylib",
description: `Import 'MyClass' from module "../packages/mylib"`,
data: {
exportName: "MyClass",
fileName: "/packages/mylib/index.ts",
},
preferences: {
includeCompletionsForModuleExports: true,
includeCompletionsWithInsertText: true,
allowIncompleteCompletions: true,
},
newFileContent: `import { MyClass } from "../packages/mylib";

const a = new MyClass();
const b = new MyClass2();`,
});

edit.replaceLine(0, `import { MyClass } from "mylib";`);

verify.completions({
marker: "2",
includes: [{
name: "MyClass2",
source: "mylib",
sourceDisplay: "mylib",
hasAction: true,
sortText: completion.SortText.AutoImportSuggestions,
}],
preferences: {
includeCompletionsForModuleExports: true,
includeInsertTextCompletions: true,
allowIncompleteCompletions: true,
}
});