Description
π Search Terms
move to file, has unknown extension.
β Viability Checklist
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- This wouldn't change the runtime behavior of existing JavaScript code
- This could be implemented without emitting different JS based on the types of the expressions
- This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
β 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 patchprogram.getSourceFiles
before calling thegetMoveToRefactoringFileSuggestions
and restoring it afterwards.