-
Notifications
You must be signed in to change notification settings - Fork 646
Add command and code action to extract into function and local variable #2139
Conversation
Thanks for the PR! This is one of my most wanted features :D Any Updates on this? |
Wondering what the status of this is? |
This approach using godoctor has been tried before and was abandoned. But I guess it has gotten better and vim-go uses it. It works for the simple use cases that I tried. I am waiting for the maintainer to review it or give me some feedback. |
@ramya-rao-a sorry for the ping, but did u allready notice this pr? :) |
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.
Thanks so much for the PR @aswinmprabhu!
My apologies for not taking a look at this earlier.
I have left a few comments based on just code review, please do take a look.
I'll try out the feature this week and get back here if I see any issues.
src/goDoctor.ts
Outdated
return resolve('Could not find godoctor'); | ||
} | ||
if (err) { | ||
return resolve(`Could not extract function : \n\n${stderr}`); |
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 should use reject
here instead of resolve
to deal with errors
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 type Thenable<string>
returned by runGoDoctor
doesn't have a catch
method to handle rejected promises.
Sadly i'm really bad at JavaScript, so sorry for the dumb question. And btw: Thank u so much for reviewing ramya-rao-a 🥇 |
@Nerzal Yes, I believe all the shortcuts as described in https://code.visualstudio.com/docs/editor/refactoring should be usable. |
Also the refactoring seems to extremely slow in decently large files. This does not seem to be a problem with the implementation, as the godoctor command if run from the terminal with the same args, takes the same amount of time as in the editor. |
strong desire !!! |
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.
Thanks @aswinmprabhu!
I have pushed a few more commits to make some changes and use diffs instead of overwriting the file on disk to allow undo.
Can you take a look and see if the feature still works as expected for you?
Works good. But why do you still have the |
This reverts commit 7edc8bf.
Looks like sometime in the past year, VS Code is able to do the undo feature even for the changes that were made directly to the file on disk. (It didn't do this when I was working a feature 2 years ago). So we don't need to use the diffs after all. Reverting that commit |
Ok. Cool. Tested it out again. Can confirm that undo works fine. |
The latest beta version (0.9.3-beta.2) of this extension has this feature. Please see Refactoring in VS Code on how you can use the refactor feature. Thanks @aswinmprabhu! |
it seems that not support go mod. |
Thanks for the observation @helphi |
No description provided.