-
Notifications
You must be signed in to change notification settings - Fork 511
Fix issue with cwd being set to untitled file path #656
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What if the config.script is set to
Invoke-Pester
? Will we try to set that to the CWD?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.
I don't know about you, but it's getting to be a bit harder keeping straight the matrix of no-folder vs folder workspaces (ie existence of launch.json) and unsaved vs saved file debugging.
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.
Yeah, it is. Any ideas?
Regarding Invoke-Pester, I think we'll have to check the string for validity as a path before trying to use it. Though that might not exactly be reliable...
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.
That check is something we do on the PSES side.
Regarding alternatives, I think around line 37, where we handle the no-folder workspace case we assign cwd there. It would be the filepath if the document has been saved otherwise the workspace rootPath. That leaves the unsaved file with a launch.json case. That by default want's to use "${file}" for the cwd. After line 53 we could set the CWD to the workspace root. Then move the sanity check on CWD to the end of the
if (config.request === 'launch')
. Does that make sense?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.
Let me take a crack at a PR, would be easier to visualize anyway. :-)
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.
When I let
undefined
slip through as cwd, the debug session seems to hang. Wasn't that the original issue?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.
Weird, it was working fine for me. But yeah, you're right... In theory that would cause the workingDir to be set to the path of the file in the debug adapter. Maybe we should take out this logic in one of the places? Maybe make the debug adapter dumb and the extension code smart?
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.
OK so if we pass undefined or null we get to this code:
That tries to set the CWD to untitled:Untitled-1. Then we try to get file attrs on that and it throws. In the catch handler, we reset workingDir to
null
and then later that gets set toEnvironment.CurrentDirectory
which is initially $Home. But that can change in the integrated console as the user cd's around. Not sure if that is a feature or a problem. Anyway, specifically for unsaved files, seems like we should handle setting the working dir on the PSES side since it eventually knows where it will save the text in order to run it. I assume you actually save the unsaved file contents to a file to run it. Is that correct? If so, then we could set the CWD to path holding the temp file. Do you think that makes sense? I'm not so sure. It is unlikely that would be advantageous. So maybe we force it $home (always writable and any relative path file output generated by the script would be easier to find) or we stick with Environment.CurrentDirectory.If we go with home then we should be able to specify that on the extension side ${env.HOME} or something like that (assuming we find a xplat env var). OK that's a lot of yammering. Your thoughts?
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.
Currently I'm not saving the untitled file contents to a file. Since the language server already has the contents of the untitled file, I just execute the entire file buffer as a script without saving to a file first. This is also what the ISE does with untitled files when you press F5. In the future I might want to save to a temp file so that we can set virtual breakpoints in the untitled script, but then we might run into issues for folks with a restrictive ExecutionPolicy set.
Now that I think about it, does it even make sense to try and set the cwd path when running a script in the shared integrated console session? It's basically resetting the user's current file path. Definitely makes sense with unique debug sessions, but we're not back to that point yet.
Sticking with the Environment.CurrentDirectory approach for now could be fine until we have more time to come up with a better solution. I'm planning to ship a patch update tomorrow morning to resolve some issues we found while preparing demos for the PS Summit.
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.
Sounds good. Then for the unsaved file, the cwd will come through as undefined, then PSES will temporarily set it to
untitled:Untitled-N
and then set it back to Env.CurrentDir orAppContext.BaseDirectory
on CoreCLR. We might want to cleanup the handling of this on the PSES later but should be OK for now. I'll submit my PR soon for you to check out.