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

Idea: Migrate to TypeScript plugin #836

Open
zardoy opened this issue Mar 10, 2023 · 4 comments
Open

Idea: Migrate to TypeScript plugin #836

zardoy opened this issue Mar 10, 2023 · 4 comments
Assignees
Labels
💪 Improvement Refactoring doesn't run on a specific case or result could be optimized

Comments

@zardoy
Copy link
Contributor

zardoy commented Mar 10, 2023

This is continuation of #415 (comment) from @OliverJAsh

So basically I suggest to rewrite a few files to use TS ast instead of babel. Advantages:

  • Abracadabra could finally work with syntax errors (eg not closed functions or other blocks)
  • Type inferrence in native way (external modules / global augmentations and so on)
  • No performance issues anymore as it would work in the same way as other refactorings and use existing cache of source files / types links. As I understand abracadabra doesn't even use dedicated server for parsing, which slows down extension host anyway.
  • You don't need to care of formatting anymore, there is ChangesTracker so TS can infer code-style from existing code + its configurable with typescript.format settings (Move Statement Down/Up Always Add Semicolons #481)

For example extract-use-callback would better infer type (I couldnt check current implementation as abracadabra always giving error 😅 I'm sorry, something went wrong: Failed to load parser '@typescript-eslint/parser' declared in 'CLIOptions': Cannot find module '@typescript-eslint/parser' Require stack: - /__placeholder__.js)

For example this is how I implemented Split declaration and initialization refactoring. And this code action still works on the web and with Volar (eg vue file or takeover mode).

On the other hand its known that TS refactorings has very limited functionality its not possible to build interactive code actions, they don't even support snippets, so I was using the following workaround: registering my own code action provider which sends custom requests to TS server, where I can return arbitrary data. For two-step code actions such as move to existing file just need to send such request twice. For example I have refactoring to convert array into object by selecting specific key (I can attach gif if needed, and by the way, do you like the idea of such refactoring?).

I've heard you have very limited time, so I'd happy to help you with some PRs, feel free to ask any kind of questions :)

@zardoy zardoy added the 💪 Improvement Refactoring doesn't run on a specific case or result could be optimized label Mar 10, 2023
@zardoy
Copy link
Contributor Author

zardoy commented Mar 10, 2023

Also I've seen you use TS typeChecker, why don't you use TS AST API then and prefer babel then? Sorry, I might be missing something

@nicoespeon
Copy link
Owner

That sounds like a good idea. I haven't spent much time and energy on Abracadabra recently, but I will give this more thought during the weekend and come back to you. Thanks for the detailed suggestion @zardoy 👍

@nicoespeon
Copy link
Owner

May be helpful: I just noticed that there is now an official way to retrieve the TS API used by VS Code (https://code.visualstudio.com/api/references/contribution-points#contributes.typescriptServerPlugins)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 Improvement Refactoring doesn't run on a specific case or result could be optimized
Projects
None yet
Development

No branches or pull requests

2 participants