From 156f14e44515f0c94d38b36d20eae060ad0b0590 Mon Sep 17 00:00:00 2001 From: dfinke Date: Wed, 14 Jun 2017 18:29:25 -0400 Subject: [PATCH 1/6] Implemented NewFile for $psEditor.Workspace.NewFile() --- .../LanguageServer/EditorCommands.cs | 7 +++++++ .../Server/LanguageServerEditorOperations.cs | 9 +++++++++ .../Extensions/EditorWorkspace.cs | 5 +++++ .../Extensions/IEditorOperations.cs | 2 ++ .../Extensions/ExtensionServiceTests.cs | 6 ++++++ 5 files changed, 29 insertions(+) diff --git a/src/PowerShellEditorServices.Protocol/LanguageServer/EditorCommands.cs b/src/PowerShellEditorServices.Protocol/LanguageServer/EditorCommands.cs index 04d15c0e9..be66829a7 100644 --- a/src/PowerShellEditorServices.Protocol/LanguageServer/EditorCommands.cs +++ b/src/PowerShellEditorServices.Protocol/LanguageServer/EditorCommands.cs @@ -101,6 +101,13 @@ public static readonly public Position CursorPosition { get; set; } } + public class NewFileRequest + { + public static readonly + RequestType Type = + RequestType.Create("editor/newFile"); + } + public class OpenFileRequest { public static readonly diff --git a/src/PowerShellEditorServices.Protocol/Server/LanguageServerEditorOperations.cs b/src/PowerShellEditorServices.Protocol/Server/LanguageServerEditorOperations.cs index c8648660d..2b2746d04 100644 --- a/src/PowerShellEditorServices.Protocol/Server/LanguageServerEditorOperations.cs +++ b/src/PowerShellEditorServices.Protocol/Server/LanguageServerEditorOperations.cs @@ -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 diff --git a/src/PowerShellEditorServices/Extensions/EditorWorkspace.cs b/src/PowerShellEditorServices/Extensions/EditorWorkspace.cs index 68d113523..341616b81 100644 --- a/src/PowerShellEditorServices/Extensions/EditorWorkspace.cs +++ b/src/PowerShellEditorServices/Extensions/EditorWorkspace.cs @@ -40,6 +40,11 @@ internal EditorWorkspace(IEditorOperations editorOperations) #region Public Methods + public void NewFile() + { + this.editorOperations.NewFile().Wait(); + } + /// /// Opens a file in the workspace. If the file is already open /// its buffer will be made active. diff --git a/src/PowerShellEditorServices/Extensions/IEditorOperations.cs b/src/PowerShellEditorServices/Extensions/IEditorOperations.cs index 9471aec80..e9a970ce1 100644 --- a/src/PowerShellEditorServices/Extensions/IEditorOperations.cs +++ b/src/PowerShellEditorServices/Extensions/IEditorOperations.cs @@ -33,6 +33,8 @@ public interface IEditorOperations /// The resolved file path. string GetWorkspaceRelativePath(string filePath); + Task NewFile(); + /// /// Causes a file to be opened in the editor. If the file is /// already open, the editor must switch to the file. diff --git a/test/PowerShellEditorServices.Test/Extensions/ExtensionServiceTests.cs b/test/PowerShellEditorServices.Test/Extensions/ExtensionServiceTests.cs index a0f251fee..84bee5562 100644 --- a/test/PowerShellEditorServices.Test/Extensions/ExtensionServiceTests.cs +++ b/test/PowerShellEditorServices.Test/Extensions/ExtensionServiceTests.cs @@ -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(); From b2df8648476b2a60fc53e40a42e385dbf1b787d1 Mon Sep 17 00:00:00 2001 From: dfinke Date: Wed, 14 Jun 2017 18:30:16 -0400 Subject: [PATCH 2/6] Implemented Out-Currentfile. Sends data from the pipeline to the current open file --- .../Commands/Public/Out-CurrentFile.ps1 | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 diff --git a/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 b/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 new file mode 100644 index 000000000..cf0bad607 --- /dev/null +++ b/module/PowerShellEditorServices/Commands/Public/Out-CurrentFile.ps1 @@ -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) + } +} \ No newline at end of file From 5abbd379d6b5d3b17f24262e57e9302bd87f3d2c Mon Sep 17 00:00:00 2001 From: dfinke Date: Wed, 14 Jun 2017 18:30:52 -0400 Subject: [PATCH 3/6] Creates a new file, does a `git log --stat` pipes it to Out-CurrentFile --- .../PowerShellEditorServices/Commands/Public/Get-GitLog.ps1 | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 module/PowerShellEditorServices/Commands/Public/Get-GitLog.ps1 diff --git a/module/PowerShellEditorServices/Commands/Public/Get-GitLog.ps1 b/module/PowerShellEditorServices/Commands/Public/Get-GitLog.ps1 new file mode 100644 index 000000000..e8298622a --- /dev/null +++ b/module/PowerShellEditorServices/Commands/Public/Get-GitLog.ps1 @@ -0,0 +1,4 @@ +function Get-GitLog { + $psEditor.Workspace.NewFile() + git log --stat | Out-CurrentFile +} From 0c93a60be6e22ec2a17ee824fb477377290efb9a Mon Sep 17 00:00:00 2001 From: dfinke Date: Wed, 14 Jun 2017 18:31:03 -0400 Subject: [PATCH 4/6] Export the new functions for performance --- .../Commands/PowerShellEditorServices.Commands.psd1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 b/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 index cd4bf764c..ffec73a08 100644 --- a/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 +++ b/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 @@ -73,7 +73,9 @@ FunctionsToExport = @('Register-EditorCommand', 'Import-EditorCommand', 'ConvertFrom-ScriptExtent', 'ConvertTo-ScriptExtent', - 'Get-Token', + 'Get-Token', + 'Get-GitLog', + 'Out-CurrentFile', 'Join-ScriptExtent', 'Test-ScriptExtent', 'psedit') From 997cd2dad0ac0f8b14c37c815e95f81d624bd99b Mon Sep 17 00:00:00 2001 From: dfinke Date: Wed, 14 Jun 2017 19:33:12 -0400 Subject: [PATCH 5/6] Removed Get-GitLog.ps1, updated psd1 --- .../Commands/PowerShellEditorServices.Commands.psd1 | 5 ++--- .../PowerShellEditorServices/Commands/Public/Get-GitLog.ps1 | 4 ---- 2 files changed, 2 insertions(+), 7 deletions(-) delete mode 100644 module/PowerShellEditorServices/Commands/Public/Get-GitLog.ps1 diff --git a/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 b/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 index ffec73a08..9e4fcb42e 100644 --- a/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 +++ b/module/PowerShellEditorServices/Commands/PowerShellEditorServices.Commands.psd1 @@ -73,9 +73,8 @@ FunctionsToExport = @('Register-EditorCommand', 'Import-EditorCommand', 'ConvertFrom-ScriptExtent', 'ConvertTo-ScriptExtent', - 'Get-Token', - 'Get-GitLog', - 'Out-CurrentFile', + 'Get-Token', + 'Out-CurrentFile', 'Join-ScriptExtent', 'Test-ScriptExtent', 'psedit') diff --git a/module/PowerShellEditorServices/Commands/Public/Get-GitLog.ps1 b/module/PowerShellEditorServices/Commands/Public/Get-GitLog.ps1 deleted file mode 100644 index e8298622a..000000000 --- a/module/PowerShellEditorServices/Commands/Public/Get-GitLog.ps1 +++ /dev/null @@ -1,4 +0,0 @@ -function Get-GitLog { - $psEditor.Workspace.NewFile() - git log --stat | Out-CurrentFile -} From d95d2e2c83565eb42529bc54f1309c013f8ed770 Mon Sep 17 00:00:00 2001 From: dfinke Date: Wed, 14 Jun 2017 19:33:22 -0400 Subject: [PATCH 6/6] Added XML comment --- src/PowerShellEditorServices/Extensions/EditorWorkspace.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/PowerShellEditorServices/Extensions/EditorWorkspace.cs b/src/PowerShellEditorServices/Extensions/EditorWorkspace.cs index 341616b81..8923b48ef 100644 --- a/src/PowerShellEditorServices/Extensions/EditorWorkspace.cs +++ b/src/PowerShellEditorServices/Extensions/EditorWorkspace.cs @@ -40,6 +40,9 @@ internal EditorWorkspace(IEditorOperations editorOperations) #region Public Methods + /// + /// Creates a new file in the editor + /// public void NewFile() { this.editorOperations.NewFile().Wait();