Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Typescript Language Server Error on "Move to File" in Svelte Project #2222

Open
ian-viri opened this issue Dec 4, 2023 · 8 comments
Open
Labels

Comments

@ian-viri
Copy link

ian-viri commented Dec 4, 2023

Describe the bug

The new VSCode Move to file refactor throws an error in a Svelte project that has *.svelte component files.

Reproduction

  1. Create a new SvelteKit project
  2. Add a new component file, e.g. src/lib/Component.svelte
  3. Use that component in a +page.svelte file
  4. Open any .ts file, find a function, and attempt to Refactor > Move to File
  5. See the following error from the TS lanugage server
<semantic> TypeScript Server Error (5.2.2) Debug Failure. File /Users/iangillis/code/blog/prisma-sveltekit-seeding/src/lib/Component.svelte has unknown extension. Error: Debug Failure. File /Users/iangillis/code/blog/prisma-sveltekit-seeding/src/lib/Component.svelte has unknown extension. at extensionFromPath (/Users/iangillis/code/blog/prisma-sveltekit-seeding/node_modules/typescript/lib/tsserver.js:21064:39) at /Users/iangillis/code/blog/prisma-sveltekit-seeding/node_modules/typescript/lib/tsserver.js:144823:221 at mapDefined (/Users/iangillis/code/blog/prisma-sveltekit-seeding/node_modules/typescript/lib/tsserver.js:2671:22) at Proxy.getMoveToRefactoringFileSuggestions (/Users/iangillis/code/blog/prisma-sveltekit-seeding/node_modules/typescript/lib/tsserver.js:144823:19) at IpcIOSession.getMoveToRefactoringFileSuggestions (/Users/iangillis/code/blog/prisma-sveltekit-seeding/node_modules/typescript/lib/tsserver.js:184487:41) at getMoveToRefactoringFileSuggesti...

Expected behaviour

Ideally, be able to use the Move to File refactor to move files between any combination of .ts and .svelte files. At the very least, be able to us it to move files between two .ts files without error.

System Info

  • OS: Mac
  • IDE: VSCode

Which package is the issue about?

Svelte for VS Code extension

Additional Information, eg. Screenshots

Moved from microsoft/vscode#199785

@ian-viri ian-viri added the bug Something isn't working label Dec 4, 2023
@jasonlyu123

This comment has been minimized.

@jasonlyu123 jasonlyu123 added upstream and removed bug Something isn't working labels Dec 5, 2023
@ian-viri
Copy link
Author

ian-viri commented Dec 5, 2023

This is also technically not "caused" by the Svelte extension. The root reason is that there are imports for svelte files, and TypeScirpt doesn't know how to rewrite it.

That was my thought as well. Who owns the upstream TypeScript language server? Is it VSCode maintainers or someone else

@jasonlyu123
Copy link
Member

Typescript team https://github.com/microsoft/TypeScript

@ian-viri
Copy link
Author

ian-viri commented Dec 5, 2023

I'd like to be able to use this built-in refactor -- what would the fix look like? Some wild guesses:

  • We somehow tell VSCode to use the Svelte language server for this refactor in Svelte projects?
  • The TS language server natively supports .svelte extensions
  • The TS language exposes some way to let the svelte extension plug in and tell is how to handle .svelte files

@jasonlyu123
Copy link
Member

Sorry, I jumped to the conclusion too fast. I didn't realise it only happens in "move to file" and not "move to new files", so I thought I reproduced with an import that ends with .js.

This is not related to the js ending thing I mentioned. It is a new issue. It just used the same utility function that caused the previous problem. Looking at the typescript source code, we might be able to work around It, but I'll have to see if the workaround is too hacky and might cause other problems.

@fregante
Copy link

I had this issue when using a more common .module.css import. In my case it would be easier (or at least it would be a start) to just ignore unrecognized imports. A partial "Move to file" action is better than a complete failure.

@dummdidumm
Copy link
Member

@jasonlyu123 did you ever open an issue at the TypeScript repo asking for this assertion to be removed?

@jasonlyu123
Copy link
Member

Yes. microsoft/TypeScript#56749
It was assigned to a team member so I didn't create a PR to fix it. But it has been over half a year now I'll probably create one.

The refactor source of the feature has also been limited from an arbitrary amount of code to a named block of code. So it probably doesn't make much sense for html-liked files or CSS modules to be a "move to" target anyway. Making TS filter out unknown files should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants