Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
81ec4fd
Prototype resolving to JS when go-to-def aliases all resolve to ambie…
andrewbranch Feb 25, 2022
422d845
Add test infrastructure
andrewbranch Mar 1, 2022
1b43352
Start fleshing out test coverage
andrewbranch Mar 2, 2022
7aeb92f
Fix some go-to-def stuff
andrewbranch Mar 8, 2022
f2915e6
Finish lodash test case
andrewbranch Mar 10, 2022
309c4bb
Make go-to-implementation never return ambient results
andrewbranch Mar 10, 2022
381799d
Build new functionality into go-to-implementation
andrewbranch Mar 11, 2022
0727702
Update baselines
andrewbranch Mar 11, 2022
ebeda0b
Two more test cases
andrewbranch Mar 14, 2022
03ea413
Refine definition searches for unresolved imports
andrewbranch Mar 14, 2022
e5556b8
Revert "Build new functionality into go-to-implementation"
andrewbranch Mar 14, 2022
6104a5c
Fix tests
andrewbranch Mar 14, 2022
bea3de0
Merge branch 'main' into go-to-js
andrewbranch Mar 14, 2022
4e64659
Revert go-to-implementation changes
andrewbranch Mar 14, 2022
1cb2ba6
Wow a bunch of code was unnecessary
andrewbranch Mar 14, 2022
7e57890
Update baselines and go-to-def test
andrewbranch Mar 15, 2022
43c01e2
Fix navigation on symbols that are not aliases but resolve through al…
andrewbranch Mar 16, 2022
34c6cfd
Temporarily replace go-to-def with new command implementation
andrewbranch Mar 15, 2022
7357593
Revert "Temporarily replace go-to-def with new command implementation"
andrewbranch Mar 16, 2022
d14e43d
Revert "Wow a bunch of code was unnecessary"
andrewbranch Mar 21, 2022
4e1cf1c
Bring back some deleted code needed for a new test case
andrewbranch Mar 21, 2022
52a79d5
Clean up a little
andrewbranch Mar 22, 2022
e011f2d
Rename more stuff
andrewbranch Mar 22, 2022
05cfd27
Update test
andrewbranch Mar 22, 2022
b95f496
Update API baseline
andrewbranch Mar 22, 2022
b883898
Temporarily replace go-to-def with new command implementation
andrewbranch Mar 15, 2022
373bca2
PR review fixes
andrewbranch Apr 4, 2022
c05adbd
Merge branch 'main' into go-to-js
andrewbranch Apr 4, 2022
3a85dc8
Fix getTopMostDeclarationNamesInFile
andrewbranch Apr 4, 2022
7dd9db8
Rename local
andrewbranch Apr 4, 2022
0f3b29c
Use hash set
andrewbranch Apr 4, 2022
234c139
Remove option from commandLineParser
andrewbranch Apr 4, 2022
92ff999
Merge branch 'main' into go-to-js
andrewbranch Apr 6, 2022
1698930
Keep noDtsResolution project around
andrewbranch Apr 7, 2022
859ed79
Handle AuxiliaryProject kind in ScriptInfo getDefaultProject etc.
andrewbranch Apr 7, 2022
7be215a
Do not run updateGraph in the background for AuxiliaryProject
andrewbranch Apr 7, 2022
8f4e622
Don’t create auxiliary project outside of semantic mode
andrewbranch Apr 7, 2022
d633356
No-op on scheduled invalidation
andrewbranch Apr 7, 2022
b89b7cb
Add comments to unit test
andrewbranch Apr 7, 2022
a59024c
Sync compiler options to auxiliary project
andrewbranch Apr 7, 2022
7f290bb
Fix case sensitivity
andrewbranch Apr 7, 2022
c5bddbe
Update extensionIsOk with new file extensions
andrewbranch Apr 7, 2022
24c0d8a
PR feedback
andrewbranch Apr 13, 2022
f6bd9d8
Update API baseline
andrewbranch Apr 13, 2022
2cb2048
Mark scheduleInvalidateResolutionsOfFailedLookupLocations internal
andrewbranch Apr 13, 2022
f9f4592
Use same heuristics on property accesses of loosely-resolvable aliase…
andrewbranch Apr 14, 2022
e302f56
Rename command, and no need to return the bound span
andrewbranch Apr 14, 2022
3f15ed3
Update API baseline
andrewbranch Apr 14, 2022
f80c9ef
Merge branch 'main' into go-to-js
andrewbranch Apr 14, 2022
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
Prev Previous commit
Next Next commit
Wow a bunch of code was unnecessary
  • Loading branch information
andrewbranch committed Mar 14, 2022
commit 1cb2ba646c9e80d1ca08b6fc3f6a2219aac44f67
92 changes: 0 additions & 92 deletions src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1255,32 +1255,6 @@ namespace ts.server {
pushIfUnique(definitions, jsDefinition, documentSpansEqual);
}
}
else {
const ambientCandidates = definitions.filter(d => d.isAliasTarget && d.isAmbient);
for (const candidate of ambientCandidates) {
const candidateFileName = getEffectiveFileNameOfDefinition(candidate, project.getLanguageService().getProgram()!);
if (candidateFileName) {
const fileNameToSearch = findImplementationFileFromDtsFileName(candidateFileName, file, auxiliaryProject);
const scriptInfo = fileNameToSearch ? auxiliaryProject.getScriptInfo(fileNameToSearch) : undefined;
if (!scriptInfo) {
continue;
}
if (!auxiliaryProject.containsScriptInfo(scriptInfo)) {
auxiliaryProject.addRoot(scriptInfo);
}
const auxiliaryProgram = auxiliaryProject.getLanguageService().getProgram()!;
const fileToSearch = Debug.checkDefined(auxiliaryProgram.getSourceFile(fileNameToSearch!));
const matches = FindAllReferences.Core.getTopMostDeclarationNamesInFile(candidate.name, fileToSearch);
for (const match of matches) {
const symbol = match.symbol || auxiliaryProgram.getTypeChecker().getSymbolAtLocation(match);
const decl = getDeclarationFromName(match);
if (symbol && decl) {
pushIfUnique(definitions, GoToDefinition.createDefinitionInfo(decl, auxiliaryProgram.getTypeChecker(), symbol, match));
}
}
}
}
}
});
}

Expand All @@ -1299,72 +1273,6 @@ namespace ts.server {
textSpan,
};

function getEffectiveFileNameOfDefinition(definition: DefinitionInfo, program: Program) {
const sourceFile = program.getSourceFile(definition.fileName)!;
const checker = program.getTypeChecker();
const symbol = checker.getSymbolAtLocation(getTouchingPropertyName(sourceFile, definition.textSpan.start));
if (symbol) {
let parent = symbol.parent;
while (parent && !isExternalModuleSymbol(parent)) {
parent = parent.parent;
}
if (parent?.declarations && some(parent.declarations, isExternalModuleAugmentation)) {
// Always CommonJS right now, but who knows in the future
const mode = getModeForUsageLocation(sourceFile, find(parent.declarations, isExternalModuleAugmentation)!.name as StringLiteral);
const fileName = sourceFile.resolvedModules?.get(stripQuotes(parent.name), mode)?.resolvedFileName;
if (fileName) {
return fileName;
}
}
const fileName = tryCast(parent?.valueDeclaration, isSourceFile)?.fileName;
if (fileName) {
return fileName;
}
}
}

function findImplementationFileFromDtsFileName(fileName: string, resolveFromFile: string, auxiliaryProject: Project) {
const nodeModulesPathParts = getNodeModulePathParts(fileName);
if (nodeModulesPathParts && fileName.lastIndexOf(nodeModulesPathPart) === nodeModulesPathParts.topLevelNodeModulesIndex) {
// Second check ensures the fileName only contains one `/node_modules/`. If there's more than one I give up.
const packageDirectory = fileName.substring(0, nodeModulesPathParts.packageRootIndex);
const packageJsonCache = project.getModuleResolutionCache()?.getPackageJsonInfoCache();
const compilerOptions = project.getCompilationSettings();
const packageJson = getPackageScopeForPath(project.toPath(packageDirectory + "/package.json"), packageJsonCache, project, compilerOptions);
if (!packageJson) return undefined;
// Use fake options instead of actual compiler options to avoid following export map if the project uses node12 or nodenext -
// Mapping from an export map entry across packages is out of scope for now. Returned entrypoints will only be what can be
// resolved from the package root under --moduleResolution node
const entrypoints = getEntrypointsFromPackageJsonInfo(
packageJson,
{ moduleResolution: ModuleResolutionKind.NodeJs },
project,
project.getModuleResolutionCache());
// This substring is correct only because we checked for a single `/node_modules/` at the top.
const packageNamePathPart = fileName.substring(
nodeModulesPathParts.topLevelPackageNameIndex + 1,
nodeModulesPathParts.packageRootIndex);
const packageName = getPackageNameFromTypesPackageName(unmangleScopedPackageName(packageNamePathPart));
const path = project.toPath(fileName);
if (entrypoints && some(entrypoints, e => project.toPath(e) === path)) {
// This file was the main entrypoint of a package. Try to resolve that same package name with
// the auxiliary project that only resolves to implementation files.
const [implementationResolution] = auxiliaryProject.resolveModuleNames([packageName], resolveFromFile);
return implementationResolution?.resolvedFileName;
}
else {
// It wasn't the main entrypoint but we are in node_modules. Try a subpath into the package.
const pathToFileInPackage = fileName.substring(nodeModulesPathParts.packageRootIndex + 1);
const specifier = `${packageName}/${removeFileExtension(pathToFileInPackage)}`;
const [implementationResolution] = auxiliaryProject.resolveModuleNames([specifier], resolveFromFile);
return implementationResolution?.resolvedFileName;
}
}
// We're not in node_modules, and we only get to this function if non-dts module resolution failed.
// I'm not sure what else I can do here that isn't already covered by that module resolution.
return undefined;
}

function tryRefineDefinition(definition: DefinitionInfo, program: Program, auxiliaryProgram: Program) {
const fileToSearch = auxiliaryProgram.getSourceFile(definition.fileName);
if (!fileToSearch) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,6 @@


// @Filename: /index.ts
//// import { /*start*/add } from 'lodash';
//// import { [|/*start*/add|] } from 'lodash';

verify.goToSourceDefinition("start", ["variable", "property"]);