@@ -13,11 +13,8 @@ namespace Microsoft.PowerShell.EditorServices.Services.Extension
1313{
1414 internal class EditorOperationsService : IEditorOperations
1515 {
16- private const bool DefaultPreviewSetting = true ;
17-
1816 private readonly PsesInternalHost _psesHost ;
1917 private readonly WorkspaceService _workspaceService ;
20-
2118 private readonly ILanguageServerFacade _languageServer ;
2219
2320 public EditorOperationsService (
@@ -72,7 +69,7 @@ public async Task InsertTextAsync(string filePath, string text, BufferRange inse
7269 Character = insertRange . End . Column - 1
7370 }
7471 }
75- } ) . ReturningVoid ( CancellationToken . None ) . ConfigureAwait ( false ) ;
72+ } ) . Returning < EditorOperationResponse > ( CancellationToken . None ) . ConfigureAwait ( false ) ;
7673 }
7774
7875 public async Task SetSelectionAsync ( BufferRange selectionRange )
@@ -98,7 +95,7 @@ public async Task SetSelectionAsync(BufferRange selectionRange)
9895 Character = selectionRange . End . Column - 1
9996 }
10097 }
101- } ) . ReturningVoid ( CancellationToken . None ) . ConfigureAwait ( false ) ;
98+ } ) . Returning < EditorOperationResponse > ( CancellationToken . None ) . ConfigureAwait ( false ) ;
10299 }
103100
104101 public EditorContext ConvertClientEditorContext (
@@ -123,15 +120,15 @@ public EditorContext ConvertClientEditorContext(
123120 clientContext . CurrentFileLanguage ) ;
124121 }
125122
126- public async Task NewFileAsync ( )
123+ public async Task NewFileAsync ( string content = "" )
127124 {
128125 if ( ! TestHasLanguageServer ( ) )
129126 {
130127 return ;
131128 }
132129
133- await _languageServer . SendRequest < string > ( "editor/newFile" , null )
134- . ReturningVoid ( CancellationToken . None )
130+ await _languageServer . SendRequest ( "editor/newFile" , content )
131+ . Returning < EditorOperationResponse > ( CancellationToken . None )
135132 . ConfigureAwait ( false ) ;
136133 }
137134
@@ -145,8 +142,8 @@ public async Task OpenFileAsync(string filePath)
145142 await _languageServer . SendRequest ( "editor/openFile" , new OpenFileDetails
146143 {
147144 FilePath = filePath ,
148- Preview = DefaultPreviewSetting
149- } ) . ReturningVoid ( CancellationToken . None ) . ConfigureAwait ( false ) ;
145+ Preview = true
146+ } ) . Returning < EditorOperationResponse > ( CancellationToken . None ) . ConfigureAwait ( false ) ;
150147 }
151148
152149 public async Task OpenFileAsync ( string filePath , bool preview )
@@ -160,7 +157,7 @@ public async Task OpenFileAsync(string filePath, bool preview)
160157 {
161158 FilePath = filePath ,
162159 Preview = preview
163- } ) . ReturningVoid ( CancellationToken . None ) . ConfigureAwait ( false ) ;
160+ } ) . Returning < EditorOperationResponse > ( CancellationToken . None ) . ConfigureAwait ( false ) ;
164161 }
165162
166163 public async Task CloseFileAsync ( string filePath )
@@ -171,7 +168,7 @@ public async Task CloseFileAsync(string filePath)
171168 }
172169
173170 await _languageServer . SendRequest ( "editor/closeFile" , filePath )
174- . ReturningVoid ( CancellationToken . None )
171+ . Returning < EditorOperationResponse > ( CancellationToken . None )
175172 . ConfigureAwait ( false ) ;
176173 }
177174
@@ -188,11 +185,11 @@ public async Task SaveFileAsync(string currentPath, string newSavePath)
188185 {
189186 FilePath = currentPath ,
190187 NewPath = newSavePath
191- } ) . ReturningVoid ( CancellationToken . None ) . ConfigureAwait ( false ) ;
188+ } ) . Returning < EditorOperationResponse > ( CancellationToken . None ) . ConfigureAwait ( false ) ;
192189 }
193190
194- // TODO : This should get the current editor's context and use it to determine which
195- // workspace it's in .
191+ // NOTE : This name is now outdated since we don't have a way to distinguish one workspace
192+ // from another for the extension API .
196193 public string GetWorkspacePath ( ) => _workspaceService . InitialWorkingDirectory ;
197194
198195 public string GetWorkspaceRelativePath ( string filePath ) => _workspaceService . GetRelativePath ( filePath ) ;
@@ -205,7 +202,7 @@ public async Task ShowInformationMessageAsync(string message)
205202 }
206203
207204 await _languageServer . SendRequest ( "editor/showInformationMessage" , message )
208- . ReturningVoid ( CancellationToken . None )
205+ . Returning < EditorOperationResponse > ( CancellationToken . None )
209206 . ConfigureAwait ( false ) ;
210207 }
211208
@@ -217,7 +214,7 @@ public async Task ShowErrorMessageAsync(string message)
217214 }
218215
219216 await _languageServer . SendRequest ( "editor/showErrorMessage" , message )
220- . ReturningVoid ( CancellationToken . None )
217+ . Returning < EditorOperationResponse > ( CancellationToken . None )
221218 . ConfigureAwait ( false ) ;
222219 }
223220
@@ -229,7 +226,7 @@ public async Task ShowWarningMessageAsync(string message)
229226 }
230227
231228 await _languageServer . SendRequest ( "editor/showWarningMessage" , message )
232- . ReturningVoid ( CancellationToken . None )
229+ . Returning < EditorOperationResponse > ( CancellationToken . None )
233230 . ConfigureAwait ( false ) ;
234231 }
235232
@@ -244,7 +241,7 @@ public async Task SetStatusBarMessageAsync(string message, int? timeout)
244241 {
245242 Message = message ,
246243 Timeout = timeout
247- } ) . ReturningVoid ( CancellationToken . None ) . ConfigureAwait ( false ) ;
244+ } ) . Returning < EditorOperationResponse > ( CancellationToken . None ) . ConfigureAwait ( false ) ;
248245 }
249246
250247 public void ClearTerminal ( )
@@ -267,7 +264,7 @@ private bool TestHasLanguageServer(bool warnUser = true)
267264 if ( warnUser )
268265 {
269266 _psesHost . UI . WriteWarningLine (
270- "Editor operations are not supported in temporary consoles. Re-run the command in the main PowerShell Intergrated Console ." ) ;
267+ "Editor operations are not supported in temporary consoles. Re-run the command in the main Extension Terminal ." ) ;
271268 }
272269
273270 return false ;
0 commit comments