Skip to content

Commit e9310f9

Browse files
Merge pull request #2000 from PowerShell/andschwa/code-review
Code clean-up and fixing end-to-end tests
2 parents 97ae16a + 50ee6ad commit e9310f9

27 files changed

+82
-200
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dotnet_diagnostic.CS0649.severity = error
3939
# CS1570: Parameter has no matching param tag in the XML comment
4040
dotnet_diagnostic.CS1570.severity = silent
4141
# CS1574: XML comment has cref attribute that could not be resolved.
42-
dotnet_diagnostic.CS1574.severity = suggestion
42+
dotnet_diagnostic.CS1574.severity = silent
4343
# CS1591: Missing XML comment for publicly visible type or member
4444
dotnet_diagnostic.CS1591.severity = silent
4545
# CS1998: This async method lacks 'await' operators and will run synchronously

PowerShellEditorServices.build.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ Task TestE2E Build, SetupHelpForTests, {
203203
Set-Location .\test\PowerShellEditorServices.Test.E2E\
204204

205205
$env:PWSH_EXE_NAME = if ($IsCoreCLR) { "pwsh" } else { "powershell" }
206-
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS72 }
206+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS73 }
207207

208208
if (!$script:IsNix) {
209209
if (-not [Security.Principal.WindowsIdentity]::GetCurrent().Owner.IsWellKnown("BuiltInAdministratorsSid")) {
@@ -214,7 +214,7 @@ Task TestE2E Build, SetupHelpForTests, {
214214
try {
215215
Write-Host "Running end-to-end tests in Constrained Language Mode."
216216
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", "0x80000007", [System.EnvironmentVariableTarget]::Machine);
217-
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS72 }
217+
Invoke-BuildExec { & dotnet $script:dotnetTestArgs $script:NetRuntime.PS73 }
218218
} finally {
219219
[System.Environment]::SetEnvironmentVariable("__PSLockdownPolicy", $null, [System.EnvironmentVariableTarget]::Machine);
220220
}

src/PowerShellEditorServices/Extensions/EditorContext.cs

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,26 +86,15 @@ public void SetSelection(
8686
/// </summary>
8787
/// <param name="startPosition">The starting position of the selection.</param>
8888
/// <param name="endPosition">The ending position of the selection.</param>
89-
public void SetSelection(
90-
FilePosition startPosition,
91-
FilePosition endPosition)
92-
{
93-
SetSelection(
94-
new FileRange(
95-
startPosition,
96-
endPosition));
97-
}
89+
public void SetSelection(FilePosition startPosition, FilePosition endPosition) => SetSelection(new FileRange(startPosition, endPosition));
9890

9991
/// <summary>
10092
/// Sets a selection in the host editor's active buffer.
10193
/// </summary>
10294
/// <param name="selectionRange">The range of the selection.</param>
103-
public void SetSelection(FileRange selectionRange)
104-
{
105-
editorOperations
106-
.SetSelectionAsync(selectionRange.ToBufferRange())
107-
.Wait();
108-
}
95+
#pragma warning disable VSTHRD002
96+
public void SetSelection(FileRange selectionRange) => editorOperations.SetSelectionAsync(selectionRange.ToBufferRange()).Wait();
97+
#pragma warning restore VSTHRD002
10998

11099
#endregion
111100
}

src/PowerShellEditorServices/Extensions/EditorFileRanges.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public interface ILspCurrentFileContext : IFileContext
274274
ILspFileRange SelectionRange { get; }
275275
}
276276

277-
internal struct OmnisharpLspPosition : ILspFilePosition, IEquatable<OmnisharpLspPosition>
277+
internal readonly struct OmnisharpLspPosition : ILspFilePosition, IEquatable<OmnisharpLspPosition>
278278
{
279279
private readonly Position _position;
280280

@@ -287,7 +287,7 @@ internal struct OmnisharpLspPosition : ILspFilePosition, IEquatable<OmnisharpLsp
287287
public bool Equals(OmnisharpLspPosition other) => _position == other._position;
288288
}
289289

290-
internal struct OmnisharpLspRange : ILspFileRange, IEquatable<OmnisharpLspRange>
290+
internal readonly struct OmnisharpLspRange : ILspFileRange, IEquatable<OmnisharpLspRange>
291291
{
292292
private readonly Range _range;
293293

@@ -300,7 +300,7 @@ internal struct OmnisharpLspRange : ILspFileRange, IEquatable<OmnisharpLspRange>
300300
public bool Equals(OmnisharpLspRange other) => _range == other._range;
301301
}
302302

303-
internal struct BufferFilePosition : IFilePosition, IEquatable<BufferFilePosition>
303+
internal readonly struct BufferFilePosition : IFilePosition, IEquatable<BufferFilePosition>
304304
{
305305
private readonly BufferPosition _position;
306306

@@ -317,7 +317,7 @@ public bool Equals(BufferFilePosition other)
317317
}
318318
}
319319

320-
internal struct BufferFileRange : IFileRange, IEquatable<BufferFileRange>
320+
internal readonly struct BufferFileRange : IFileRange, IEquatable<BufferFileRange>
321321
{
322322
private readonly BufferRange _range;
323323

src/PowerShellEditorServices/Extensions/EditorObject.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ internal EditorObject(
115115
/// at the time this method is invoked.
116116
/// </summary>
117117
/// <returns>A instance of the EditorContext class.</returns>
118+
#pragma warning disable VSTHRD002, VSTHRD104
118119
public EditorContext GetEditorContext() => _editorOperations.GetEditorContextAsync().Result;
120+
#pragma warning restore VSTHRD002, VSTHRD104
119121

120122
internal void SetAsStaticInstance()
121123
{

src/PowerShellEditorServices/Extensions/EditorWindow.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ internal EditorWindow(IEditorOperations editorOperations)
3939
#endregion
4040

4141
#region Public Methods
42+
#pragma warning disable VSTHRD002 // These are public APIs that use async internal methods.
4243

4344
/// <summary>
4445
/// Shows an informational message to the user.
@@ -71,6 +72,7 @@ internal EditorWindow(IEditorOperations editorOperations)
7172
/// <param name="timeout">A timeout in milliseconds for how long the message should remain visible.</param>
7273
public void SetStatusBarMessage(string message, int timeout) => editorOperations.SetStatusBarMessageAsync(message, timeout).Wait();
7374

75+
#pragma warning restore VSTHRD002
7476
#endregion
7577
}
7678
}

src/PowerShellEditorServices/Extensions/EditorWorkspace.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public sealed class EditorWorkspace
3131
#endregion
3232

3333
#region Public Methods
34+
#pragma warning disable VSTHRD002 // These are public APIs that use async internal methods.
3435

3536
/// <summary>
3637
/// Creates a new file in the editor
@@ -53,6 +54,7 @@ public sealed class EditorWorkspace
5354
/// <param name="preview">Determines wether the file is opened as a preview or as a durable editor.</param>
5455
public void OpenFile(string filePath, bool preview) => editorOperations.OpenFileAsync(filePath, preview).Wait();
5556

57+
#pragma warning restore VSTHRD002
5658
#endregion
5759
}
5860
}

src/PowerShellEditorServices/Extensions/FileContext.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,14 @@ public void InsertText(
209209
/// </summary>
210210
/// <param name="textToInsert">The text string to insert.</param>
211211
/// <param name="insertRange">The buffer range which will be replaced by the string.</param>
212+
#pragma warning disable VSTHRD002
212213
public void InsertText(string textToInsert, IFileRange insertRange)
213214
{
214215
editorOperations
215216
.InsertTextAsync(scriptFile.DocumentUri.ToString(), textToInsert, insertRange.ToBufferRange())
216217
.Wait();
217218
}
219+
#pragma warning restore VSTHRD002
218220

219221
#endregion
220222

@@ -232,6 +234,7 @@ public void InsertText(string textToInsert, IFileRange insertRange)
232234
/// the path where the file should be saved,
233235
/// including the file name with extension as the leaf
234236
/// </param>
237+
#pragma warning disable VSTHRD002
235238
public void SaveAs(string newFilePath)
236239
{
237240
// Do some validation here so that we can provide a helpful error if the path won't work
@@ -244,8 +247,9 @@ public void SaveAs(string newFilePath)
244247
throw new IOException(string.Format("The file '{0}' already exists", absolutePath));
245248
}
246249

247-
editorOperations.SaveFileAsync(scriptFile.FilePath, newFilePath);
250+
editorOperations.SaveFileAsync(scriptFile.FilePath, newFilePath).Wait();
248251
}
252+
#pragma warning restore VSTHRD002
249253

250254
#endregion
251255
}

src/PowerShellEditorServices/Hosting/EditorServicesServerFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static EditorServicesServerFactory Create(string logPath, int minimumLogL
8383
/// <param name="inputStream">The protocol transport input stream.</param>
8484
/// <param name="outputStream">The protocol transport output stream.</param>
8585
/// <param name="hostStartupInfo">The host details configuration for Editor Services
86-
/// instantation.</param>
86+
/// instantiation.</param>
8787
/// <returns>A new, unstarted language server instance.</returns>
8888
public PsesLanguageServer CreateLanguageServer(
8989
Stream inputStream,

src/PowerShellEditorServices/Logging/LoggerExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace Microsoft.PowerShell.EditorServices.Logging
99
{
1010
internal static class LoggerExtensions
1111
{
12+
// TODO: These need to be fixed (and used consistently).
1213
public static void LogException(
1314
this ILogger logger,
1415
string message,

0 commit comments

Comments
 (0)