Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
WIP
  • Loading branch information
gabritto committed Feb 14, 2022
commit 9acc88f852ec2e1333f1cc0caf36b7856670aff9
45 changes: 44 additions & 1 deletion src/server/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ namespace ts.server {
hostPreferences: UserPreferences
): readonly RenameLocation[] {
const outputs: RenameLocation[] = [];
combineProjectOutputWorker(
combineProjectOutputRenameWorker(
projects,
defaultProject,
initialLocation,
Expand Down Expand Up @@ -499,6 +499,49 @@ namespace ts.server {
}
}

function combineProjectOutputRenameWorker<TLocation extends DocumentPosition | undefined>(
projects: Projects,
defaultProject: Project,
initialLocation: TLocation,
cb: CombineProjectOutputCallback<TLocation>
): void {
const projectService = defaultProject.projectService;
let toDo: ProjectAndLocation<TLocation>[] | undefined;
const seenProjects = new Set<string>();
forEachProjectInProjects(projects, initialLocation && initialLocation.fileName, (project, path) => {
// TLocation should be either `DocumentPosition` or `undefined`. Since `initialLocation` is `TLocation` this cast should be valid.
const location = (initialLocation ? { fileName: path, pos: initialLocation.pos } : undefined) as TLocation;
toDo = callbackProjectAndLocation(project, location, projectService, toDo, seenProjects, cb);
});

// After initial references are collected, go over every other project and see if it has a reference for the symbol definition.
// if (initialLocation) {
// const defaultDefinition = getDefinitionLocation(defaultProject, initialLocation);
// if (defaultDefinition) {
// const getGeneratedDefinition = memoize(() => defaultProject.isSourceOfProjectReferenceRedirect(defaultDefinition.fileName) ?
// defaultDefinition :
// defaultProject.getLanguageService().getSourceMapper().tryGetGeneratedPosition(defaultDefinition));
// const getSourceDefinition = memoize(() => defaultProject.isSourceOfProjectReferenceRedirect(defaultDefinition.fileName) ?
// defaultDefinition :
// defaultProject.getLanguageService().getSourceMapper().tryGetSourcePosition(defaultDefinition));
// projectService.loadAncestorProjectTree(seenProjects);
// projectService.forEachEnabledProject(project => {
// if (!addToSeen(seenProjects, project)) return;
// const definition = mapDefinitionInProject(defaultDefinition, project, getGeneratedDefinition, getSourceDefinition);
// if (definition) {
// toDo = callbackProjectAndLocation<TLocation>(project, definition as TLocation, projectService, toDo, seenProjects, cb);
// }
// });
// }
// }

while (toDo && toDo.length) {
const next = toDo.pop();
Debug.assertIsDefined(next);
toDo = callbackProjectAndLocation(next.project, next.location, projectService, toDo, seenProjects, cb);
}
}

function mapDefinitionInProject(
definition: DocumentPosition,
project: Project,
Expand Down
12 changes: 12 additions & 0 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1814,6 +1814,18 @@ namespace ts {
}
}

// function findRenameDefinition(fileName: string, position: number): DocumentPosition | undefined {
// const sourceFile = getValidSourceFile(fileName);
// const node = getAdjustedRenameLocation(getTouchingPropertyName(sourceFile, position));
// if (!Rename.nodeIsEligibleForRename(node)) return undefined;
// if (false) {
// // return something else
// }
// const infos = getDefinitionAtPosition(fileName, position);
// const info = infos && firstOrUndefined(infos);
// return info && !info.isLocal ? { fileName: info.fileName, pos: info.textSpan.start } : undefined;
// }

function getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[] | undefined {
synchronizeHostData();
return getReferencesWorker(getTouchingPropertyName(getValidSourceFile(fileName), position), position, { use: FindAllReferences.FindReferencesUse.References }, (entry, node, checker) => FindAllReferences.toReferenceEntry(entry, checker.getSymbolAtLocation(node)));
Expand Down
24 changes: 24 additions & 0 deletions tests/cases/fourslash/server/renameNamespaceImport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/// <reference path='../fourslash.ts' />

// @Filename: /lib/tsconfig.json
//// {}

// @Filename: /lib/index.ts
//// const [|unrelatedLocalVariable|] = 123;
//// export const someExportedVariable = unrelatedLocalVariable;

// @Filename: /src/tsconfig.json
//// {}

// @Filename: /src/index.ts
//// import * as /*i*/[|lib|] from '../lib/index';
//// lib.someExportedVariable;


// @Filename: /tsconfig.json
//// {}

// const [unrelated, rename] = test.ranges();
goTo.file("/lib/index.ts");
goTo.file("/src/index.ts");
verify.baselineRename("i", {});