forcedotcom / salesforcedx-vscode

Salesforce Extensions for VS Code
https://developer.salesforce.com/tools/vscode
BSD 3-Clause "New" or "Revised" License
947 stars 404 forks source link

Cannot read property 'fspath' of undefined --> when using a Keyboard shortcut to deploy Salesforce file #662

Closed pranaymistry closed 5 years ago

pranaymistry commented 5 years ago

I added a custom keyboard shortcut to deploy current file using "sfdx.force.source.deploy.current.file" command

One of our business requirements is to figure out a keyboard shortcut that can do Save and compile of Apex classes from VSCode while doing ORG based development. This is very important for us to roll out VSCode and drive adoption of its use for Salesforce development. This feature is currently not available in VSCode and hence I tried adding a keyboard shortcut for the sfdx command but I am running into an issue.

Steps To Reproduce:

  1. Go to Code --> Preferences --> Keyboard Shortcuts
screen shot 2018-10-05 at 9 17 56 am
  1. Open keybindings.json file
screen shot 2018-10-05 at 9 19 37 am
  1. Add the below command in your keybindings.json file

[ { "key": "shift+cmd+r", "command": "sfdx.force.source.deploy.current.file" } ]

  1. This is how your keybindings.json file should look like
screen shot 2018-10-05 at 9 20 54 am
  1. Now open an Apex class or Visualforce page or Trigger file and press Shift+Cmd+r

Expected result

The file should have been deployed

Actual result

screen shot 2018-10-05 at 9 23 21 am

VS Code Version:

screen shot 2018-10-05 at 9 24 51 am

SFDX CLI Version:

screen shot 2018-10-05 at 9 25 39 am

OS and version:

screen shot 2018-10-05 at 9 26 12 am

Other Commands just work perfectly fine, for e.g.

[ { "key": "shift+cmd+r", "command": "sfdx.force.org.open" } ]

screen shot 2018-10-05 at 9 40 37 am
ntotten commented 5 years ago

@lcampos I assume this is because we are using the context of current file as the file that is being right clicked on rather than the file that is actually open. This isn't strictly a bug, but rather a new use of the command. Is there a better way to identify the current file that would make this command work in both our current situation and this one (which i am assuming to mean the currently open file).

pranaymistry commented 5 years ago

@ntotten @lcampos thanks a lot for the quick response, I am basically looking to replicate Mavensmate behavior of "Save and Compile" in one action. So, when I save my file, it gets compiled and gets deployed to my Sandbox.

ntotten commented 5 years ago

Yeah, we actually have that feature planned very soon as well. ;)

lcampos commented 5 years ago

Thanks for reporting this @pranaymistry, the issue lies in that this command (as well as a few others) takes an argument to be able to run. In this case that argument is the file path of the opened file or folder you want to deploy.

There are a couple of ways we can address it but will discuss it with the team first and update this thread right after.

pranaymistry commented 5 years ago

Thanks a lot @lcampos and @ntotten for following up on this issue. Will eagerly wait for your next update.

xixiaofinland commented 5 years ago

One of my colleagues found a good way to do this:

Output: hit "cmd+shift+b" (in MacOS), it will do 1) save 2)sfdx deploy current file

Steps

  1. Go to "Terminal" in VSC top menu
  2. Click "Configure tasks..."
  3. New a task from a template
  4. Copy paste code below to "tasks.json" and save
  5. Now "cmd+shift+b" (the default build hotkey) will do what we want.
{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
    "tasks": [
    {
    "label": "ssave",
    "type": "shell",
    "command": "sfdx force:source:deploy -p ${file}",
    "group": {
    "kind": "build",
    "isDefault": true
    },
    "problemMatcher": []
    }
  ]
}
sivabalan commented 5 years ago

@ntotten @lcampos Dug around a bit and saw the error was caused by line 49 in https://github.com/forcedotcom/salesforcedx-vscode/blob/develop/packages/salesforcedx-vscode-core/src/commands/forceSourceRetrieve.ts

Changing the constructor from this,

public constructor(explorerPath: any) {
    this.explorerPath = explorerPath.fsPath;
}

to,

public constructor(explorerPath: any) {
    this.explorerPath = typeof explorerPath !== "undefined" ? explorerPath.fsPath : vscode.window.activeTextEditor.document.uri.fsPath;
}

seems to do the trick.

Would like to know any possible downsides to this fix. Thanks.

xixiaofinland commented 5 years ago

@ntotten @lcampos Dug around a bit and saw the error was caused by line 49 in https://github.com/forcedotcom/salesforcedx-vscode/blob/develop/packages/salesforcedx-vscode-core/src/commands/forceSourceRetrieve.ts

Changing the constructor from this,

public constructor(explorerPath: any) {
    this.explorerPath = explorerPath.fsPath;
}

to,

public constructor(explorerPath: any) {
    this.explorerPath = typeof explorerPath !== "undefined" ? explorerPath.fsPath : vscode.window.activeTextEditor.document.uri.fsPath;
}

seems to do the trick.

Would like to know any possible downsides to this fix. Thanks.

open source shows the power in SF world :)

lcampos commented 5 years ago

Hi @sivabalan that is a great starting point. We've started to talk internally on how to address this for a number of commands and situations since the commands can be used from different places (right-click a folder/file in File Explorer, right click on open file, keyboard shortcut) and with different attributes (the same piece of code is used for a single file or a collection of files).

For the scenario where the path is undefined, we are thinking of the following flow:

  1. Check if there's an open file 1a. Check if it's a valid file to act on (apex class, layout, etc).
  2. If no valid file is open, show the user a dropdown with values to select based on the contents of the project (similar to how we show the folder structure when using SFDX: Create Apex Class).

If you feel like opening a Pull Request for this, given you've already made progress on your side, we'd be happy to collaborate with you in getting it merged.

cc @ntotten

ChuckJonas commented 5 years ago

+1 on fixing this

JamieBriersSageCom commented 5 years ago

+1 here too. I am trying to get into using VS Code, but these minor annoyances keep me away for now.

NikitaChizhik commented 5 years ago

I commented this text at issue Deploy on Save #577. Just want to duplicate here for you to pay attention.(no offence) if you want you can delete them)

Please , could you do deploy on save. (I should press ctrl+save then with mouse choose file from left sidebar and right click and choose to deploy source to org. and repeat it every time I want to deploy) - that's a nightmare.)

Note: I am dealing with not scratch org. I develop against any org(simple). Thats my case for now. VSCode version is latest and salesforcePack version is latest.

Now I made a shortcut(ctrl+d) to deploy current open file . BUT it also doesnt work. it writes to me Cannot read property 'fsPath' of undefined.

Please look at these two bugs (which prevent me and many others not to use vsCode and this SF plugin).

Thanks for your project and work.

lcampos commented 5 years ago

Hi @NikitaChizhik, no offense taken. As an update, we currently have a change under review that will auto deploy/push code when a change is saved. We found some issues while testing it in Windows OS which we're currently sorting out. Once that's addressed and the review is approved it'll go out and be available for everyone. We'll keep this thread updated.

ntotten commented 5 years ago

Save on deploy is going out in our next release.

dujsu commented 5 years ago

Do you have an idea of when this will be available? Thanks ahead of time!

pranaymistry commented 5 years ago

Hi @ntotten,

Thanks for the update, just want to clarify, is it save on deploy or deploy on save. So when you save the file by using Cmd + S, the file will be deployed to Salesforce first and then saved on your local, correct?

Regards, Pranay

jfaderanga commented 5 years ago

@pranaymistry it should be deploy on save, it's a combination of saving it locally and deploying it to server at the same time. I am pretty excited with this fix..

pranaymistry commented 5 years ago

Thanks @jfaderanga, I too am very excited with this fix. This was the only hurdle for us rolling out VS Code as the preferred Salesforce Development IDE to our clients. Does anyone have a date for this fix going live?

lcampos commented 5 years ago

@dujsu, @pranaymistry we released some fixes to deploy on save based on the feedback we received, the latest changes are part of version 44.18.0 of the extensions.

To enable it, set the salesforcedx-vscode-core.push-or-deploy-on-save.enabled setting to true in either your user or workspace settings. More info can be found on Develop Against Any Org in Visual Studio Code (Beta).

dcstuff commented 5 years ago

Hiya folks, I stumbled onto this when I was having the same problem. One point and one question.

The 'Push-or-deploy-on-save' shows Enabled even though I had not yet enabled it. In the JSON, it was false. image

Also, I'm curious as to why saving via the Tooling API isn't an option. In the ol' Mavensmate days, or HaoIDE, which was my preferred Salesforce IDE that no one seems to know about... when you Save to Server rather than Deploy, you'd be warned if you weren't the last one to save said file... and it was also a bazillion times faster. What was the rational behind going with deploy vs save?

Thanks very much. Keep up the great work! cc @lcampos

jfaderanga commented 5 years ago

@lcampos thanks for the fix bro!..how can we adjust the auto deploy time delay after we save it using the shortcut? the default at the moment is like 5 seconds before the auto deploy kicks in....can it be real-time after save?

Xtremefaith commented 5 years ago

I've updated my CLI and Plugins, and I thought I setup shortcut key correctly but unfortunately still getting the same error.

Cannot read property 'fsPath' of undefined

image

image

What is strange is if I right-click and select the same command it works as expected: image

jfaderanga commented 5 years ago

@Xtremefaith you don't need to set binding key once you set the salesforcedx-vscode-core.push-or-deploy-on-save.enabled settings to true, it's automatic..

Xtremefaith commented 5 years ago

I don't want it to be automatic, I want the ability to save and deploy when I feel it is appropriate. Also does this then deploy just the file or does it deploy the directory?

lcampos commented 5 years ago

@jfaderanga regarding the deploy on save time delay. That's currently not configurable but we've been discussing how useful it would be to allow it to be. If you're interested in that functionality/feature I'd suggest you open a separate issue so we can have a thread specific for that.

cc @ntotten

lcampos commented 5 years ago

hi @dc7380 , regarding the push or deploy on save showing enabled, this is because of a convention that the new vscode settings UI follows. It takes the name of the setting definition and "breaks" it in a way that for our setting might look like it's enabled. Our setting is named salesforcedx-vscode-core.push-or-deploy-on-save.enabled, which the UI then takes the push-or-deploy-on-save part to be the first, grayed out text at the begining and then takes the last part of the string, enabled and sets is to white bold. If this is confusing I'd suggest opening a separate issue and we'll take a look at updating the name but that could break people's existing settings.

Regarding alerting the user of existing potential conflicts before deploying. That functionality is already available if you are using source:push which is exclusive for scratch orgs. If you are using source:deploy, which would mean working with non-scratch orgs, then we are currently working on a feature for it and can follow the specs/updates or post suggestions on the #971 open issue.

Last thing, the lack of tooling api usage. This is mainly because of current limitations in that api. It has limited metadata coverage, meaning you can only use it for a subset of the metadata that we support. Having said that, we are actively working on making things faster and do not discard it's usage in the future if it provides the performance and coverage we're looking for.

dcstuff commented 5 years ago

@lcampos Thank you for your very complete answer!

lcampos commented 5 years ago

hi @Xtremefaith, using a keybinding for existing deploy commands won't work because of limitations on how to define it and the commands depending on a filepath to be provided. We explored the possibility of changing the commands to show a quick-pick option, when no filepath was provided, and then choose the file/folder you wanted to deploy. We discarded that because of how unmanageable it became when working on medium-to-large projects and decided to invest time in releasing the current deploy on save functionality. If this is something you really want I'd suggest opening a feature request (a new issue) for it.

As to how deploy on save works, it deploys only the file that you save. E.g. if you are modifying an apex class and save it, it will wait for a few seconds to see if you're done editing it and will then deploy the file.

iFernandoSousa commented 5 years ago

Passed 4 months and the "bug" exist yet, @Xixiao007 gave the perfect solution for this problem: https://github.com/forcedotcom/salesforcedx-vscode/issues/662#issuecomment-439354751

Why SF don't update it yet :(?

ntotten commented 5 years ago

The issue has been closed. At this time, we don’t plan on addressing this. Save on deploy should solve this use case.

NikitaChizhik commented 5 years ago

If you want your product to be useful for sf developers, listen to them. Otherwise, we will not use it. I, for example, is almost ready to switch to another IDE from VSCode because of such bugs. Sorry but true.

ntotten commented 5 years ago

@NikitaChizhik Does deploy on save not resolve this for you? My understanding is people were using this as a workaround for another missing feature. As many people requested the feature, we added it and it has been available for some time.

You can find instructions here: https://forcedotcom.github.io/salesforcedx-vscode/articles/user-guide/org-development-model#deploy-source

To deploy files each time you save them, set the user or workspace setting salesforcedx-vscode-core.push-or-deploy-on-save.enabled to true.

JamieBriersSageCom commented 5 years ago

push/deploy on save is not a viable alternative for many, including myself. Many plugins can cause the file to save (such as editorconfig), plus many people have a habit of frequently saving their code, way before its compilable and ready to push to an org.

Deploy on save is a good feature for those that want it, but it is not really a reliable alternative to having a shortcut that ONLY deploys, when the developer is ready.

Just my opinion of course!

ntotten commented 5 years ago

@JamieBriersSageCom Makes sense, thanks for the explanation. I will reopen for us to implement or to accept a PR.

gbutt commented 5 years ago

Yes, this would be a great add as an alternative to deploy on save. Thanks so much for reopening this issue.

dcstuff commented 5 years ago

@lcampos Hiya, just a quick follow up re the tooling API. While I get that it doesn't support all metadata types, you should definitely consider enabling it just for those types that it does. Though I'm sure you have.. You guys know what you're doing. (I'm kind of an idiot..)

Anyhoo.. I have recently installed the SalesforceDX Code Companion extension. It uses an sfdx plugin he built which provides new commands to save/retrieve using the Tooling API, and I've gotta say... it's now all I use (for Apex anyway).

1) It's super-quick 2) He returns a diff with the option to overwrite

Ctrl-shift-c for the win. Now, I'm happy. I was honestly having a hard time being productive with the deploy to save.

Just my experience...

Anyways, keep up the great work guys!

msrivastav13 commented 5 years ago

I agree here .I got so frustrated with speed I got that I built one using the tooling API version .Salesforce should definitely consider the approach I took or give us a time line when speed by which we save to server should be improved .

ntotten commented 5 years ago

The speed is not related to the Tooling API vs Metadata API. We are working to improve the perf and will have updates coming over the next few months, but both APIs are exactly the same on the backend. It is more about how they get called (Sync vs Async) and a few other factors.

msrivastav13 commented 5 years ago

@ntotten I agree that both might look same on backend but having experimented with both APIs we do see when it comes to push simple changes to apex , aura , vf or lwc via tooling rest api they somehow take almost 0.5x less time than the other. The fact that we have to wait so much to push a simple change of apex class to server makes me inefficient as a developer . We never had this performance issues when we used Mavensmate , eclipse or even other vscode extensions for salesforce (like forcecode, mavensmate). I can understand that fixing the root cause will be permanent solution but for now i was almost blocked without building something like this .

tsalb commented 5 years ago

Agree with above - I have use cases where I want to save (to track to git or get past linter) but not compile to server just yet. I am using "right click deploy" workflow for now and this would solve for my use case.

jfaderanga commented 5 years ago

Well I think its how it was built if you want a real rapid development I think you may want to consider offline development..

On Tue, 5 Mar 2019 at 2:29 PM, James notifications@github.com wrote:

Agree with above - I have use cases where I want to save (to track to git or get past linter) but not compile to server just yet. I am using "right click deploy" workflow for now and this would solve for my use case.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/forcedotcom/salesforcedx-vscode/issues/662#issuecomment-469497445, or mute the thread https://github.com/notifications/unsubscribe-auth/AOqbILRY51T3j1j94XW0oUvDmaz2p0ulks5vTciNgaJpZM4XKVU_ .

jasmine-nguyen commented 5 years ago

+1 on this issue. I can see a pull request waiting to be approved, hopefully it will be released soon so we can optimise our workflows. Huge thanks to the devs who are working on the fix.

ntotten commented 5 years ago

This is fixed and has been released. Please reopen if you have any issues.

NikitaChizhik commented 5 years ago

it works! thanks a lot! now the dev process will be much more faster)!

jfaderanga commented 5 years ago

oh my! thanks for the hardwork mates!

On Sun, Apr 7, 2019 at 1:01 AM Nikita Chizhik notifications@github.com wrote:

it works! thanks a lot! now the dev process will be much more faster)!

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/forcedotcom/salesforcedx-vscode/issues/662#issuecomment-480498535, or mute the thread https://github.com/notifications/unsubscribe-auth/AOqbII32CnR47wc0hDYH-OxZs5ch2PQ1ks5veIyBgaJpZM4XKVU_ .

dvon88 commented 2 years ago

This issue appears to be broken again. I updated VSCode today and it now gives me the same error. Was working previously.

renatoliveira commented 2 years ago

This issue appears to be broken again. I updated VSCode today and it now gives me the same error. Was working previously.

You are not alone, same thing happening here. Right-clicking the file and selecting the deploy option still works though.

wojciech-slodziak-waeg commented 2 years ago

Same here.

AndrewKrava commented 2 years ago

Same

sqone2 commented 2 years ago

I started getting this error today too. Yesterday it worked fine. I had to disable deploy on save and right click on a file to deploy.