-
Notifications
You must be signed in to change notification settings - Fork 189
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
LanguageService - getSuggestionDiagnostics, getEditsForRefactor, getCodeFixesAtPosition #488
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The LanguageService
changes look good, but I don't want to have the refactors that cause the nodes to be forgotten to be so easily accessible.
@cancerberoSgx The |
No worries! Will do it tomorrow, that's why I separate it in two different commits. I insist on having this discussions on a PR instead of on an issue since it's much more clear and is not a big deal for me, but in the future I will create an issue first. I understand. forgotten why these cannot" ? I think I want to have the discussion at least. There is another code fix that is as useful as Organize Imports - the one that will remove all declarations or symbols that are not used. So I will keep this functions in a separate library of mine. Do you think I could still contribute it to ts-simple-ast as a separate class/utility at least? |
I think is ready now, thanks |
@cancerberoSgx I'm going to quickly make all the changes and merge this PR. Will have it done in 15-30 mins so don't bother with any changes at the moment. |
Hey @cancerberoSgx, this is almost done. I made some updates because it was quicker than reviewing. We just need a few tests for the remaining comments I made before this is merged. I've stopped working on this now so if you have the time to add those tests then please add them. Otherwise, I will get to it sometime next weekend. |
added more test asserts |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to fix the CI errors (issue with declaration file... fix outlined in my comments)
import { DefinitionInfo, EmitOutput, FileTextChanges, ImplementationLocation, RenameLocation, TextChange } from "./results"; | ||
import { DefinitionInfo, EmitOutput, FileTextChanges, ImplementationLocation, RenameLocation, TextChange, DiagnosticWithLocation } from "./results"; | ||
import { RefactorEditInfo } from "./results/RefactorEditInfo"; | ||
import { CodeFixAction } from "./results/CodeFixAction"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two imports aren't included in the barrel file (./results/index.ts
). Could you add them there and then fix these imports?
That should fix these CI errors:
> ts-node --transpileOnly scripts/verification/ensureNoDeclarationFileErrors
dist-declarations/ts-simple-ast.d.ts:8897:214 - error TS2304: Cannot find name 'RefactorEditInfo'.
8897 getEditsForRefactor(filePathOrSourceFile: string | SourceFile, formatOptions: FormatCodeSettings, positionOrRange: number | TextRange, refactorName: string, actionName: string, preferences?: UserPreferences): RefactorEditInfo | undefined;
~~~~~~~~~~~~~~~~
dist-declarations/ts-simple-ast.d.ts:8907:202 - error TS2304: Cannot find name 'CodeFixAction'.
8907 getCodeFixesAtPosition(filePathOrSourceFile: string | SourceFile, start: number, end: number, errorCodes: ReadonlyArray<number>, formatOptions?: FormatCodeSettings, preferences?: UserPreferences): CodeFixAction[];
~~~~~~~~~~~~~
There were declaration file issues!
Thanks once again @cancerberoSgx! :) |
…efactor, getCodeFixesAtPosition
The first commit implements LanguageService getEditsForRefactor and getCodeFixesAtPosition and wraps all the data types used by those.
The last commit shows how this can be useful to (re)use exsting TypeScript refactors in ts-simple-ast. In this case I implemented ArrowFunction.addBracesToBody and ArrowFunction.removeBracesToBody just using existing typescript code fix
"Add or remove braces in an arrow function"
. And also implemented Statement.moveToNewFile, using existing typescript refactor"Move to a new file"
.I think TypeScript team slowly starts to focus on providing useful refactoring tools and I think ts-simple-ast should use these to enrich its high level APIs. I can keep adding more refactors provided by TS but first I wanted to ask you what do you think.