Skip to content

Type completion with tooltips #1352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Sep 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal static class AstOperations
{
// TODO: When netstandard is upgraded to 2.0, see if
// Delegate.CreateDelegate can be used here instead
private static readonly MethodInfo s_extentCloneWithNewOffset = typeof(PSObject).GetTypeInfo().Assembly
private static readonly MethodInfo s_extentCloneWithNewOffset = typeof(PSObject).Assembly
.GetType("System.Management.Automation.Language.InternalScriptPosition")
.GetMethod("CloneWithNewOffset", BindingFlags.Instance | BindingFlags.NonPublic);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ private static CompletionItem CreateCompletionItem(

switch (completionDetails.CompletionType)
{
case CompletionType.Type:
case CompletionType.Namespace:
case CompletionType.ParameterValue:
case CompletionType.Method:
case CompletionType.Property:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using Microsoft.PowerShell.EditorServices.Services.TextDocument;

namespace Microsoft.PowerShell.EditorServices.Test.Shared.Completion
{
internal class CompleteNamespace
{
public static readonly ScriptRegion SourceDetails =
new ScriptRegion(
file: TestUtilities.NormalizePath("Completion/CompletionExamples.psm1"),
text: string.Empty,
startLineNumber: 22,
startColumnNumber: 15,
startOffset: 0,
endLineNumber: 0,
endColumnNumber: 0,
endOffset: 0);

public static readonly CompletionDetails ExpectedCompletion =
CompletionDetails.Create(
"System.Collections",
CompletionType.Namespace,
"System.Collections"
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using Microsoft.PowerShell.EditorServices.Services.TextDocument;

namespace Microsoft.PowerShell.EditorServices.Test.Shared.Completion
{
internal class CompleteTypeName
{
public static readonly ScriptRegion SourceDetails =
new ScriptRegion(
file: TestUtilities.NormalizePath("Completion/CompletionExamples.psm1"),
text: string.Empty,
startLineNumber: 21,
startColumnNumber: 25,
startOffset: 0,
endLineNumber: 0,
endColumnNumber: 0,
endOffset: 0);

public static readonly CompletionDetails ExpectedCompletion =
CompletionDetails.Create(
"System.Collections.ArrayList",
CompletionType.Type,
"System.Collections.ArrayList"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ function Test-Completion {
}

Get-ChildItem /

[System.Collections.ArrayList].GetType()
[System.Collect
81 changes: 69 additions & 12 deletions test/PowerShellEditorServices.Test/Language/LanguageServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,28 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.PowerShell.EditorServices.Handlers;
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.PowerShell.EditorServices.Services.Symbols;
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
using Microsoft.PowerShell.EditorServices.Test.Shared;
using Microsoft.PowerShell.EditorServices.Test.Shared.Completion;
using Microsoft.PowerShell.EditorServices.Test.Shared.Definition;
using Microsoft.PowerShell.EditorServices.Test.Shared.Occurrences;
using Microsoft.PowerShell.EditorServices.Test.Shared.ParameterHint;
using Microsoft.PowerShell.EditorServices.Test.Shared.References;
using Microsoft.PowerShell.EditorServices.Test.Shared.SymbolDetails;
using Microsoft.PowerShell.EditorServices.Test.Shared.Symbols;
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.PowerShell.EditorServices.Utility;
using Xunit;
using Microsoft.PowerShell.EditorServices.Services;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.PowerShell.EditorServices.Services.TextDocument;
using Microsoft.PowerShell.EditorServices.Services.Symbols;
using System.Collections.Generic;
using Microsoft.PowerShell.EditorServices.Handlers;
using System.Runtime.InteropServices;
using Xunit.Abstractions;

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

[Trait("Category", "Completions")]
[SkippableFact]
public async Task LanguageServiceCompletesTypeName()
{
Skip.If(
!VersionUtils.IsNetCore,
"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");

CompletionResults completionResults =
await this.GetCompletionResults(
CompleteTypeName.SourceDetails);

Assert.NotEmpty(completionResults.Completions);

Assert.Equal(
CompleteTypeName.ExpectedCompletion.CompletionText,
completionResults.Completions[0].CompletionText
);

Assert.Equal(
CompleteTypeName.ExpectedCompletion.CompletionType,
completionResults.Completions[0].CompletionType
);

Assert.NotNull(completionResults.Completions[0].ToolTipText);
}

[Trait("Category", "Completions")]
[SkippableFact]
public async Task LanguageServiceCompletesNamespace()
{
Skip.If(
!VersionUtils.IsNetCore,
"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");

CompletionResults completionResults =
await this.GetCompletionResults(
CompleteNamespace.SourceDetails);

Assert.NotEmpty(completionResults.Completions);

Assert.Equal(
CompleteNamespace.ExpectedCompletion.CompletionText,
completionResults.Completions[0].CompletionText
);

Assert.Equal(
CompleteNamespace.ExpectedCompletion.CompletionType,
completionResults.Completions[0].CompletionType
);

Assert.NotNull(completionResults.Completions[0].ToolTipText);
}

[Trait("Category", "Completions")]
[Fact]
public async Task LanguageServiceCompletesVariableInFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<PropertyGroup>
<TargetFrameworks>net5.0;netcoreapp3.1;net461</TargetFrameworks>
<AssemblyName>Microsoft.PowerShell.EditorServices.Test</AssemblyName>
<TargetPlatform>x64</TargetPlatform>
</PropertyGroup>
<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
Expand All @@ -28,6 +29,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0" />
<PackageReference Include="xunit" Version="2.4.1-pre.build.4059" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
<PackageReference Include="OmniSharp.Extensions.LanguageServer" Version="0.17.4" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.4.0-beta.1.build3958" />
</ItemGroup>
Expand Down