-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: workaround for move to file refactor restriction (#2227)
prevent Svelte files from showing up in the suggestions until TypeScript allows this
- Loading branch information
1 parent
a2f86e1
commit 3f7f27b
Showing
2 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
packages/typescript-plugin/src/language-service/move-to-file.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type ts from 'typescript/lib/tsserverlibrary'; | ||
|
||
export function decorateMoveToRefactoringFileSuggestions(ls: ts.LanguageService): void { | ||
const getMoveToRefactoringFileSuggestions = ls.getMoveToRefactoringFileSuggestions; | ||
|
||
ls.getMoveToRefactoringFileSuggestions = ( | ||
fileName, | ||
positionOrRange, | ||
preferences, | ||
triggerReason, | ||
kind | ||
) => { | ||
const program = ls.getProgram(); | ||
|
||
if (!program) { | ||
return getMoveToRefactoringFileSuggestions( | ||
fileName, | ||
positionOrRange, | ||
preferences, | ||
triggerReason, | ||
kind | ||
); | ||
} | ||
|
||
const getSourceFiles = program.getSourceFiles; | ||
try { | ||
// typescript currently only allows js/ts files to be moved to. | ||
// Once there isn't a restriction anymore, we can remove this. | ||
program.getSourceFiles = () => | ||
getSourceFiles().filter((file) => !file.fileName.endsWith('.svelte')); | ||
|
||
return getMoveToRefactoringFileSuggestions( | ||
fileName, | ||
positionOrRange, | ||
preferences, | ||
triggerReason, | ||
kind | ||
); | ||
} finally { | ||
program.getSourceFiles = getSourceFiles; | ||
} | ||
}; | ||
} |