Conversation
| const { scopes, readsAndWrites: { errorsPerScope } } = getPossibleExtractionsWorker(targetRange, context); | ||
| // Need the inner type annotation to avoid https://github.com/Microsoft/TypeScript/issues/7547 | ||
| return scopes.map((scope, i): PossibleExtraction => { | ||
| const errors = errorsPerScope[i]; |
| Debug.assert(fileName === renameFilename); | ||
| for (const change of textChanges) { | ||
| const { span, newText } = change; | ||
| const index = newText.indexOf(functionNameText); |
There was a problem hiding this comment.
we do not know if the name is really unique text wise. we only look if it was declared as an identifier, but not in a comment or string literal for instance.
There was a problem hiding this comment.
this also relies on the use site being inserted in the file before the definition. we should add a comment to that meaning in case we change where the function declaration is added.
There was a problem hiding this comment.
It would definitely be preferable not to assume that the new declaration is inserted after the extracted range because that will almost certainly not be the case when we start extracting locals.
src/harness/fourslash.ts
Outdated
| } | ||
| } | ||
| else { | ||
| // TODO: test editInfo.renameFilename too |
There was a problem hiding this comment.
Maybe just assert that it's non-empty for now?
| for (const r of results) { | ||
| const changes = refactor.extractMethod.getPossibleExtractions(result.targetRange, context, results.indexOf(r))[0].changes; | ||
| const { renameLocation, edits } = refactor.extractMethod.getPossibleExtractionAtIndex(result.targetRange, context, results.indexOf(r)); | ||
| Debug.assert(edits.length === 1); |
|
Please port this to release-2.5 |
| } | ||
|
|
||
| // exported only for tests | ||
| export function getPossibleExtractionAtIndex(targetRange: TargetRange, context: RefactorContext, requestedChangesIndex: number): RefactorEditInfo { |
| } | ||
|
|
||
| function getUniqueName(isNameOkay: (name: string) => boolean) { | ||
| function getUniqueName(fileText: string): string { |
There was a problem hiding this comment.
So, somewhat ironically, if you were to add a comment //TODO newFunction_1 goes here, we would call the new function "newFunction_2"?
There was a problem hiding this comment.
Would it be easier to use something temporary, like a GUID, until the replacement has been accomplished and then swap it for the name we would originally have generated?
There was a problem hiding this comment.
That might be doable, but we might (might not) need the GUID to have an identical length. But you could still calculate them together inside getUniqueName.
| isClassLike(scope) ? createPropertyAccess(range.facts & RangeFacts.InStaticRegion ? createIdentifier(scope.name.getText()) : createThis(), functionReference) : functionReference, | ||
| const called = getCalledExpression(scope, range, functionNameText); | ||
|
|
||
| let call: Expression = createCall(called, |
There was a problem hiding this comment.
Missing linebreak before argument?
| Debug.assert(fileName === renameFilename); | ||
| for (const change of textChanges) { | ||
| const { span, newText } = change; | ||
| // Note: We are assuming that the call expression comes before the function declaration, |
There was a problem hiding this comment.
Can you please add TODO (acasey) (or TODO (17098))? This assumption will be incorrect as soon as we implement Extract Local.
| usages: Map<UsageEntry>; | ||
| typeParameterUsages: Map<TypeParameter>; // Key is type ID | ||
| substitutions: Map<Node>; | ||
| readonly usages: Map<UsageEntry>; |
There was a problem hiding this comment.
What happens when a property of an exported type depends on a non-exported type?
There was a problem hiding this comment.
Users can't reference the type itself, but they can get a variable of the type. Pretty annoying. But it looks like this doesn't actually need to be exported.
| var i = 10; | ||
| var __return: any; | ||
| ({ __return, i } = newFunction(i)); | ||
| ({ __return, i } = n/*RENAME*/ewFunction(i)); |
There was a problem hiding this comment.
Why is the location within the identifier?
amcasey
left a comment
There was a problem hiding this comment.
Our method of coming up with a unique name seems slightly crazy to me (esp for large files), but this generally makes sense.
Fixes #17852
Does not fix #18048
EDIT: Now fixes both