Skip to content

Added NewFile() for $psEditor and new functions #517

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 6 commits into from
Jun 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -74,6 +74,7 @@ FunctionsToExport = @('Register-EditorCommand',
'ConvertFrom-ScriptExtent',
'ConvertTo-ScriptExtent',
'Get-Token',
'Out-CurrentFile',
'Join-ScriptExtent',
'Test-ScriptExtent',
'psedit')
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function Out-CurrentFile {
param(
[Parameter(ValueFromPipeline)]
$data
)

Begin { $d = @() }
Process { $d += $data }
End {
$target = "@`"`r`n{0}`r`n`"@" -f ($d|out-string).Trim()
$pseditor.GetEditorContext().currentfile.inserttext($target)
}
}
Original file line number Diff line number Diff line change
@@ -101,6 +101,13 @@ public static readonly
public Position CursorPosition { get; set; }
}

public class NewFileRequest
{
public static readonly
RequestType<string, EditorCommandResponse, object, object> Type =
RequestType<string, EditorCommandResponse, object, object>.Create("editor/newFile");
}

public class OpenFileRequest
{
public static readonly
Original file line number Diff line number Diff line change
@@ -101,6 +101,15 @@ public EditorContext ConvertClientEditorContext(
clientContext.SelectionRange.End.Character + 1));
}

public Task NewFile()
{
return
this.messageSender.SendRequest(
NewFileRequest.Type,
null,
true);
}

public Task OpenFile(string filePath)
{
return
8 changes: 8 additions & 0 deletions src/PowerShellEditorServices/Extensions/EditorWorkspace.cs
Original file line number Diff line number Diff line change
@@ -40,6 +40,14 @@ internal EditorWorkspace(IEditorOperations editorOperations)

#region Public Methods

/// <summary>
/// Creates a new file in the editor
/// </summary>
public void NewFile()
{
this.editorOperations.NewFile().Wait();
}

/// <summary>
/// Opens a file in the workspace. If the file is already open
/// its buffer will be made active.
2 changes: 2 additions & 0 deletions src/PowerShellEditorServices/Extensions/IEditorOperations.cs
Original file line number Diff line number Diff line change
@@ -33,6 +33,8 @@ public interface IEditorOperations
/// <returns>The resolved file path.</returns>
string GetWorkspaceRelativePath(string filePath);

Task NewFile();

/// <summary>
/// Causes a file to be opened in the editor. If the file is
/// already open, the editor must switch to the file.
Original file line number Diff line number Diff line change
@@ -174,6 +174,7 @@ await this.extensionEventQueue.EnqueueAsync(

public class TestEditorOperations : IEditorOperations
{

public string GetWorkspacePath()
{
throw new NotImplementedException();
@@ -184,6 +185,11 @@ public string GetWorkspaceRelativePath(string filePath)
throw new NotImplementedException();
}

public Task NewFile()
{
throw new NotImplementedException();
}

public Task OpenFile(string filePath)
{
throw new NotImplementedException();