@@ -13,11 +13,8 @@ namespace Microsoft.PowerShell.EditorServices.Services.Extension
13
13
{
14
14
internal class EditorOperationsService : IEditorOperations
15
15
{
16
- private const bool DefaultPreviewSetting = true ;
17
-
18
16
private readonly PsesInternalHost _psesHost ;
19
17
private readonly WorkspaceService _workspaceService ;
20
-
21
18
private readonly ILanguageServerFacade _languageServer ;
22
19
23
20
public EditorOperationsService (
@@ -72,7 +69,7 @@ public async Task InsertTextAsync(string filePath, string text, BufferRange inse
72
69
Character = insertRange . End . Column - 1
73
70
}
74
71
}
75
- } ) . ReturningVoid ( CancellationToken . None ) . ConfigureAwait ( false ) ;
72
+ } ) . Returning < EditorOperationResponse > ( CancellationToken . None ) . ConfigureAwait ( false ) ;
76
73
}
77
74
78
75
public async Task SetSelectionAsync ( BufferRange selectionRange )
@@ -98,7 +95,7 @@ public async Task SetSelectionAsync(BufferRange selectionRange)
98
95
Character = selectionRange . End . Column - 1
99
96
}
100
97
}
101
- } ) . ReturningVoid ( CancellationToken . None ) . ConfigureAwait ( false ) ;
98
+ } ) . Returning < EditorOperationResponse > ( CancellationToken . None ) . ConfigureAwait ( false ) ;
102
99
}
103
100
104
101
public EditorContext ConvertClientEditorContext (
@@ -123,15 +120,15 @@ public EditorContext ConvertClientEditorContext(
123
120
clientContext . CurrentFileLanguage ) ;
124
121
}
125
122
126
- public async Task NewFileAsync ( )
123
+ public async Task NewFileAsync ( string content = "" )
127
124
{
128
125
if ( ! TestHasLanguageServer ( ) )
129
126
{
130
127
return ;
131
128
}
132
129
133
- await _languageServer . SendRequest < string > ( "editor/newFile" , null )
134
- . ReturningVoid ( CancellationToken . None )
130
+ await _languageServer . SendRequest ( "editor/newFile" , content )
131
+ . Returning < EditorOperationResponse > ( CancellationToken . None )
135
132
. ConfigureAwait ( false ) ;
136
133
}
137
134
@@ -145,8 +142,8 @@ public async Task OpenFileAsync(string filePath)
145
142
await _languageServer . SendRequest ( "editor/openFile" , new OpenFileDetails
146
143
{
147
144
FilePath = filePath ,
148
- Preview = DefaultPreviewSetting
149
- } ) . ReturningVoid ( CancellationToken . None ) . ConfigureAwait ( false ) ;
145
+ Preview = true
146
+ } ) . Returning < EditorOperationResponse > ( CancellationToken . None ) . ConfigureAwait ( false ) ;
150
147
}
151
148
152
149
public async Task OpenFileAsync ( string filePath , bool preview )
@@ -160,7 +157,7 @@ public async Task OpenFileAsync(string filePath, bool preview)
160
157
{
161
158
FilePath = filePath ,
162
159
Preview = preview
163
- } ) . ReturningVoid ( CancellationToken . None ) . ConfigureAwait ( false ) ;
160
+ } ) . Returning < EditorOperationResponse > ( CancellationToken . None ) . ConfigureAwait ( false ) ;
164
161
}
165
162
166
163
public async Task CloseFileAsync ( string filePath )
@@ -171,7 +168,7 @@ public async Task CloseFileAsync(string filePath)
171
168
}
172
169
173
170
await _languageServer . SendRequest ( "editor/closeFile" , filePath )
174
- . ReturningVoid ( CancellationToken . None )
171
+ . Returning < EditorOperationResponse > ( CancellationToken . None )
175
172
. ConfigureAwait ( false ) ;
176
173
}
177
174
@@ -188,11 +185,11 @@ public async Task SaveFileAsync(string currentPath, string newSavePath)
188
185
{
189
186
FilePath = currentPath ,
190
187
NewPath = newSavePath
191
- } ) . ReturningVoid ( CancellationToken . None ) . ConfigureAwait ( false ) ;
188
+ } ) . Returning < EditorOperationResponse > ( CancellationToken . None ) . ConfigureAwait ( false ) ;
192
189
}
193
190
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 .
196
193
public string GetWorkspacePath ( ) => _workspaceService . InitialWorkingDirectory ;
197
194
198
195
public string GetWorkspaceRelativePath ( string filePath ) => _workspaceService . GetRelativePath ( filePath ) ;
@@ -205,7 +202,7 @@ public async Task ShowInformationMessageAsync(string message)
205
202
}
206
203
207
204
await _languageServer . SendRequest ( "editor/showInformationMessage" , message )
208
- . ReturningVoid ( CancellationToken . None )
205
+ . Returning < EditorOperationResponse > ( CancellationToken . None )
209
206
. ConfigureAwait ( false ) ;
210
207
}
211
208
@@ -217,7 +214,7 @@ public async Task ShowErrorMessageAsync(string message)
217
214
}
218
215
219
216
await _languageServer . SendRequest ( "editor/showErrorMessage" , message )
220
- . ReturningVoid ( CancellationToken . None )
217
+ . Returning < EditorOperationResponse > ( CancellationToken . None )
221
218
. ConfigureAwait ( false ) ;
222
219
}
223
220
@@ -229,7 +226,7 @@ public async Task ShowWarningMessageAsync(string message)
229
226
}
230
227
231
228
await _languageServer . SendRequest ( "editor/showWarningMessage" , message )
232
- . ReturningVoid ( CancellationToken . None )
229
+ . Returning < EditorOperationResponse > ( CancellationToken . None )
233
230
. ConfigureAwait ( false ) ;
234
231
}
235
232
@@ -244,7 +241,7 @@ public async Task SetStatusBarMessageAsync(string message, int? timeout)
244
241
{
245
242
Message = message ,
246
243
Timeout = timeout
247
- } ) . ReturningVoid ( CancellationToken . None ) . ConfigureAwait ( false ) ;
244
+ } ) . Returning < EditorOperationResponse > ( CancellationToken . None ) . ConfigureAwait ( false ) ;
248
245
}
249
246
250
247
public void ClearTerminal ( )
@@ -267,7 +264,7 @@ private bool TestHasLanguageServer(bool warnUser = true)
267
264
if ( warnUser )
268
265
{
269
266
_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 ." ) ;
271
268
}
272
269
273
270
return false ;
0 commit comments