镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

"rename file" and "move to new file" refactors do not work when using files #24857

Description

TypeScript Version: 2.9.1

Search Terms:
files "move to new file" "rename file"

Code

// tsconfig.json
{
  "files": ["./src/index.ts"]
}
// ./src/index.ts
import foo from './other';
// ./src/other.ts
export default {}

const bar = {};

Expected behavior:

  • When renaming the file ./src/other.ts, I expect TypeScript/VSCode to prompt me to update the import in ./src/index.ts.
  • When selecting bar in ./src/other.ts, TypeScript/VSCode offers to move this to a new file. When actioning this, I expect this to work.

(TypeScript knows that ./src/other.ts is in the project because it is part of the traced dependency graph from the entry file ./src/index.ts.)

Actual behavior:

  • When renaming the file ./src/other.ts, there is no prompt to update the import.
  • When selecting bar in ./src/other.ts, TypeScript/VSCode offers to move this to a new file. When actioning this, nothing happens.

Playground Link:

Related Issues:
microsoft/vscode#51366
#23573
#23726


A known workaround is to use the include option instead of files. However, I am curious why this is necessary. I prefer to list the entry file and let TypeScript work the rest out. This is especially helpful when a folder has a combination of source and test files—TypeScript automatically knows not to include the test files because they are not part of the dependency graph.

If there is a good reason why these commands/refactors can't work with files, could we make the experience clearer? Why is the "move to new file" command suggested in VSCode when it leads to nothing? If so, perhaps this is an issue for VSCode.

Activity

  1. mhegazy commented on Jun 11, 2018

    @mhegazy
    Contributor

    Can you share the log from your tsserver? i suspect it is a duplicate of #24613

  2. OliverJAsh commented on Jun 12, 2018

    @OliverJAsh
    ContributorAuthor
  3. added
    BugA bug in TypeScript
    and removed
    Needs More InfoThe issue still hasn't been fully clarified
    on Jun 12, 2018
  4. mhegazy commented on Jun 12, 2018

    @mhegazy
    Contributor

    This looks different.

  5. sheetalkamat commented on Jun 13, 2018

    @sheetalkamat
    Member

    Matt Bierner (@mjbvz) this seems like there are 2 open requests on same file. Can you check why? We do not expect open on same file without closing it first. Thats the assert that raised error in the log.
    Interesting open requests:

    Info 7    [11:4:3.833] request:
        {"seq":0,"type":"request","command":"open","arguments":{"file":"/Users/OliverJAsh/Development/temp/typescript-files-refactors-test/src/index.ts","fileContent":"// ./src/index.ts\nimport foo from './other';"}}
    
    nfo 52   [11:4:7.163] request:
        {"seq":6,"type":"request","command":"open","arguments":{"file":"/Users/OliverJAsh/Development/temp/typescript-files-refactors-test/src/index.ts","fileContent":"// ./src/index.ts\nimport foo from './other';","scriptKindName":"TS","projectRootPath":"/Users/OliverJAsh/Development/temp/typescript-files-refactors-test"}}
    
  6. mjbvz commented on Jun 27, 2018

    @mjbvz

    Oliver Joseph Ash (@OliverJAsh) Can you please try collecting the TS Server log again in the latest VS Code insiders build. I made some changes to how we track opened files and haven't been able to reproduce the duplicate open requests in recent VS Code builds

  7. OliverJAsh commented on Jun 28, 2018

    @OliverJAsh
    ContributorAuthor

    Matt Bierner (@mjbvz) In this log I attempt to use the "move to new file" command as described in my original post.
    tsserver.log

    Matt Bierner (@mjbvz) Are you able to reproduce the issue as I described?

  8. mhegazy commented on Jun 30, 2018

    @mhegazy
    Contributor

    Oliver Joseph Ash (@OliverJAsh) looks like this log is using typescript@2.9.1 can you try with typescript@next?

  9. sheetalkamat commented on Jul 2, 2018

    @sheetalkamat
    Member

    Oliver Joseph Ash (@OliverJAsh) The error you are seeing in the log, i think is fixed by #24613. Please try typescript@next and let us know if you still see the issue. Thank you.

  10. 43 remaining items

  11. Repository owner unassigned on Nov 16, 2018
  12. sheetalkamat commented on Jan 3, 2019

    @sheetalkamat
    Member

    Oliver Joseph Ash (@OliverJAsh) Sorry for getting back but can you please try your repro with typescript@next and see if it repros. Providing log if it repros will help. Thanks.

  13. OliverJAsh commented on Jan 5, 2019

    @OliverJAsh
    ContributorAuthor

    Testing "move to new file", unfortunately that doesn't seem to help.

    tsserver.log

  14. sheetalkamat commented on Jan 7, 2019

    @sheetalkamat
    Member

    Oliver Joseph Ash (@OliverJAsh) Thank you for the log. Will investigate.

  15. sheetalkamat commented on Jan 11, 2019

    @sheetalkamat
    Member

    Oliver Joseph Ash (@OliverJAsh) its been now fixed by #26280 Please verify with typescript@next and report back with tsserver log if it still repros. Thank you,

  16. OliverJAsh commented on Jan 13, 2019

    @OliverJAsh
    ContributorAuthor

    It fixes the problem—thank you! One small thing though: it adds the new file to files even though it doesn't need to be (when it's included via the dependency graph of existing files).

  17. sheetalkamat commented on Jan 14, 2019

    @sheetalkamat
    Member

    Oliver Joseph Ash (@OliverJAsh) can you please share tsserver log where your newFile gets added to the files list? I don't see that when I do it with typescript@next

  18. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issueNeeds More InfoThe issue still hasn't been fully clarified

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions