-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Copilot UI prototype to Semantic Search window (#77222)
- Loading branch information
Showing
25 changed files
with
559 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/Features/Core/Portable/SemanticSearch/ISemanticSearchCopilotService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.CodeAnalysis.SemanticSearch; | ||
|
||
internal interface ISemanticSearchCopilotService | ||
{ | ||
bool IsAvailable { get; } | ||
|
||
/// <summary> | ||
/// Translates natural language <paramref name="text"/> to C# query. | ||
/// </summary> | ||
ValueTask<SemanticSearchCopilotGeneratedQuery> TryGetQueryAsync(string text, SemanticSearchCopilotContext context, CancellationToken cancellationToken); | ||
} |
35 changes: 35 additions & 0 deletions
35
src/Features/Core/Portable/SemanticSearch/SemanticSearchCopilotContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace Microsoft.CodeAnalysis.SemanticSearch; | ||
|
||
/// <summary> | ||
/// Context necessary to generate Copilot prompt for semantic search query. | ||
/// </summary> | ||
internal sealed class SemanticSearchCopilotContext | ||
{ | ||
public required string ModelName { get; init; } | ||
|
||
/// <summary> | ||
/// List of package names and versions that to include in the prompt. | ||
/// </summary> | ||
public required IEnumerable<(string name, Version version)> AvailablePackages { get; init; } | ||
} | ||
|
||
internal readonly struct SemanticSearchCopilotGeneratedQuery | ||
{ | ||
/// <summary> | ||
/// The generated code or an error message. | ||
/// </summary> | ||
public required string Text { get; init; } | ||
|
||
/// <summary> | ||
/// True if <see cref="Text"/> is an error message. | ||
/// </summary> | ||
public required bool IsError { get; init; } | ||
} | ||
|
43 changes: 43 additions & 0 deletions
43
...res/ExternalAccess/Copilot/Internal/SemanticSearch/SemanticSearchCopilotServiceWrapper.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Composition; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.CodeAnalysis.Host.Mef; | ||
using Microsoft.CodeAnalysis.ExternalAccess.Copilot.SemanticSearch; | ||
using Microsoft.CodeAnalysis.SemanticSearch; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.Copilot.Internal.SemanticSearch; | ||
|
||
[Export(typeof(ISemanticSearchCopilotService)), Shared] | ||
[method: ImportingConstructor] | ||
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)] | ||
internal sealed class SemanticSearchCopilotServiceWrapper( | ||
[Import(AllowDefault = true)] Lazy<ISemanticSearchCopilotServiceImpl>? impl) : ISemanticSearchCopilotService | ||
{ | ||
bool ISemanticSearchCopilotService.IsAvailable | ||
=> impl != null; | ||
|
||
async ValueTask<SemanticSearchCopilotGeneratedQuery> ISemanticSearchCopilotService.TryGetQueryAsync(string text, SemanticSearchCopilotContext context, CancellationToken cancellationToken) | ||
{ | ||
Contract.ThrowIfNull(impl); | ||
|
||
var result = await impl.Value.TryGetQueryAsync( | ||
text, | ||
new SemanticSearchCopilotContextImpl() | ||
{ | ||
ModelName = context.ModelName, | ||
AvailablePackages = context.AvailablePackages, | ||
}, | ||
cancellationToken).ConfigureAwait(false); | ||
|
||
return new SemanticSearchCopilotGeneratedQuery() | ||
{ | ||
IsError = result.IsError, | ||
Text = result.Text, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Features/ExternalAccess/Copilot/SemanticSearch/ISemanticSearchCopilotServiceImpl.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.CodeAnalysis.ExternalAccess.Copilot.SemanticSearch; | ||
|
||
internal interface ISemanticSearchCopilotServiceImpl | ||
{ | ||
ValueTask<SemanticSearchCopilotGeneratedQueryImpl> TryGetQueryAsync(string text, SemanticSearchCopilotContextImpl context, CancellationToken cancellationToken); | ||
} | ||
|
||
internal sealed class SemanticSearchCopilotContextImpl | ||
{ | ||
public required string ModelName { get; init; } | ||
|
||
/// <summary> | ||
/// List of package names and versions that to include in the prompt. | ||
/// </summary> | ||
public required IEnumerable<(string name, Version version)> AvailablePackages { get; init; } | ||
} | ||
|
||
internal readonly struct SemanticSearchCopilotGeneratedQueryImpl | ||
{ | ||
/// <summary> | ||
/// True if <see cref="Text"/> is an error message. | ||
/// </summary> | ||
public required bool IsError { get; init; } | ||
|
||
/// <summary> | ||
/// The generated code or an error message. | ||
/// </summary> | ||
public required string Text { get; init; } | ||
} |
19 changes: 19 additions & 0 deletions
19
src/VisualStudio/CSharp/Impl/SemanticSearch/CSharpSemanticSearchContentType.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.ComponentModel.Composition; | ||
using Microsoft.CodeAnalysis.Editor; | ||
using Microsoft.VisualStudio.Utilities; | ||
|
||
namespace Microsoft.VisualStudio.LanguageServices.CSharp; | ||
|
||
internal static class CSharpSemanticSearchContentType | ||
{ | ||
public const string Name = "SemanticSearch-CSharp"; | ||
|
||
[Export] | ||
[Name(Name)] | ||
[BaseDefinition(ContentTypeNames.CSharpContentType)] | ||
public static readonly ContentTypeDefinition Definition = null!; | ||
} |
Oops, something went wrong.