Skip to content

Respect useAliasesForRenames in rename edits#4371

Open
Copilot wants to merge 6 commits into
mainfrom
copilot/fix-use-aliases-for-renames
Open

Respect useAliasesForRenames in rename edits#4371
Copilot wants to merge 6 commits into
mainfrom
copilot/fix-use-aliases-for-renames

Conversation

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

The native language service parsed js/ts.preferences.useAliasesForRenames and typescript.preferences.useAliasesForRenames, but rename edits still always used alias-preserving import rewrites.

  • Rename behavior

    • Threaded UseAliasesForRename into rename reference collection.
    • When disabled, renames now target the exported declaration and its references instead of introducing an import alias.
  • Edit generation

    • Gated prefix/suffix rename edits on UseAliasesForRename.
    • Preserved existing alias-style behavior when the preference is enabled or unset.
  • Coverage

    • Added fourslash coverage for renaming an imported type with the preference both enabled and disabled.
    • Updated affected rename baselines.

Example:

import { MyTypeA } from "./file-b";
const type: MyTypeA = { foo: "bar" };

With useAliasesForRenames: false, renaming MyTypeA from the import now also renames the exported interface MyTypeA instead of producing:

import { MyTypeA as NewName } from "./file-b";

Copilot AI and others added 2 commits June 19, 2026 01:31
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix js/ts.preferences.useAliasesForRenames not respected Respect useAliasesForRenames in rename edits Jun 19, 2026
Copilot AI requested a review from jakebailey June 19, 2026 01:37
@jakebailey jakebailey marked this pull request as ready for review June 19, 2026 01:53
Copilot AI review requested due to automatic review settings June 19, 2026 01:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Not ready to approve

Rename edit generation now incorrectly gates numeric-literal index quoting on useAliasesForRenames, which can produce semantically wrong edits (e.g. obj[foo] vs obj["foo"]).

Pull request overview

This PR updates the native language service rename pipeline to respect the js/ts.preferences.useAliasesForRenames / typescript.preferences.useAliasesForRenames user preference, switching between alias-preserving import/export rewrites vs. renaming the underlying exported declaration and its references.

Changes:

  • Threaded UseAliasesForRename into rename reference collection so useAliasesForRenames: false targets the exported declaration rather than introducing import/export aliases.
  • Gated rename edit text generation for alias-style prefix/suffix rewrites on UseAliasesForRename.
  • Added fourslash coverage for renaming an imported type with the preference enabled vs. disabled, and updated affected baselines.
File summaries
File Description
internal/ls/findallreferences.go Uses the preference to choose rename reference-collection strategy.
internal/ls/rename.go Threads the preference into rename edit text generation to enable/disable alias-style rewrites.
internal/fourslash/tests/renameNamedImportUseAliasesForRenames_test.go New fourslash test covering named-import rename behavior for useAliasesForRenames true vs false.
testdata/baselines/reference/fourslash/findRenameLocations/renameNamedImportUseAliasesForRenames.baseline.jsonc New reference baseline for the added fourslash test.
testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameExportSpecifier2.baseline.jsonc Updated submodule baseline reflecting preference-driven rename behavior changes.
testdata/baselines/reference/submodule/fourslash/findRenameLocations/renameExportSpecifier2.baseline.jsonc.diff Removed accepted-diff baseline file (no longer needed after baseline updates).
testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsReExportsUseInImportType.baseline.jsonc Updated submodule baseline reflecting preference-driven rename behavior changes.
testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsReExportsUseInImportType.baseline.jsonc.diff Updated diff baseline for the above submodule baseline change.
testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsPrefixSuffixPreference.baseline.jsonc Updated submodule baseline reflecting preference-driven rename behavior changes.
testdata/baselines/reference/submodule/fourslash/findRenameLocations/findAllRefsPrefixSuffixPreference.baseline.jsonc.diff Updated diff baseline for the above submodule baseline change.

Copilot's findings

  • Files reviewed: 10/10 changed files
  • Comments generated: 1

Note

Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.

Comment thread internal/ls/rename.go
Comment on lines 343 to 346
// If the node is a numerical indexing literal, then add quotes around the property access.
if entry.kind != entryKindRange && ast.IsNumericLiteral(entry.node) && ast.IsAccessExpression(entry.node.Parent) {
if useAliasesForRename && entry.kind != entryKindRange && ast.IsNumericLiteral(entry.node) && ast.IsAccessExpression(entry.node.Parent) {
quote := getQuoteFromPreference(quotePreference)
return quote + newText + quote
Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Not ready to approve

Rename preference default handling appears inconsistent across rename edit generation vs rename validation, which could cause incorrect behavior when the preference is unset.

Copilot's findings
  • Files reviewed: 10/10 changed files
  • Comments generated: 1

Note

Your feedback helps us improve the quality of this feature.
Please use 👍 or 👎 to tell us whether this assessment is correct.

Comment thread internal/ls/rename.go
Comment on lines 82 to 84
quotePreference := lsutil.GetQuotePreference(sourceFile, l.UserPreferences())
useAliasesForRename := l.UserPreferences().UseAliasesForRename != core.TSFalse

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Comment thread internal/ls/findallreferences.go Outdated
} else {
options.use = referenceUseRename
options.useAliasesForRename = true
options.useAliasesForRename = l.UserPreferences().UseAliasesForRename != core.TSFalse

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot I much prefer .IsTrueOrUnknown for these tristate comparisons you've put everywhere

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 7bb684d.

Co-authored-by: jakebailey <5341706+jakebailey@users.noreply.github.com>
Copilot AI requested a review from jakebailey June 19, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants