Skip to content

Incorrect rename when using npm workspaces and project references #53041

@itrapashko

Description

@itrapashko

Bug Report

🔎 Search Terms

workspace, npm, invalid reference count, cannot rename, failed to apply edits

🕗 Version & Regression Information

  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about rename, references, workspace
    Tried versions 4.9.5, 3.0.0, 'Nightly'

⏯ Playground Link

Repository link with relevant code

💻 Code

project1/index.ts

export function myFunc() {

}

project2/index.ts

import { myFunc } from 'project1'

myFunc()

🙁 Actual behavior

  • Rename myFunc in project1/index.ts to myFunc1
  • It is renamed to myFunc11 in project1/index.ts and myFunc1 in project2/index.ts

🙂 Expected behavior

Function is renamed to myFunc1 in both projects.

Details

Operating system: Windows 11

Project structure is the following:

  • root directory has package.json file where two workspaces are specified: project1 and project2
  • root tsconfig.json has two project references: ./project1 and ./project2
  • both project1 and project2 has tsconfig.json with composite flag set to true
  • project2 has one project reference: ../project1

Problem occurs only when project references and npm workspaces are used and function is imported using package name from package.json. If function is imported using relative path (../project1), everything works correctly.

Here is trace from TypeScript language server when renaming function:
[Trace - 08:25:35.101] <semantic> Response received: rename (421). Request took 3 ms. Success: true 
Result: {
    "info": {
        "canRename": true,
        "displayName": "myFunc",
        "fullDisplayName": "\"c:/npm-workspace-and-project-references/project1/index\".myFunc",
        "kind": "function",
        "kindModifiers": "export",
        "triggerSpan": {
            "start": {
                "line": 1,
                "offset": 17
            },
            "end": {
                "line": 1,
                "offset": 23
            }
        }
    },
    "locs": [
        {
            "file": "c:/npm-workspace-and-project-references/project1/index.ts",
            "locs": [
                {
                    "start": {
                        "line": 1,
                        "offset": 17
                    },
                    "end": {
                        "line": 1,
                        "offset": 23
                    },
                    "contextStart": {
                        "line": 1,
                        "offset": 1
                    },
                    "contextEnd": {
                        "line": 3,
                        "offset": 2
                    }
                }
            ]
        },
        {
            "file": "C:/npm-workspace-and-project-references/project1/index.ts",
            "locs": [
                {
                    "start": {
                        "line": 1,
                        "offset": 17
                    },
                    "end": {
                        "line": 1,
                        "offset": 23
                    },
                    "contextStart": {
                        "line": 1,
                        "offset": 1
                    },
                    "contextEnd": {
                        "line": 3,
                        "offset": 2
                    }
                }
            ]
        },
        {
            "file": "c:/npm-workspace-and-project-references/project2/index.ts",
            "locs": [
                {
                    "start": {
                        "line": 1,
                        "offset": 10
                    },
                    "end": {
                        "line": 1,
                        "offset": 16
                    },
                    "contextStart": {
                        "line": 1,
                        "offset": 1
                    },
                    "contextEnd": {
                        "line": 1,
                        "offset": 34
                    }
                },
                {
                    "start": {
                        "line": 3,
                        "offset": 1
                    },
                    "end": {
                        "line": 3,
                        "offset": 7
                    }
                }
            ]
        }
    ]
}

For some reason response contains two text edits for same text range in project1/index.ts file, that differ only in case of disk letter (C: and c:).

Checked this problem on macOS - renaming works correctly. Maybe the problem is related to case insensitive file system? Or maybe it is caused by symlinks created by npm workspace?

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: Refactoringse.g. extract to constant or function, rename symbolFix AvailableA PR has been opened for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions