Skip to content

Commit

Permalink
Semantic search
Browse files Browse the repository at this point in the history
  • Loading branch information
tmat committed Mar 15, 2024
1 parent 93fb581 commit 7470447
Show file tree
Hide file tree
Showing 140 changed files with 4,562 additions and 84 deletions.
24 changes: 24 additions & 0 deletions Roslyn.sln
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Feat
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Features.Test.Utilities", "src\Features\TestUtilities\Microsoft.CodeAnalysis.Features.Test.Utilities.csproj", "{5762E483-75CE-4328-A410-511F30737712}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SemanticSearch", "SemanticSearch", "{52ABB0E4-C3A1-4897-B51B-18EDA83F5D20}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SemanticSearch.BuildTask", "src\Tools\SemanticSearch\BuildTask\SemanticSearch.BuildTask.csproj", "{FCE88BBD-9BBD-4871-B9B0-DE176D73A6B0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SemanticSearch.ReferenceAssemblies", "src\Tools\SemanticSearch\ReferenceAssemblies\SemanticSearch.ReferenceAssemblies.csproj", "{EDEF898A-CEFA-4151-8168-D0231A602093}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SemanticSearch.BuildTask.UnitTests", "src\Tools\SemanticSearch\Tests\SemanticSearch.BuildTask.UnitTests.csproj", "{D817E3CE-F603-499B-B02A-7DECD017B170}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -1346,6 +1354,18 @@ Global
{5762E483-75CE-4328-A410-511F30737712}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5762E483-75CE-4328-A410-511F30737712}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5762E483-75CE-4328-A410-511F30737712}.Release|Any CPU.Build.0 = Release|Any CPU
{FCE88BBD-9BBD-4871-B9B0-DE176D73A6B0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FCE88BBD-9BBD-4871-B9B0-DE176D73A6B0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FCE88BBD-9BBD-4871-B9B0-DE176D73A6B0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FCE88BBD-9BBD-4871-B9B0-DE176D73A6B0}.Release|Any CPU.Build.0 = Release|Any CPU
{EDEF898A-CEFA-4151-8168-D0231A602093}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EDEF898A-CEFA-4151-8168-D0231A602093}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EDEF898A-CEFA-4151-8168-D0231A602093}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EDEF898A-CEFA-4151-8168-D0231A602093}.Release|Any CPU.Build.0 = Release|Any CPU
{D817E3CE-F603-499B-B02A-7DECD017B170}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D817E3CE-F603-499B-B02A-7DECD017B170}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D817E3CE-F603-499B-B02A-7DECD017B170}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D817E3CE-F603-499B-B02A-7DECD017B170}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1595,6 +1615,10 @@ Global
{4D9D7A28-BB44-4F3F-81DA-14F39B853718} = {CC126D03-7EAC-493F-B187-DCDEE1EF6A70}
{5BABC440-4F1B-46E8-9068-DD7F02ED25D3} = {3E5FE3DB-45F7-4D83-9097-8F05D3B3AEC6}
{5762E483-75CE-4328-A410-511F30737712} = {3E5FE3DB-45F7-4D83-9097-8F05D3B3AEC6}
{52ABB0E4-C3A1-4897-B51B-18EDA83F5D20} = {FD0FAF5F-1DED-485C-99FA-84B97F3A8EEC}
{FCE88BBD-9BBD-4871-B9B0-DE176D73A6B0} = {52ABB0E4-C3A1-4897-B51B-18EDA83F5D20}
{EDEF898A-CEFA-4151-8168-D0231A602093} = {52ABB0E4-C3A1-4897-B51B-18EDA83F5D20}
{D817E3CE-F603-499B-B02A-7DECD017B170} = {52ABB0E4-C3A1-4897-B51B-18EDA83F5D20}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {604E6B91-7BC0-4126-AE07-D4D2FEFC3D29}
Expand Down
1 change: 1 addition & 0 deletions eng/targets/Services.props
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<ServiceHubService Include="Microsoft.VisualStudio.LanguageServices.StackTraceExplorer" ClassName="Microsoft.CodeAnalysis.Remote.RemoteStackTraceExplorerService+Factory" />
<ServiceHubService Include="Microsoft.VisualStudio.LanguageServices.UnitTestingSearch" ClassName="Microsoft.CodeAnalysis.Remote.RemoteUnitTestingSearchService+Factory" />
<ServiceHubService Include="Microsoft.VisualStudio.LanguageServices.SourceGeneration" ClassName="Microsoft.CodeAnalysis.Remote.RemoteSourceGenerationService+Factory" />
<ServiceHubService Include="Microsoft.VisualStudio.LanguageServices.SemanticSearch" ClassName="Microsoft.CodeAnalysis.Remote.RemoteSemanticSearchService+Factory" />
</ItemGroup>

<!--
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
<InternalsVisibleTo Include="CompilerBenchmarks" />
<InternalsVisibleTo Include="Microsoft.Build.Tasks.CodeAnalysis.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Features.Test.Utilities" />
<InternalsVisibleTo Include="SemanticSearch.BuildTask.UnitTests" />
</ItemGroup>
<Import Project="..\CSharpAnalyzerDriver\CSharpAnalyzerDriver.projitems" Label="Shared" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,30 @@ namespace Microsoft.CodeAnalysis.UnitTests.Collections
{
public class ArrayBuilderTests
{
[Fact]
public void RemoveAll()
{
var builder = new ArrayBuilder<int> { 6, 5, 1, 2, 3, 2, 4, 5, 1, 7 };

builder.RemoveAll((_, _) => false, arg: 0);
AssertEx.Equal([6, 5, 1, 2, 3, 2, 4, 5, 1, 7], builder);

builder.RemoveAll((i, arg) => i == arg, arg: 6);
AssertEx.Equal([5, 1, 2, 3, 2, 4, 5, 1, 7], builder);

builder.RemoveAll((i, arg) => i == arg, arg: 7);
AssertEx.Equal([5, 1, 2, 3, 2, 4, 5, 1], builder);

builder.RemoveAll((i, arg) => i < arg, arg: 3);
AssertEx.Equal([5, 3, 4, 5], builder);

builder.RemoveAll((_, _) => true, arg: 0);
AssertEx.Equal([], builder);

builder.RemoveAll((_, _) => true, arg: 0);
AssertEx.Equal([], builder);
}

[Fact]
public void RemoveDuplicates1()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
<InternalsVisibleTo Include="Roslyn.Test.PdbUtilities" />
<InternalsVisibleTo Include="Roslyn.VisualStudio.Next.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.LanguageServer.Protocol.UnitTests" />
<InternalsVisibleTo Include="SemanticSearch.BuildTask.UnitTests"/>
</ItemGroup>
<ItemGroup>
<!-- TODO: Remove the below IVTs to CodeStyle Unit test projects once all analyzer/code fix tests are switched to Microsoft.CodeAnalysis.Testing -->
Expand Down
24 changes: 24 additions & 0 deletions src/Dependencies/PooledObjects/ArrayBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,30 @@ public void RemoveLast()
_builder.RemoveAt(_builder.Count - 1);
}

public void RemoveAll(Predicate<T> match)
{
_builder.RemoveAll(match);
}

public void RemoveAll<TArg>(Func<T, TArg, bool> match, TArg arg)
{
var i = 0;
for (var j = 0; j < _builder.Count; j++)
{
if (!match(_builder[j], arg))
{
if (i != j)
{
_builder[i] = _builder[j];
}

i++;
}
}

Clip(i);
}

public void ReverseContents()
{
_builder.Reverse();
Expand Down
16 changes: 16 additions & 0 deletions src/EditorFeatures/CSharp/SemanticSearch/SemanticSearchT.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// 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.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.CodeAnalysis.Editor.CSharp.SemanticSearch
{
internal class SemanticSearchT
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Text;

namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem;
namespace Microsoft.CodeAnalysis.Editor;

internal static class TextEditApplication
{
Expand All @@ -31,7 +31,7 @@ public static void UpdateText(ImmutableArray<TextChange> textChanges, ITextBuffe
private static void UpdateText(ImmutableArray<TextChange> textChanges, ITextBuffer buffer, ITextSnapshot oldSnapshot, SourceText oldText, EditOptions options)
{
using var edit = buffer.CreateEdit(options, reiteratedVersionNumber: null, editTag: null);
if (CodeAnalysis.Workspace.TryGetWorkspace(oldText.Container, out var workspace))
if (Workspace.TryGetWorkspace(oldText.Container, out var workspace))
{
var undoService = workspace.Services.GetRequiredService<ISourceTextUndoService>();
undoService.BeginUndoTransaction(oldSnapshot);
Expand Down
3 changes: 3 additions & 0 deletions src/EditorFeatures/Core/EditorFeaturesResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,9 @@ Do you want to proceed?</value>
<data name="Cancel" xml:space="preserve">
<value>Cancel</value>
</data>
<data name="Run" xml:space="preserve">
<value>Run</value>
</data>
<data name="Changes" xml:space="preserve">
<value>Changes</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// 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;
using Microsoft.CodeAnalysis.Editor;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.TestHooks;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Text;
using Roslyn.Utilities;

namespace Microsoft.CodeAnalysis.SemanticSearch;

internal sealed class SemanticSearchEditorWorkspace(
HostServices services,
SemanticSearchProjectConfiguration config,
IThreadingContext threadingContext,
IAsynchronousOperationListenerProvider listenerProvider)
: SemanticSearchWorkspace(services, config)
{
private readonly IAsynchronousOperationListener _asyncListener = listenerProvider.GetListener(FeatureAttribute.SemanticSearch);

private ITextBuffer? _queryTextBuffer;
private DocumentId? _queryDocumentId;

public async Task OpenQueryDocumentAsync(ITextBuffer buffer, CancellationToken cancellationToken)
{
_queryTextBuffer = buffer;

// initialize solution with default query, unless it has already been initialized:
var queryDocument = await UpdateQueryDocumentAsync(query: null, cancellationToken).ConfigureAwait(false);

_queryDocumentId = queryDocument.Id;

OnDocumentOpened(queryDocument.Id, buffer.AsTextContainer());
}

/// <summary>
/// Used by code actions through <see cref="Workspace.TryApplyChanges(Solution)"/>.
/// </summary>
protected override void ApplyDocumentTextChanged(DocumentId documentId, SourceText newText)
{
if (documentId == _queryDocumentId)
{
ApplyQueryDocumentTextChanged(newText);
}
}

protected override void ApplyQueryDocumentTextChanged(SourceText newText)
{
Contract.ThrowIfNull(_queryTextBuffer);

// update the buffer on UI thread:

var completionToken = _asyncListener.BeginAsyncOperation(nameof(SemanticSearchEditorWorkspace) + "." + nameof(ApplyQueryDocumentTextChanged));
_ = UpdateTextAsync().ReportNonFatalErrorAsync().CompletesAsyncOperation(completionToken);

async Task UpdateTextAsync()
{
await threadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(CancellationToken.None);
TextEditApplication.UpdateText(newText, _queryTextBuffer, EditOptions.DefaultMinimalChange);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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 Microsoft.CodeAnalysis.Editor.Shared;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.VisualStudio.Text;

namespace Microsoft.CodeAnalysis.SemanticSearch;

[ExportWorkspaceService(typeof(ITextBufferSupportsFeatureService), WorkspaceKind.SemanticSearch), Shared]
[method: ImportingConstructor]
[method: Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
internal class SemanticSeatchTextBufferSupportsFeatureService() : ITextBufferSupportsFeatureService
{
public bool SupportsCodeFixes(ITextBuffer textBuffer)
=> true;

public bool SupportsRefactorings(ITextBuffer textBuffer)
=> true;

public bool SupportsRename(ITextBuffer textBuffer)
=> true;

public bool SupportsNavigationToAnyPosition(ITextBuffer textBuffer)
=> true;
}
5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/EditorFeatures/Core/xlf/EditorFeaturesResources.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7470447

Please sign in to comment.