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

Implementing Client side Rename provider to allow variable/function rename #4950

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

Razmo99
Copy link

@Razmo99 Razmo99 commented Mar 25, 2024

PR Summary

This pull request implements the VSCode RenameProvider class along with two methods within it provideRenameEdits and prepareRename the goal being to complete #261

This will allow for the client to make requests to the server side of the extension when pressing F2 to perform refactoring on variables and functions.

This client side code has been modified from the C# VSCode extension and modified to work with the Powershell extension's server side component.

There will be a sister pull request on the PowershellEditorServices repository to implement the server side.

PR Checklist

Note: Tick the boxes below that apply to this pull request by putting an x between the square brackets.
Please mark anything not applicable to this PR NA.

  • PR has a meaningful title
  • Summarized changes
  • [NA] PR has tests
  • This PR is ready to merge and is not work in progress
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready

@Razmo99
Copy link
Author

Razmo99 commented Mar 25, 2024

@microsoft-github-policy-service agree

@Razmo99 Razmo99 changed the title WIP: Implementing Client side Rename provider to allow variable/function rename Implementing Client side Rename provider to allow variable/function rename Mar 25, 2024
@Razmo99 Razmo99 marked this pull request as ready for review March 25, 2024 04:06
@Razmo99 Razmo99 requested a review from a team as a code owner March 25, 2024 04:06
@SydneyhSmith
Copy link
Collaborator

Hi @Razmo99 super appreciate the detailed PR! Just want to give you a heads up that the maintainers are all pretty heads down on commitments at the moment so it may be a couple of weeks before we get a chance to review the PR

@silverqx
Copy link

silverqx commented May 31, 2024

I would like to ask, what is the state of this PR, does it work actually? I fastly scrolled through the proposed PR and also PowerShellEditorServices#2152, looks like @Razmo99 did a great job about registerRenameProvider and worked ~1 year on this.

The code quality looks good to me and contains a lot of tests, which is a good thing.

Would it be possible to review it, git checkout it, test it, and release it in the next version? @andyleejordan

I lack renaming in PS extension so much, would greatly boost dev. productivity in many cases. I know there always is Search & Replace, but properly implemented rename refactorings are gold in some cases 🙂 To just hit ctrl+shift+r or f2 and rename the symbol under the cursor, to avoid classic search and replace.

I know that the PR is huge, but also the functionality is complex.

@andyleejordan
Copy link
Member

I would really like to get this feature in, yes. However, we're currently paused on feature work for a bit while some security work takes priority. Said another way: please expect to see it within the year, but probably not in the next month.

@silverqx
Copy link

silverqx commented Jun 1, 2024

Ok, thx for stating it out, would be nice to make it a little quicker but whatever, at least check-in it out and test it to see if it works and in which state the PR is would be a good idea. I think that having a new feature like this is more interesting for developers than having npm packages at the latest versions every month or every release 😁

@JustinGrote
Copy link
Collaborator

For what it's worth I'm currently reviewing the PSES part of this to hopefully help reduce the friction when the opportunity arises for a more thorough review.

@andyleejordan
Copy link
Member

Justin's work will be very helpful and should speed up the process!

src/features/RenameSymbol.ts Outdated Show resolved Hide resolved
src/features/RenameSymbol.ts Outdated Show resolved Hide resolved
src/main.ts Outdated Show resolved Hide resolved
@JustinGrote
Copy link
Collaborator

Here is a build of the latest PSES rename changes. Lots of progress to go but it's here to test out:
powershell-2024.6.0-renameAlpha.vsix.zip

You'll need to rename the .vsix.zip to just .vsix and then install using VSIX locally with vscode.

@JustinGrote
Copy link
Collaborator

JustinGrote commented Jun 5, 2024

Caught here too:

$NeededTools = @{
    OpenSsl       = 'openssl for macOS'
    PowerShellGet = 'PowerShellGet latest'
    InvokeBuild   = 'InvokeBuild latest'
}

function getMissingTools () {
    $missingTools = @()

    if (needsOpenSsl) {
        $missingTools += $NeededTools.OpenSsl
    }
    if (needsPowerShellGet) {
        $missingTools += $NeededTools.PowerShellGet
    }
    if (needsInvokeBuild) {
        $missingTools += $NeededTools.InvokeBuild
    }

    return $missingTools
}

If you try to rename $NeededTools inside the function, it only renames the external reference but not the internal ones. Vice-versa does not work, if we support one we should support the other.

Maybe this should be a configurable option? Or maybe we require SCRIPT or GLOBAL scope references in order for rename of variables referenced outside functions to work? Probably good to put a warning here that if you try to rename an inner referenced variable but the initial reference is not found, should fail with a nice error message explaining that.

Should maybe look at the AST logic of PSUseDeclaredVarsMoreThanAssignments as a reference (or even call it directly) for finding those references.

@andyleejordan
Copy link
Member

Hi! We discussed this in triage and our main condition on accepting it is that it's an opt-in feature controlled by a setting that ideally has a good explanation of when and how it can fail (due to PowerShell scoping). As long as it's opt-in most of our concerns don't apply.

@JustinGrote
Copy link
Collaborator

JustinGrote commented Jun 6, 2024

Hi! We discussed this in triage and our main condition on accepting it is that it's an opt-in feature controlled by a setting that ideally has a good explanation of when and how it can fail (due to PowerShell scoping). As long as it's opt-in most of our concerns don't apply.

Right, I was thinking more specifically for this handling, but I plan to assist it in such a way that it will operate as such:

First time you attempt F2 rename, a popup will appear with a link to Markdown docs we will have in the docs section explaining about PowerShell being a dynamic language, and the limitations and at-your-own-risk aspects. You will then have to click an "Accept", "Accept for Workspace", etc. option that will drop a setting in the appropriate location to suppress the dialog and allow rename to continue.

package.json Outdated
@@ -1016,6 +1016,11 @@
],
"default": "off",
"description": "Traces the communication between VS Code and the PowerShell Editor Services language server. **This setting is only meant for extension developers!**"
},
"powershell.renameSymbol.shouldGenerateAlias": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just from a UX perspective, since this is user facing it can probably be simplified to powershell.rename.createAlias to be generally in line with conventions I see for VSCode settings. Nice work!

@JustinGrote
Copy link
Collaborator

@Razmo99 this is great work, FYI, I will be PTO June 14-28 in Europe so I may be limited in further reviews until then but I will probably show this off at PSConfEU and give you full credit!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants