-
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 6 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 |
---|---|---|
|
@@ -57,6 +57,35 @@ public Workspace(Version powerShellVersion, ILogger logger) | |
|
||
#region Public Methods | ||
|
||
/// <summary> | ||
/// Creates a new ScriptFile instance which is identified by the given file | ||
/// path and initially contains the given buffer contents. | ||
/// </summary> | ||
/// <param name="filePath">The file path for which a buffer will be retrieved.</param> | ||
/// <param name="initialBuffer">The initial buffer contents if there is not an existing ScriptFile for this path.</param> | ||
/// <returns>A ScriptFile instance for the specified path.</returns> | ||
public ScriptFile CreateScriptFileFromFileBuffer(string filePath, string initialBuffer) | ||
{ | ||
Validate.IsNotNullOrEmptyString("filePath", filePath); | ||
|
||
// Resolve the full file path | ||
string resolvedFilePath = this.ResolveFilePath(filePath); | ||
string keyName = resolvedFilePath.ToLower(); | ||
SeeminglyScience marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
ScriptFile scriptFile = | ||
new ScriptFile( | ||
resolvedFilePath, | ||
filePath, | ||
initialBuffer, | ||
this.powerShellVersion); | ||
|
||
this.workspaceFiles[keyName] = scriptFile; | ||
|
||
this.logger.Write(LogLevel.Verbose, "Opened file as in-memory buffer: " + resolvedFilePath); | ||
|
||
return scriptFile; | ||
} | ||
|
||
/// <summary> | ||
/// Gets an open file in the workspace. If the file isn't open but | ||
/// exists on the filesystem, load and return it. | ||
|
@@ -101,6 +130,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.