Registry Mirror
Skip to content

Ignore non-ts/js files in move to file refactorΒ #56749

Closed as not planned
Closed as not planned

Description

πŸ” Search Terms

move to file, has unknown extension.

βœ… Viability Checklist

⭐ Suggestion

In getMoveToRefactoringFileSuggestions, changes to use tryGetExtensionFromPath to filter candidate files to move to. And ignore the unknown file extension. It would be nice if it could fall back or switch to using SourceFile.scriptKind and SourceFile.isDeclarationFile, but ignoring unknown extensions for at least the candidates should be fine.

πŸ“ƒ Motivating Example

The "Move to file" refactor currently errors if the program contains any source files with a file extension unknown to TypeScript.
Is it possible to remove this restriction? The error is because the getMoveToRefactoringFileSuggestions method uses the extensionFromPath function to find candidates from all the files in the program. If any typescript plugin provides external files with non-ts/js file extension, This will result in a Debug.assert error. For example, mrmckeb/typescript-plugin-css-modules#241

Most of the other language service features don't have this restriction. At least it won't error whenever one external file is in the program. It would be nice if this feature could work with other file extensions. And even allow this feature to be used in other language servers that wrap typescript language service.

πŸ’» Use Cases

  • What do you want to use this for?
    Using the move to file refactor in projects where a typescript plugin adds a custom module, like vue and svelte.

  • Workarounds I can think of
    The TypeScript plugins monkey patch program.getSourceFiles before calling the getMoveToRefactoringFileSuggestions and restoring it afterwards.

Activity

  1. mrmckeb commented on Feb 11, 2024

    @mrmckeb

    Thanks for raising this Lyu, Wei-Da (@jasonlyu123)!

    I've only had the two reports of this issue so far, Ryan Cavanaugh (@RyanCavanaugh) and navya9singh, but if there's anything I can do on the plugin side to mitigate this, please let me know!

  2. itsMapleLeaf commented on Jun 14, 2024

    @itsMapleLeaf

    I regularly encounter this while using the Astro and MDX extensions in VSCode. Are there any workarounds for this, other than disabling those extensions before running the refactor?

  3. alonesuperman commented on Jul 10, 2024

    @alonesuperman

    Need it. I believe this situation will occur frequently in Vue projects.

  4. kongmoumou commented on Aug 1, 2024

    @kongmoumou

    Facing same issue on all vue project 🀯, TS version 5.x.

  5. pabletecodes commented on Aug 14, 2024

    @pabletecodes

    πŸ‘. I just encountered this issue when using "Move to file" in VSCode with Typescript Version 4.9.5.

  6. stevefan1999-personal commented on Sep 12, 2024

    @stevefan1999-personal

    This is quite an annoying problem in Astro

  7. Obiwarn commented on May 16, 2025

    @Obiwarn

    In VS Code the "move to file" refactoring is affected by this when I use mdx files.

    mdx-js/mdx-analyzer#420

  8. DrBearZay commented on Jul 9, 2025

    @DrBearZay

    Didn't fix so far 🀯, and I have no other solution

  9. added
    Domain: LS: Refactorings
    on Oct 16, 2025
  10. RyanCavanaugh commented on Dec 3, 2025

    @RyanCavanaugh
    Member

    Closing language service bugs related to the 6.0 implementation. For more information, see #62827

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

Metadata

Metadata

Assignees

Labels

7.0 LS MigrationBugDomain: LS: Refactorings

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions