-
Notifications
You must be signed in to change notification settings - Fork 237
New-EditorFile works on non-powershell untitled files #774
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
Changes from 3 commits
750f17d
5807f08
fafcbd2
a4d120a
be5b707
045ebf7
75e58da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using Microsoft.PowerShell.EditorServices; | ||
using Microsoft.PowerShell.EditorServices.Extensions; | ||
using Microsoft.PowerShell.EditorServices.Protocol.LanguageServer; | ||
using Microsoft.PowerShell.EditorServices.Protocol.MessageProtocol; | ||
|
@@ -89,10 +90,17 @@ public Task SetSelection(BufferRange selectionRange) | |
public EditorContext ConvertClientEditorContext( | ||
ClientEditorContext clientContext) | ||
{ | ||
|
||
ScriptFile scriptFile = null; | ||
if (!this.editorSession.Workspace.TryGetFile(clientContext.CurrentFilePath, out scriptFile)) | ||
{ | ||
scriptFile = this.editorSession.Workspace.GetFileBuffer(clientContext.CurrentFilePath, clientContext.CurrentFileContent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Consider putting each arg on a new line |
||
} | ||
|
||
return | ||
new EditorContext( | ||
this, | ||
this.editorSession.Workspace.GetFile(clientContext.CurrentFilePath), | ||
scriptFile, | ||
new BufferPosition( | ||
clientContext.CursorPosition.Line + 1, | ||
clientContext.CursorPosition.Character + 1), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,34 @@ public ScriptFile GetFile(string filePath) | |
return scriptFile; | ||
} | ||
|
||
/// <summary> | ||
/// Tries to get an open file in the workspace. Returns true or false if it succeeds. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor nit - would probably phrase the end of the summary this way "Returns true if it succeeds, false otherwise.". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tylerl0706 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fixed :) |
||
/// </summary> | ||
/// <param name="filePath">The file path at which the script resides.</param> | ||
/// <param name="scriptFile">The out parameter that will contain the ScriptFile object.</param> | ||
public bool TryGetFile(string filePath, out ScriptFile scriptFile) | ||
{ | ||
try | ||
{ | ||
scriptFile = GetFile(filePath); | ||
return true; | ||
} | ||
catch (Exception e) when ( | ||
e is IOException || | ||
e is SecurityException || | ||
e is FileNotFoundException || | ||
e is DirectoryNotFoundException || | ||
e is PathTooLongException || | ||
e is UnauthorizedAccessException) | ||
{ | ||
this.logger.WriteException( | ||
$"Failed to set breakpoint on file: {filePath}", | ||
e); | ||
scriptFile = null; | ||
return false; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets a new ScriptFile instance which is identified by the given file path. | ||
/// </summary> | ||
|
Uh oh!
There was an error while loading. Please reload this page.