Skip to content

Commit e7fc1b5

Browse files
committed
Update CompletionHandlerTests.cs
1 parent c616c97 commit e7fc1b5

File tree

8 files changed

+276
-192
lines changed

8 files changed

+276
-192
lines changed

test/PowerShellEditorServices.Test.Shared/Completion/CompleteAttributeValue.cs

+70-16
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,80 @@
22
// Licensed under the MIT License.
33

44
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
5+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
56

67
namespace Microsoft.PowerShell.EditorServices.Test.Shared.Completion
78
{
8-
internal class CompleteAttributeValue
9+
internal static class CompleteAttributeValue
910
{
10-
public static readonly ScriptRegion SourceDetails =
11-
new ScriptRegion(
12-
file: TestUtilities.NormalizePath("Completion/CompletionExamples.psm1"),
13-
text: string.Empty,
14-
startLineNumber: 16,
15-
startColumnNumber: 38,
16-
startOffset: 0,
17-
endLineNumber: 0,
18-
endColumnNumber: 0,
19-
endOffset: 0);
11+
public static readonly ScriptRegion SourceDetails = new(
12+
file: TestUtilities.NormalizePath("Completion/CompletionExamples.psm1"),
13+
text: string.Empty,
14+
startLineNumber: 16,
15+
startColumnNumber: 38,
16+
startOffset: 0,
17+
endLineNumber: 0,
18+
endColumnNumber: 0,
19+
endOffset: 0);
2020

21-
public static readonly BufferRange ExpectedRange =
22-
new BufferRange(
23-
new BufferPosition(16, 33),
24-
new BufferPosition(16, 38));
21+
public static readonly CompletionItem ExpectedCompletion1 = new()
22+
{
23+
Kind = CompletionItemKind.Property,
24+
Detail = "System.Boolean ValueFromPipeline",
25+
InsertTextFormat = InsertTextFormat.PlainText,
26+
InsertText = "ValueFromPipeline",
27+
FilterText = "ValueFromPipeline",
28+
Label = "ValueFromPipeline",
29+
SortText = "0001ValueFromPipeline",
30+
TextEdit = new TextEdit
31+
{
32+
NewText = "ValueFromPipeline",
33+
Range = new Range
34+
{
35+
Start = new Position { Line = 15, Character = 32 },
36+
End = new Position { Line = 15, Character = 37 }
37+
}
38+
}
39+
};
40+
41+
public static readonly CompletionItem ExpectedCompletion2 = new()
42+
{
43+
Kind = CompletionItemKind.Property,
44+
Detail = "System.Boolean ValueFromPipelineByPropertyName",
45+
InsertTextFormat = InsertTextFormat.PlainText,
46+
InsertText = "ValueFromPipelineByPropertyName",
47+
FilterText = "ValueFromPipelineByPropertyName",
48+
Label = "ValueFromPipelineByPropertyName",
49+
SortText = "0002ValueFromPipelineByPropertyName",
50+
TextEdit = new TextEdit
51+
{
52+
NewText = "ValueFromPipelineByPropertyName",
53+
Range = new Range
54+
{
55+
Start = new Position { Line = 15, Character = 32 },
56+
End = new Position { Line = 15, Character = 37 }
57+
}
58+
}
59+
};
60+
61+
public static readonly CompletionItem ExpectedCompletion3 = new()
62+
{
63+
Kind = CompletionItemKind.Property,
64+
Detail = "System.Boolean ValueFromRemainingArguments",
65+
InsertTextFormat = InsertTextFormat.PlainText,
66+
InsertText = "ValueFromRemainingArguments",
67+
FilterText = "ValueFromRemainingArguments",
68+
Label = "ValueFromRemainingArguments",
69+
SortText = "0003ValueFromRemainingArguments",
70+
TextEdit = new TextEdit
71+
{
72+
NewText = "ValueFromRemainingArguments",
73+
Range = new Range
74+
{
75+
Start = new Position { Line = 15, Character = 32 },
76+
End = new Position { Line = 15, Character = 37 }
77+
}
78+
}
79+
};
2580
}
2681
}
27-

test/PowerShellEditorServices.Test.Shared/Completion/CompleteCommandFromModule.cs

+32-22
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,43 @@
33

44
using System;
55
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
6+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
67

78
namespace Microsoft.PowerShell.EditorServices.Test.Shared.Completion
89
{
9-
internal class CompleteCommandFromModule
10+
internal static class CompleteCommandFromModule
1011
{
11-
private static readonly string[] s_getRandomParamSets = {
12-
"Get-Random [[-Maximum] <Object>] [-SetSeed <int>] [-Minimum <Object>] [<CommonParameters>]",
13-
"Get-Random [-InputObject] <Object[]> [-SetSeed <int>] [-Count <int>] [<CommonParameters>]"
14-
};
12+
public static readonly string GetRandomDetail =
13+
"Get-Random [[-Maximum] <Object>] [-SetSeed <int>] [-Minimum <Object>]";
1514

16-
public static readonly ScriptRegion SourceDetails =
17-
new ScriptRegion(
18-
file: TestUtilities.NormalizePath("Completion/CompletionExamples.psm1"),
19-
text: string.Empty,
20-
startLineNumber: 13,
21-
startColumnNumber: 8,
22-
startOffset: 0,
23-
endLineNumber: 0,
24-
endColumnNumber: 0,
25-
endOffset: 0);
15+
public static readonly ScriptRegion SourceDetails = new(
16+
file: TestUtilities.NormalizePath("Completion/CompletionExamples.psm1"),
17+
text: string.Empty,
18+
startLineNumber: 13,
19+
startColumnNumber: 8,
20+
startOffset: 0,
21+
endLineNumber: 0,
22+
endColumnNumber: 0,
23+
endOffset: 0);
2624

27-
public static readonly CompletionDetails ExpectedCompletion =
28-
CompletionDetails.Create(
29-
"Get-Random",
30-
CompletionType.Command,
31-
string.Join(Environment.NewLine + Environment.NewLine, s_getRandomParamSets),
32-
listItemText: "Get-Random"
33-
);
25+
public static readonly CompletionItem ExpectedCompletion = new()
26+
{
27+
Kind = CompletionItemKind.Function,
28+
Detail = "", // OS-dependent, checked separately.
29+
InsertTextFormat = InsertTextFormat.PlainText,
30+
InsertText = "Get-Random",
31+
FilterText = "Get-Random",
32+
Label = "Get-Random",
33+
SortText = "0001Get-Random",
34+
TextEdit = new TextEdit
35+
{
36+
NewText = "Get-Random",
37+
Range = new Range
38+
{
39+
Start = new Position { Line = 12, Character = 0 },
40+
End = new Position { Line = 12, Character = 8 }
41+
}
42+
}
43+
};
3444
}
3545
}

test/PowerShellEditorServices.Test.Shared/Completion/CompleteCommandInFile.cs

+30-16
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,40 @@
22
// Licensed under the MIT License.
33

44
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
5+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
56

67
namespace Microsoft.PowerShell.EditorServices.Test.Shared.Completion
78
{
8-
internal class CompleteCommandInFile
9+
internal static class CompleteCommandInFile
910
{
10-
public static readonly ScriptRegion SourceDetails =
11-
new ScriptRegion(
12-
file: TestUtilities.NormalizePath("Completion/CompletionExamples.psm1"),
13-
text: string.Empty,
14-
startLineNumber: 8,
15-
startColumnNumber: 7,
16-
startOffset: 0,
17-
endLineNumber: 0,
18-
endColumnNumber: 0,
19-
endOffset: 0);
11+
public static readonly ScriptRegion SourceDetails = new(
12+
file: TestUtilities.NormalizePath("Completion/CompletionExamples.psm1"),
13+
text: string.Empty,
14+
startLineNumber: 8,
15+
startColumnNumber: 7,
16+
startOffset: 0,
17+
endLineNumber: 0,
18+
endColumnNumber: 0,
19+
endOffset: 0);
2020

21-
public static readonly CompletionDetails ExpectedCompletion =
22-
CompletionDetails.Create(
23-
"Get-Something",
24-
CompletionType.Command,
25-
"Get-Something");
21+
public static readonly CompletionItem ExpectedCompletion = new()
22+
{
23+
Kind = CompletionItemKind.Function,
24+
Detail = "",
25+
InsertTextFormat = InsertTextFormat.PlainText,
26+
InsertText = "Get-Something",
27+
FilterText = "Get-Something",
28+
Label = "Get-Something",
29+
SortText = "0001Get-Something",
30+
TextEdit = new TextEdit
31+
{
32+
NewText = "Get-Something",
33+
Range = new Range
34+
{
35+
Start = new Position { Line = 7, Character = 0 },
36+
End = new Position { Line = 7, Character = 6 }
37+
}
38+
}
39+
};
2640
}
2741
}

test/PowerShellEditorServices.Test.Shared/Completion/CompleteFilePath.cs

+20-16
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,30 @@
22
// Licensed under the MIT License.
33

44
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
5+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
56

67
namespace Microsoft.PowerShell.EditorServices.Test.Shared.Completion
78
{
8-
internal class CompleteFilePath
9+
internal static class CompleteFilePath
910
{
10-
public static readonly ScriptRegion SourceDetails =
11-
new ScriptRegion(
12-
file: TestUtilities.NormalizePath("Completion/CompletionExamples.psm1"),
13-
text: string.Empty,
14-
startLineNumber: 19,
15-
startColumnNumber: 15,
16-
startOffset: 0,
17-
endLineNumber: 0,
18-
endColumnNumber: 0,
19-
endOffset: 0);
11+
public static readonly ScriptRegion SourceDetails = new(
12+
file: TestUtilities.NormalizePath("Completion/CompletionExamples.psm1"),
13+
text: string.Empty,
14+
startLineNumber: 19,
15+
startColumnNumber: 15,
16+
startOffset: 0,
17+
endLineNumber: 0,
18+
endColumnNumber: 0,
19+
endOffset: 0);
2020

21-
public static readonly BufferRange ExpectedRange =
22-
new BufferRange(
23-
new BufferPosition(19, 15),
24-
new BufferPosition(19, 25));
21+
public static readonly TextEdit ExpectedEdit = new()
22+
{
23+
NewText = "",
24+
Range = new Range
25+
{
26+
Start = new Position { Line = 18, Character = 14 },
27+
End = new Position { Line = 18, Character = 14 }
28+
}
29+
};
2530
}
2631
}
27-

test/PowerShellEditorServices.Test.Shared/Completion/CompleteNamespace.cs

+30-17
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,40 @@
22
// Licensed under the MIT License.
33

44
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
5+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
56

67
namespace Microsoft.PowerShell.EditorServices.Test.Shared.Completion
78
{
8-
internal class CompleteNamespace
9+
internal static class CompleteNamespace
910
{
10-
public static readonly ScriptRegion SourceDetails =
11-
new ScriptRegion(
12-
file: TestUtilities.NormalizePath("Completion/CompletionExamples.psm1"),
13-
text: string.Empty,
14-
startLineNumber: 22,
15-
startColumnNumber: 15,
16-
startOffset: 0,
17-
endLineNumber: 0,
18-
endColumnNumber: 0,
19-
endOffset: 0);
11+
public static readonly ScriptRegion SourceDetails = new(
12+
file: TestUtilities.NormalizePath("Completion/CompletionExamples.psm1"),
13+
text: string.Empty,
14+
startLineNumber: 22,
15+
startColumnNumber: 15,
16+
startOffset: 0,
17+
endLineNumber: 0,
18+
endColumnNumber: 0,
19+
endOffset: 0);
2020

21-
public static readonly CompletionDetails ExpectedCompletion =
22-
CompletionDetails.Create(
23-
"System.Collections",
24-
CompletionType.Namespace,
25-
"System.Collections"
26-
);
21+
public static readonly CompletionItem ExpectedCompletion = new()
22+
{
23+
Kind = CompletionItemKind.Module,
24+
Detail = "Namespace System.Collections",
25+
InsertTextFormat = InsertTextFormat.PlainText,
26+
InsertText = "System.Collections",
27+
FilterText = "System.Collections",
28+
Label = "Collections",
29+
SortText = "0001Collections",
30+
TextEdit = new TextEdit
31+
{
32+
NewText = "System.Collections",
33+
Range = new Range
34+
{
35+
Start = new Position { Line = 21, Character = 1 },
36+
End = new Position { Line = 21, Character = 15 }
37+
}
38+
}
39+
};
2740
}
2841
}

test/PowerShellEditorServices.Test.Shared/Completion/CompleteTypeName.cs

+30-17
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,40 @@
22
// Licensed under the MIT License.
33

44
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
5+
using OmniSharp.Extensions.LanguageServer.Protocol.Models;
56

67
namespace Microsoft.PowerShell.EditorServices.Test.Shared.Completion
78
{
8-
internal class CompleteTypeName
9+
internal static class CompleteTypeName
910
{
10-
public static readonly ScriptRegion SourceDetails =
11-
new ScriptRegion(
12-
file: TestUtilities.NormalizePath("Completion/CompletionExamples.psm1"),
13-
text: string.Empty,
14-
startLineNumber: 21,
15-
startColumnNumber: 25,
16-
startOffset: 0,
17-
endLineNumber: 0,
18-
endColumnNumber: 0,
19-
endOffset: 0);
11+
public static readonly ScriptRegion SourceDetails = new(
12+
file: TestUtilities.NormalizePath("Completion/CompletionExamples.psm1"),
13+
text: string.Empty,
14+
startLineNumber: 21,
15+
startColumnNumber: 25,
16+
startOffset: 0,
17+
endLineNumber: 0,
18+
endColumnNumber: 0,
19+
endOffset: 0);
2020

21-
public static readonly CompletionDetails ExpectedCompletion =
22-
CompletionDetails.Create(
23-
"System.Collections.ArrayList",
24-
CompletionType.Type,
25-
"System.Collections.ArrayList"
26-
);
21+
public static readonly CompletionItem ExpectedCompletion = new()
22+
{
23+
Kind = CompletionItemKind.TypeParameter,
24+
Detail = "System.Collections.ArrayList",
25+
InsertTextFormat = InsertTextFormat.PlainText,
26+
InsertText = "System.Collections.ArrayList",
27+
FilterText = "System.Collections.ArrayList",
28+
Label = "ArrayList",
29+
SortText = "0001ArrayList",
30+
TextEdit = new TextEdit
31+
{
32+
NewText = "System.Collections.ArrayList",
33+
Range = new Range
34+
{
35+
Start = new Position { Line = 20, Character = 1 },
36+
End = new Position { Line = 20, Character = 29 }
37+
}
38+
}
39+
};
2740
}
2841
}

0 commit comments

Comments
 (0)