-
Notifications
You must be signed in to change notification settings - Fork 236
Fix New-EditorFile failing when no Editor window open #1411
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
Conversation
} | ||
catch { | ||
# If there's no editor, this throws an error. Create a new file, and grab the context here. | ||
# This feels really hacky way to do it, but not sure if there's another way to detect editor context... |
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.
This definitely appears like it would work, so I don't mind the approach. I would like to know if there's a way to test if an editor context exists (if so we can avoid exception handling), and if creating a new file on the workspace is the best way to generate a new editor context. If this is the only approach, then I feel like our interface is lacking because as someone new to the code, I would have expected something like:
GetEditorContext()
(which exists)HasEditorContext()
(essentially says if the above would throw)NewEditorContext()
(to create one, instead of relying what I presume is a side-effect ofWorkspace.NewFile()
)
Ah ok so @andschwa's comment has reminded me of the deeper nature of this API, and that it's essentially an old API that had to undergo some changes when we migrated to Omnisharp. Here's the actual implementation of the method that gets called: Lines 34 to 49 in b243fe3
Some things we should look at here are:
|
@corbob what does the full error message look like here? |
In particular wrt @andschwa's proposal, my counter proposal would just be for |
…e.ps1 Co-authored-by: Robert Holt <rjmholt@gmail.com>
Here's a screenshot for color coding, followed by the copy/paste of the error:
|
Well that's not very helpful. Ok my proposal for now is that we move the logic in the script inside the API call so that the file is created internally to it. Also we should change the call that throws to use |
Thanks @corbob! |
Fixes PowerShell/vscode-powershell#3180
This feels janky, but short of moving the context gathering later and doing a bunch of work we can't complete because of Temp session I'm not sure of a better way.
I've also updated the help to reference the correct filename.