salesforcedx-vscode icon indicating copy to clipboard operation
salesforcedx-vscode copied to clipboard

fix: flushFilePath() with fix for Windows

Open jeffb-sfdc opened this issue 1 year ago • 2 comments

What does this PR do?

There's a bug in VS Code, which Microsoft refuses to fix (see https://github.com/microsoft/vscode/issues/152993). After a file has been renamed, if only the casing has changes (eg no characters added or removed) VS Code passes the stale path to commands. This PR adds flushFilePath() and flushFilePaths() to fix this issue.

What issues does this PR fix or reference?

#https://github.com/forcedotcom/salesforcedx-vscode/issues/3575, @W-10273785@

Functionality Before

  1. Rename an Apex class's file name (only changing the case of the filename), and rename it's metadata file
  2. Open the file and change the name of the class to match
  3. With the file open, right-click in the editor and select "SFDX : Deploy This Source to Org"
  4. This results in an error in the output: "File name mismatch with class name"

Functionality After

1-3: the same 4. This deployment succeeds

jeffb-sfdc avatar Aug 11 '22 16:08 jeffb-sfdc

This PR was originally https://github.com/forcedotcom/salesforcedx-vscode/pull/4240, but needed to be backed out due to an issue running on Windows. I looked into the issue, and it was b/c under Windows, fs.realpathSync.native() returns a string with the first character (the drive letter) capitalized, and this causes code to fail further downstream.

jeffb-sfdc avatar Aug 11 '22 16:08 jeffb-sfdc

I ran the same tests on M1 Mac as on the last PR, all checks out:

✅ SFDX: Deploy Source to Org works after renaming locally by only making changes to the casing in the file+class name ✅ SFDX: Deploy Source to Org works when deploying multiple files after renaming one locally by only making changes to the casing in the file+class name ✅ SFDX: Retrieve Source from Org works as before * Note: If you rename locally, you still need to deploy the class first so that it is renamed on the server before executing a “Retrieve” operation ✅ SFDX: Delete from Project and Org works as before * Note: Similarly, if you rename the component/class locally, you need to deploy it so that the name is aligned on the server before running a delete operation

klewis-sfdc avatar Aug 11 '22 20:08 klewis-sfdc