Skip to content

Commit

Permalink
Merge main to main-vs-deps (#54452)
Browse files Browse the repository at this point in the history
  • Loading branch information
RikkiGibson authored Jun 29, 2021
2 parents 4794e1f + 446caeb commit 3aecf23
Show file tree
Hide file tree
Showing 29 changed files with 317 additions and 46 deletions.
3 changes: 2 additions & 1 deletion azure-pipelines-official.yml
Original file line number Diff line number Diff line change
Expand Up @@ -337,14 +337,15 @@ stages:
Write-Host "##vso[task.setvariable variable=Insertion.InsertToolset]$($branchData.insertToolset)"
}
Write-Host "##vso[task.setvariable variable=Insertion.AutoComplete]$(-not $branchData.insertionCreateDraftPR)"
Write-Host "##vso[task.setvariable variable=ComponentBranchName]$branchName"
Write-Host "##vso[task.setvariable variable=VSBranchName]$($branchData.vsBranch)"
displayName: Set Insertion Variables
- powershell: |
mv RoslynTools.VisualStudioInsertionTool.* RIT
.\RIT\tools\OneOffInsertion.ps1 `
-autoComplete "false" `
-autoComplete "$(Insertion.AutoComplete)" `
-buildQueueName "$(Build.DefinitionName)" `
-cherryPick "(default)" `
-clientId "$(ClientId)" `
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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.Collections.Immutable;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Utilities;

namespace Microsoft.CodeAnalysis.ExternalAccess.IntelliCode.Api
{
/// <summary>
/// Provides a list of possible default arguments for method calls.
/// </summary>
/// <remarks>
/// This is a MEF component and should be exported with <see cref="ContentTypeAttribute"/> and <see cref="NameAttribute"/> attributes
/// and optional <see cref="OrderAttribute"/> and <see cref="TextViewRoleAttribute"/> attributes.
/// An instance of <see cref="IIntelliCodeArgumentDefaultsSource"/> is selected
/// first by matching ContentType with content type of the <see cref="ITextView.TextBuffer"/>, and then by order.
/// Only one <see cref="IIntelliCodeArgumentDefaultsSource"/> is used in a given view.
/// <para>
/// Only one <see cref="IIntelliCodeArgumentDefaultsSource"/> will used for any given <see cref="ITextView"/>. The sources are
/// ordered by the Order attribute. The first source (if any) that satisfies the ContentType and TextViewRoles
/// attributes will be the source used to provide defaults.
/// </para>
/// <example>
/// <code>
/// [Export(typeof(IIntelliCodeArgumentDefaultsSource))]
/// [Name(nameof(IntelliCodeArgumentDefaultsSource))]
/// [ContentType("text")]
/// [TextViewRoles(PredefinedTextViewRoles.Editable)]
/// [Order(Before = "OtherCompletionDefaultsSource")]
/// public class IntelliCodeArgumentDefaultsSource : IIntelliCodeArgumentDefaultsSource
/// </code>
/// </example>
/// </remarks>
internal interface IIntelliCodeArgumentDefaultsSource
{
/// <summary>
/// Gets a list of possible default arguments for a method signature.
/// </summary>
/// <param name="view">View for which the defaults are desired.</param>
/// <returns>A list of possible default arguments for a method signature.</returns>
/// <remarks>
/// <para>The returned value will always be in the form of a "complete" set of arguments, including the leading and trailing parenthesis.</para>
/// <para>For example:
/// <code>
/// ()
/// (args[0])
/// (args.Length)
/// (value: args.Length)
/// </code>
/// </para>
/// <para>Some of the proposals may be syntactically/semantically invalid (and can be ignored by the caller).</para>
/// </remarks>
Task<ImmutableArray<string>> GetArgumentDefaultsAsync(ITextView view);
}
}
4 changes: 2 additions & 2 deletions src/EditorFeatures/Core/Shared/Options/FeatureOnOffOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ internal static class FeatureOnOffOptions
nameof(FeatureOnOffOptions), nameof(OfferRemoveUnusedReferences), defaultValue: true,
storageLocations: new RoamingProfileStorageLocation($"TextEditor.{nameof(OfferRemoveUnusedReferences)}"));

public static readonly PerLanguageOption2<bool> ShowInheritanceMargin =
public static readonly PerLanguageOption2<bool?> ShowInheritanceMargin =
new(nameof(FeatureOnOffOptions),
nameof(ShowInheritanceMargin),
defaultValue: false,
defaultValue: null,
new RoamingProfileStorageLocation("TextEditor.%LANGUAGE%.Specific.ShowInheritanceMargin"));

public static readonly Option2<bool> AutomaticallyCompleteStatementOnSemicolon = new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,52 @@ public ImmutableArray<StateSet> CreateBuildOnlyProjectStateSet(Project project)
return stateSets.ToImmutable();
}

/// <summary>
/// Determines if any of the state sets in <see cref="GetAllHostStateSets()"/> match a specified predicate.
/// </summary>
/// <remarks>
/// This method avoids the performance overhead of calling <see cref="GetAllHostStateSets()"/> for the
/// specific case where the result is only used for testing if any element meets certain conditions.
/// </remarks>
public bool HasAnyHostStateSet<TArg>(Func<StateSet, TArg, bool> match, TArg arg)
{
foreach (var (_, hostStateSet) in _hostAnalyzerStateMap)
{
foreach (var stateSet in hostStateSet.OrderedStateSets)
{
if (match(stateSet, arg))
return true;
}
}

return false;
}

/// <summary>
/// Determines if any of the state sets in <see cref="_projectAnalyzerStateMap"/> for a specific project
/// match a specified predicate.
/// </summary>
/// <remarks>
/// <para>This method avoids the performance overhead of calling <see cref="GetStateSets(Project)"/> for the
/// specific case where the result is only used for testing if any element meets certain conditions.</para>
///
/// <para>Note that host state sets (i.e. ones retured by <see cref="GetAllHostStateSets()"/> are not tested
/// by this method.</para>
/// </remarks>
public bool HasAnyProjectStateSet<TArg>(ProjectId projectId, Func<StateSet, TArg, bool> match, TArg arg)
{
if (_projectAnalyzerStateMap.TryGetValue(projectId, out var entry))
{
foreach (var (_, stateSet) in entry.StateSetMap)
{
if (match(stateSet, arg))
return true;
}
}

return false;
}

public bool OnProjectRemoved(IEnumerable<StateSet> stateSets, ProjectId projectId)
{
var removed = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeStyle;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.PooledObjects;
Expand Down Expand Up @@ -64,17 +63,11 @@ public DiagnosticIncrementalAnalyzer(

internal DiagnosticAnalyzerInfoCache DiagnosticAnalyzerInfoCache => _diagnosticAnalyzerRunner.AnalyzerInfoCache;

[PerformanceSensitive("https://github.com/dotnet/roslyn/issues/54400", Constraint = "Avoid calling GetAllHostStateSets on this hot path.")]
public bool ContainsDiagnostics(ProjectId projectId)
{
foreach (var stateSet in _stateManager.GetStateSets(projectId))
{
if (stateSet.ContainsAnyDocumentOrProjectDiagnostics(projectId))
{
return true;
}
}

return false;
return _stateManager.HasAnyHostStateSet(static (stateSet, arg) => stateSet.ContainsAnyDocumentOrProjectDiagnostics(arg), projectId)
|| _stateManager.HasAnyProjectStateSet(projectId, static (stateSet, arg) => stateSet.ContainsAnyDocumentOrProjectDiagnostics(arg), projectId);
}

public bool NeedsReanalysisOnOptionChanged(object sender, OptionChangedEventArgs e)
Expand Down
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 Microsoft.CodeAnalysis.Completion;
using Microsoft.CodeAnalysis.Options;

namespace Microsoft.CodeAnalysis.ExternalAccess.IntelliCode.Api
{
internal static class IntelliCodeCompletionOptions
{
public static PerLanguageOption<bool> TriggerOnTyping { get; } = (PerLanguageOption<bool>)CompletionOptions.TriggerOnTyping;

public static PerLanguageOption<bool> TriggerOnTypingLetters { get; } = (PerLanguageOption<bool>)CompletionOptions.TriggerOnTypingLetters2;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@
<InternalsVisibleTo Include="Microsoft.VisualStudio.CodeSense.ReferencesProvider" Key="$(VisualStudioKey)" WorkItem="https://github.com/dotnet/roslyn/issues/35086" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.CodeSense.TestsProvider" Key="$(VisualStudioKey)" WorkItem="https://github.com/dotnet/roslyn/issues/35086" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.Completion.Tests" Key="$(IntelliCodeCSharpKey)" WorkItem="https://github.com/dotnet/roslyn/issues/35081" />
<RestrictedInternalsVisibleTo Include="Microsoft.VisualStudio.IntelliCode" Partner="IntelliCode" Key="$(IntelliCodeKey)" />
<RestrictedInternalsVisibleTo Include="Microsoft.VisualStudio.IntelliCode.CSharp" Partner="Pythia" Key="$(IntelliCodeCSharpKey)" />
<RestrictedInternalsVisibleTo Include="Microsoft.VisualStudio.IntelliCode.CSharp.Extraction" Partner="Pythia" Key="$(IntelliCodeCSharpKey)" />
<RestrictedInternalsVisibleTo Include="dotnet-watch" Partner="Watch" Key="$(AspNetCoreKey)" />
Expand Down
27 changes: 17 additions & 10 deletions src/Features/LanguageServer/Protocol/Extensions/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,24 +88,31 @@ private static ImmutableArray<Document> FilterDocumentsByClientName(ImmutableArr
return documents.FindDocumentInProjectContext(documentIdentifier);
}

public static T FindDocumentInProjectContext<T>(this ImmutableArray<T> documents, TextDocumentIdentifier documentIdentifier) where T : TextDocument
public static Document FindDocumentInProjectContext(this ImmutableArray<Document> documents, TextDocumentIdentifier documentIdentifier)
{
if (documents.Length > 1)
{
// We have more than one document; try to find the one that matches the right context
if (documentIdentifier is VSTextDocumentIdentifier vsDocumentIdentifier)
if (documentIdentifier is VSTextDocumentIdentifier vsDocumentIdentifier && vsDocumentIdentifier.ProjectContext != null)
{
if (vsDocumentIdentifier.ProjectContext != null)
{
var projectId = ProtocolConversions.ProjectContextToProjectId(vsDocumentIdentifier.ProjectContext);
var matchingDocument = documents.FirstOrDefault(d => d.Project.Id == projectId);
var projectId = ProtocolConversions.ProjectContextToProjectId(vsDocumentIdentifier.ProjectContext);
var matchingDocument = documents.FirstOrDefault(d => d.Project.Id == projectId);

if (matchingDocument != null)
{
return matchingDocument;
}
if (matchingDocument != null)
{
return matchingDocument;
}
}
else
{
// We were not passed a project context. This can happen when the LSP powered NavBar is not enabled.
// This branch should be removed when we're using the LSP based navbar in all scenarios.

var solution = documents.First().Project.Solution;
// Lookup which of the linked documents is currently active in the workspace.
var documentIdInCurrentContext = solution.Workspace.GetDocumentIdInCurrentContext(documents.First().Id);
return solution.GetRequiredDocument(documentIdInCurrentContext);
}
}

// We either have only one document or have multiple, but none of them matched our context. In the
Expand Down
Loading

0 comments on commit 3aecf23

Please sign in to comment.