Skip to content

Commit b8ad2c7

Browse files
Type completion with tooltips (#1352)
* Should improve type completion * New Class for type name completion test * New test for type name completion * type name completion example * semicolons and barce mismatches * Case sensitivity * methods are case sensitive, too! * dots count! * better test example * added more characters. Test still not passing * Tyler's suggestions for the test criteria (it works for him) * the whole type name * Completing Namespace completions * make 25 15 for namespace * try this with the namespace test * rev line number * Don't use GetTypeInfo() * skip on windows powershell * add skippable fact * add versionutils Co-authored-by: JB Lewis <[email protected]>
1 parent 1142918 commit b8ad2c7

File tree

7 files changed

+137
-13
lines changed

7 files changed

+137
-13
lines changed

src/PowerShellEditorServices/Services/Symbols/Vistors/AstOperations.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ internal static class AstOperations
2525
{
2626
// TODO: When netstandard is upgraded to 2.0, see if
2727
// Delegate.CreateDelegate can be used here instead
28-
private static readonly MethodInfo s_extentCloneWithNewOffset = typeof(PSObject).GetTypeInfo().Assembly
28+
private static readonly MethodInfo s_extentCloneWithNewOffset = typeof(PSObject).Assembly
2929
.GetType("System.Management.Automation.Language.InternalScriptPosition")
3030
.GetMethod("CloneWithNewOffset", BindingFlags.Instance | BindingFlags.NonPublic);
3131

src/PowerShellEditorServices/Services/TextDocument/Handlers/CompletionHandler.cs

+2
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ private static CompletionItem CreateCompletionItem(
251251

252252
switch (completionDetails.CompletionType)
253253
{
254+
case CompletionType.Type:
255+
case CompletionType.Namespace:
254256
case CompletionType.ParameterValue:
255257
case CompletionType.Method:
256258
case CompletionType.Property:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
7+
8+
namespace Microsoft.PowerShell.EditorServices.Test.Shared.Completion
9+
{
10+
internal class CompleteNamespace
11+
{
12+
public static readonly ScriptRegion SourceDetails =
13+
new ScriptRegion(
14+
file: TestUtilities.NormalizePath("Completion/CompletionExamples.psm1"),
15+
text: string.Empty,
16+
startLineNumber: 22,
17+
startColumnNumber: 15,
18+
startOffset: 0,
19+
endLineNumber: 0,
20+
endColumnNumber: 0,
21+
endOffset: 0);
22+
23+
public static readonly CompletionDetails ExpectedCompletion =
24+
CompletionDetails.Create(
25+
"System.Collections",
26+
CompletionType.Namespace,
27+
"System.Collections"
28+
);
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Copyright (c) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
4+
//
5+
6+
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
7+
8+
namespace Microsoft.PowerShell.EditorServices.Test.Shared.Completion
9+
{
10+
internal class CompleteTypeName
11+
{
12+
public static readonly ScriptRegion SourceDetails =
13+
new ScriptRegion(
14+
file: TestUtilities.NormalizePath("Completion/CompletionExamples.psm1"),
15+
text: string.Empty,
16+
startLineNumber: 21,
17+
startColumnNumber: 25,
18+
startOffset: 0,
19+
endLineNumber: 0,
20+
endColumnNumber: 0,
21+
endOffset: 0);
22+
23+
public static readonly CompletionDetails ExpectedCompletion =
24+
CompletionDetails.Create(
25+
"System.Collections.ArrayList",
26+
CompletionType.Type,
27+
"System.Collections.ArrayList"
28+
);
29+
}
30+
}

test/PowerShellEditorServices.Test.Shared/Completion/CompletionExamples.psm1

+3
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ function Test-Completion {
1717
}
1818

1919
Get-ChildItem /
20+
21+
[System.Collections.ArrayList].GetType()
22+
[System.Collect

test/PowerShellEditorServices.Test/Language/LanguageServiceTests.cs

+69-12
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,28 @@
33
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
44
//
55

6+
using System;
7+
using System.Collections.Generic;
8+
using System.IO;
9+
using System.Linq;
10+
using System.Runtime.InteropServices;
11+
using System.Threading.Tasks;
12+
using Microsoft.Extensions.Logging.Abstractions;
13+
using Microsoft.PowerShell.EditorServices.Handlers;
14+
using Microsoft.PowerShell.EditorServices.Services;
15+
using Microsoft.PowerShell.EditorServices.Services.Symbols;
16+
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
17+
using Microsoft.PowerShell.EditorServices.Test.Shared;
618
using Microsoft.PowerShell.EditorServices.Test.Shared.Completion;
719
using Microsoft.PowerShell.EditorServices.Test.Shared.Definition;
820
using Microsoft.PowerShell.EditorServices.Test.Shared.Occurrences;
921
using Microsoft.PowerShell.EditorServices.Test.Shared.ParameterHint;
1022
using Microsoft.PowerShell.EditorServices.Test.Shared.References;
1123
using Microsoft.PowerShell.EditorServices.Test.Shared.SymbolDetails;
1224
using Microsoft.PowerShell.EditorServices.Test.Shared.Symbols;
13-
using System;
14-
using System.IO;
15-
using System.Linq;
16-
using System.Threading.Tasks;
25+
using Microsoft.PowerShell.EditorServices.Utility;
1726
using Xunit;
18-
using Microsoft.PowerShell.EditorServices.Services;
19-
using Microsoft.Extensions.Logging.Abstractions;
20-
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
21-
using Microsoft.PowerShell.EditorServices.Services.Symbols;
22-
using System.Collections.Generic;
23-
using Microsoft.PowerShell.EditorServices.Handlers;
24-
using System.Runtime.InteropServices;
27+
using Xunit.Abstractions;
2528

2629
namespace Microsoft.PowerShell.EditorServices.Test.Language
2730
{
@@ -33,7 +36,7 @@ public class LanguageServiceTests : IDisposable
3336
private readonly PowerShellContextService powerShellContext;
3437
private static readonly string s_baseSharedScriptPath =
3538
Path.Combine(
36-
Path.GetDirectoryName(RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
39+
Path.GetDirectoryName(VersionUtils.IsWindows
3740
// On non-Windows platforms, CodeBase has file:// in it.
3841
// On Windows, Location points to a temp directory.
3942
? typeof(LanguageServiceTests).Assembly.CodeBase
@@ -92,6 +95,60 @@ await this.GetCompletionResults(
9295
Assert.NotNull(completionResults.Completions[0].ToolTipText);
9396
}
9497

98+
[Trait("Category", "Completions")]
99+
[SkippableFact]
100+
public async Task LanguageServiceCompletesTypeName()
101+
{
102+
Skip.If(
103+
!VersionUtils.IsNetCore,
104+
"Windows PowerShell return no results from CommandCompletion in the test harness. Since it works in PS7 and works manually when I run the extension, I'm skipping this test");
105+
106+
CompletionResults completionResults =
107+
await this.GetCompletionResults(
108+
CompleteTypeName.SourceDetails);
109+
110+
Assert.NotEmpty(completionResults.Completions);
111+
112+
Assert.Equal(
113+
CompleteTypeName.ExpectedCompletion.CompletionText,
114+
completionResults.Completions[0].CompletionText
115+
);
116+
117+
Assert.Equal(
118+
CompleteTypeName.ExpectedCompletion.CompletionType,
119+
completionResults.Completions[0].CompletionType
120+
);
121+
122+
Assert.NotNull(completionResults.Completions[0].ToolTipText);
123+
}
124+
125+
[Trait("Category", "Completions")]
126+
[SkippableFact]
127+
public async Task LanguageServiceCompletesNamespace()
128+
{
129+
Skip.If(
130+
!VersionUtils.IsNetCore,
131+
"Windows PowerShell return no results from CommandCompletion in the test harness. Since it works in PS7 and works manually when I run the extension, I'm skipping this test");
132+
133+
CompletionResults completionResults =
134+
await this.GetCompletionResults(
135+
CompleteNamespace.SourceDetails);
136+
137+
Assert.NotEmpty(completionResults.Completions);
138+
139+
Assert.Equal(
140+
CompleteNamespace.ExpectedCompletion.CompletionText,
141+
completionResults.Completions[0].CompletionText
142+
);
143+
144+
Assert.Equal(
145+
CompleteNamespace.ExpectedCompletion.CompletionType,
146+
completionResults.Completions[0].CompletionType
147+
);
148+
149+
Assert.NotNull(completionResults.Completions[0].ToolTipText);
150+
}
151+
95152
[Trait("Category", "Completions")]
96153
[Fact]
97154
public async Task LanguageServiceCompletesVariableInFile()

test/PowerShellEditorServices.Test/PowerShellEditorServices.Test.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
<PropertyGroup>
44
<TargetFrameworks>net5.0;netcoreapp3.1;net461</TargetFrameworks>
55
<AssemblyName>Microsoft.PowerShell.EditorServices.Test</AssemblyName>
6+
<TargetPlatform>x64</TargetPlatform>
67
</PropertyGroup>
78
<PropertyGroup>
89
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
@@ -28,6 +29,7 @@
2829
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
2930
<PackageReference Include="xunit" Version="2.4.1-pre.build.4059" />
3031
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
32+
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
3133
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.17.4" />
3234
<DotNetCliToolReference Include="dotnet-xunit" Version="2.4.0-beta.1.build3958" />
3335
</ItemGroup>

0 commit comments

Comments
 (0)