-
Notifications
You must be signed in to change notification settings - Fork 12.9k
addMethodDeclaration: add after quickfix location if possible #24438
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
Conversation
The tests pass locally, but none of the VSTS or Travis builds succeeded. Is that something to worry about or is this just a temporary issue with the build process? |
|
||
// Gets the MethodDeclaration of a method of the cls class that contains the node, or undefined if the node is not in a method or that method is not in the cls class. | ||
function getNodeToInsertMethodAfter(cls: ClassLikeDeclaration, node: Node): MethodDeclaration | undefined { | ||
const nodeMethod = getParentMethodDeclaration(node); |
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.
how about:
function getContainingMethodDeclaration(node: Node, classDeclaration:ClassLikeDeclaration) {
const method = getAncestor(node, SyntaxKind.MethodDeclaration);
return method && method.parent === classDeclaration ? method : undefined;
}
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.
i would also inline these in the caller.
@@ -199,6 +199,34 @@ namespace ts.codefix { | |||
preferences: UserPreferences, | |||
): void { | |||
const methodDeclaration = createMethodFromCallExpression(callExpression, token.text, inJs, makeStatic, preferences); | |||
changeTracker.insertNodeAtClassStart(classDeclarationSourceFile, classDeclaration, methodDeclaration); | |||
const currentMethod = getNodeToInsertMethodAfter(classDeclaration, callExpression); |
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.
nit, containingMethodDeclaration
Thank you so much @mhegazy! Implemented all of your suggestions, this is a much cleaner code. |
thanks! |
Fixes #22674
Declare method quickfix/codeaction now inserts method after the current location.
Current behavior:
Changed behavior:
The old behavior is preserved if quickfix is applied outside of the class. In that case the method is inserted at the start of the class.
This is my first contribution to TypeScript, so please review carefully :)