-
-
Notifications
You must be signed in to change notification settings - Fork 66
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
Add basic support for move function refactoring #226
Conversation
Approach looks okay to me, it's unfortunate, that it needs client support, but that's how it is with language server at the moment. Until this moves further microsoft/language-server-protocol#764 Can you please install and use prettier via https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode |
The core functionality is complete. Moving a function properly updates the module |
I think we should at least fix 1 and 3 before we merge this. |
What do you mean by 1? Auto exposing the moved function in the destination file? Currently it only gets exposed if there is an external reference that needs it. |
Kinda correct, it correlates with 2, as you don't seem to differentiate between fully qualified ( I tested it with the elm-spa-example https://github.com/rtfeldman/elm-spa-example/blob/master/src/Article/Feed.elm#L172 |
We also need to update references or add imports for any functions or types used within the moved function. |
Yes, would be nice, but I think it would already be useful without, as Elm will just complain to you about it :) |
So to be clear, if a file only has fully qualified references to the function ( |
Yes, that's my understanding
…On Mon, 23 Mar 2020, 00:46 Jon Bockhorst, ***@***.***> wrote:
So to be clear, if a file only has fully qualified references to the
function (xxx.function), we don't need to expose it (just import). Only
expose it if we need it, when there is an exposed reference to it in the
file (function).
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#226 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABNLEZDYIC66FXTLZ5CC5ALRI2PMVANCNFSM4LQB74AA>
.
|
It now properly handles fully qualified references:
|
So I ended up with this as a module declaration :) |
Not able to do that again, but every time I use the declaration (not the type declaration) to initalize the move on viewPagination to the Session module I end up with |
Thanks, I think I fixed it. |
if (node?.parent?.type == "function_call_expr" && node.parent.firstNamedChild) { | ||
const parameterIndex = node.parent.namedChildren.map(c => c.text).indexOf(node.text) - 1; | ||
if ( | ||
node?.parent?.type == "function_call_expr" && |
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.
===
please
Merging this now, will address some of the smaller stuff in one of the next commits. Thank you so much! 🌈 |
Part of #194. It adds basic support for a new code action to move a function to a new file. It is a fair amount of changes so I wanted to get your feedback to make sure it was a good direction.
Because this type of refactoring requires client support (quick pick for the destination file),
I added a new
extendedCapabilites
property to the client settings that the client can initialize. Right now the only property ismoveFunctionRefactoringSupport
, but more can easily be added.I also added a
protocol.ts
that defines the custom requests between the server and client.Currently, in vscode, you can move a function to a new file and it adds new imports to all files with references. Dependent on elm-tooling/elm-language-client-vscode#88.