Skip to content
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

Expose WorkspaceKind off of Solution snapshot instance #62913

Merged
merged 4 commits into from
Jul 25, 2022
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 @@ -41,7 +41,7 @@ public CSharpConvertLocalFunctionToMethodCodeRefactoringProvider()
public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
var (document, textSpan, cancellationToken) = context;
if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles)
if (document.Project.Solution.WorkspaceKind == WorkspaceKind.MiscellaneousFiles)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public CSharpInlineTemporaryCodeRefactoringProvider()
public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
var (document, _, cancellationToken) = context;
if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles)
if (document.Project.Solution.WorkspaceKind == WorkspaceKind.MiscellaneousFiles)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public CSharpChangeNamespaceService()
SyntaxNode container,
CancellationToken cancellationToken)
{
if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles
if (document.Project.Solution.WorkspaceKind == WorkspaceKind.MiscellaneousFiles
|| document.IsGeneratedCode(cancellationToken))
{
return default;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ internal abstract class AbstractUseTypeCodeRefactoringProvider : CodeRefactoring
public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
var (document, textSpan, cancellationToken) = context;
if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles)
if (document.Project.Solution.WorkspaceKind == WorkspaceKind.MiscellaneousFiles)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public UseRecursivePatternsCodeRefactoringProvider()
public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
var (document, textSpan, cancellationToken) = context;
if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles)
if (document.Project.Solution.WorkspaceKind == WorkspaceKind.MiscellaneousFiles)
return;

if (textSpan.Length > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public AddConstructorParametersFromMembersCodeRefactoringProvider()
public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
var (document, textSpan, cancellationToken) = context;
if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles)
if (document.Project.Solution.WorkspaceKind == WorkspaceKind.MiscellaneousFiles)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private async Task<ImmutableArray<Reference>> FindResultsAsync(
}

private static bool IsHostOrRemoteWorkspace(Project project)
=> project.Solution.Workspace.Kind is WorkspaceKind.Host or WorkspaceKind.RemoteWorkspace;
=> project.Solution.WorkspaceKind is WorkspaceKind.Host or WorkspaceKind.RemoteWorkspace;

private async Task<ImmutableArray<Reference>> FindResultsAsync(
ConcurrentDictionary<Project, AsyncLazy<IAssemblySymbol>> projectToAssembly,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public async Task<ImmutableArray<CodeRefactoring>> GetRefactoringsAsync(
private static ImmutableArray<CodeRefactoringProvider> GetProjectRefactorings(Project project)
{
// TODO (https://github.com/dotnet/roslyn/issues/4932): Don't restrict refactorings in Interactive
if (project.Solution.Workspace.Kind == WorkspaceKind.Interactive)
if (project.Solution.WorkspaceKind == WorkspaceKind.Interactive)
return ImmutableArray<CodeRefactoringProvider>.Empty;

return ProjectCodeRefactoringProvider.GetExtensions(project);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal abstract partial class AbstractSyncNamespaceCodeRefactoringProvider<TNa
public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
var (document, textSpan, cancellationToken) = context;
if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles ||
if (document.Project.Solution.WorkspaceKind == WorkspaceKind.MiscellaneousFiles ||
document.IsGeneratedCode(cancellationToken))
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public IReadOnlyList<Lazy<CompletionProvider, CompletionProviderMetadata>> GetLa

public static ImmutableArray<CompletionProvider> GetProjectCompletionProviders(Project? project)
{
if (project is null || project.Solution.Workspace.Kind == WorkspaceKind.Interactive)
if (project is null || project.Solution.WorkspaceKind == WorkspaceKind.Interactive)
{
// TODO (https://github.com/dotnet/roslyn/issues/4932): Don't restrict completions in Interactive
return ImmutableArray<CompletionProvider>.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal abstract partial class AbstractConvertIfToSwitchCodeRefactoringProvider
public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
var (document, _, cancellationToken) = context;
if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles)
if (document.Project.Solution.WorkspaceKind == WorkspaceKind.MiscellaneousFiles)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private static async Task<ImmutableArray<DocumentHighlights>> CreateSpansAsync(
// Document once https://github.com/dotnet/roslyn/issues/5260 is fixed.
if (document == null)
{
Debug.Assert(solution.Workspace.Kind is WorkspaceKind.Interactive or WorkspaceKind.MiscellaneousFiles);
Debug.Assert(solution.WorkspaceKind is WorkspaceKind.Interactive or WorkspaceKind.MiscellaneousFiles);
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ private async Task ComputeRefactoringsAsync(
CleanCodeGenerationOptionsProvider fallbackOptions,
CancellationToken cancellationToken)
{
if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles)
if (document.Project.Solution.WorkspaceKind == WorkspaceKind.MiscellaneousFiles)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
if (document.Project.IsSubmission)
return;

if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles)
if (document.Project.Solution.WorkspaceKind == WorkspaceKind.MiscellaneousFiles)
return;

var service = document.GetRequiredLanguageService<IGenerateDefaultConstructorsService>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider(IPickMembe
public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
var (document, textSpan, cancellationToken) = context;
if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles)
if (document.Project.Solution.WorkspaceKind == WorkspaceKind.MiscellaneousFiles)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal abstract partial class AbstractIntroduceParameterService<
public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
var (document, textSpan, cancellationToken) = context;
if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles)
if (document.Project.Solution.WorkspaceKind == WorkspaceKind.MiscellaneousFiles)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public IntroduceVariableCodeRefactoringProvider()
public override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
var (document, textSpan, cancellationToken) = context;
if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles)
if (document.Project.Solution.WorkspaceKind == WorkspaceKind.MiscellaneousFiles)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override async Task ComputeRefactoringsAsync(CodeRefactoringContext conte
private static async Task<(SyntaxNode root, TArgumentSyntax argument, string argumentName)> TryGetArgumentInfoAsync(
Document document, TextSpan span, CancellationToken cancellationToken)
{
if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles)
if (document.Project.Solution.WorkspaceKind == WorkspaceKind.MiscellaneousFiles)
{
return default;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ protected AbstractUseNamedArgumentsCodeRefactoringProvider(
public sealed override async Task ComputeRefactoringsAsync(CodeRefactoringContext context)
{
var (document, _, cancellationToken) = context;
if (document.Project.Solution.Workspace.Kind == WorkspaceKind.MiscellaneousFiles)
if (document.Project.Solution.WorkspaceKind == WorkspaceKind.MiscellaneousFiles)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public async IAsyncEnumerable<CodeFixCollection> StreamFixesAsync(
}

// TODO (https://github.com/dotnet/roslyn/issues/4932): Don't restrict CodeFixes in Interactive
if (document.Project.Solution.Workspace.Kind != WorkspaceKind.Interactive && includeSuppressionFixes)
if (document.Project.Solution.WorkspaceKind != WorkspaceKind.Interactive && includeSuppressionFixes)
{
// Ensure that we do not register duplicate configuration fixes.
using var _2 = PooledHashSet<string>.GetInstance(out var registeredConfigurationFixTitles);
Expand Down Expand Up @@ -383,7 +383,7 @@ private async IAsyncEnumerable<CodeFixCollection> StreamFixesAsync(
yield break;

// TODO (https://github.com/dotnet/roslyn/issues/4932): Don't restrict CodeFixes in Interactive
var isInteractive = document.Project.Solution.Workspace.Kind == WorkspaceKind.Interactive;
var isInteractive = document.Project.Solution.WorkspaceKind == WorkspaceKind.Interactive;

// gather CodeFixProviders for all distinct diagnostics found for current span
using var _1 = PooledDictionary<CodeFixProvider, List<(TextSpan range, List<DiagnosticData> diagnostics)>>.GetInstance(out var fixerToRangesAndDiagnostics);
Expand Down Expand Up @@ -883,7 +883,7 @@ private ImmutableDictionary<LanguageKind, Lazy<ImmutableDictionary<CodeFixProvid
private ImmutableDictionary<DiagnosticId, ImmutableArray<CodeFixProvider>> GetProjectFixers(Project project)
{
// TODO (https://github.com/dotnet/roslyn/issues/4932): Don't restrict CodeFixes in Interactive
return project.Solution.Workspace.Kind == WorkspaceKind.Interactive
return project.Solution.WorkspaceKind == WorkspaceKind.Interactive
? ImmutableDictionary<DiagnosticId, ImmutableArray<CodeFixProvider>>.Empty
: _projectFixersMap.GetValue(project.AnalyzerReferences, _ => ComputeProjectFixers(project));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.CodeAnalysis.Structure;
internal static class BlockStructureOptionsStorage
{
public static BlockStructureOptions GetBlockStructureOptions(this IGlobalOptionService globalOptions, Project project)
=> GetBlockStructureOptions(globalOptions, project.Language, isMetadataAsSource: project.Solution.Workspace.Kind == WorkspaceKind.MetadataAsSource);
=> GetBlockStructureOptions(globalOptions, project.Language, isMetadataAsSource: project.Solution.WorkspaceKind == WorkspaceKind.MetadataAsSource);

public static BlockStructureOptions GetBlockStructureOptions(this IGlobalOptionService globalOptions, string language, bool isMetadataAsSource)
=> new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void UpdateTrackedDocument(Uri uri, SourceText newSourceText)
// Ensure we have the latest lsp solutions
var updatedSolutions = await GetLspSolutionsAsync(cancellationToken).ConfigureAwait(false);

var (hostWorkspaceSolution, isForked) = updatedSolutions.FirstOrDefault(lspSolution => lspSolution.Solution.Workspace.Kind == _hostWorkspaceKind);
var (hostWorkspaceSolution, isForked) = updatedSolutions.FirstOrDefault(lspSolution => lspSolution.Solution.WorkspaceKind == _hostWorkspaceKind);
_requestTelemetryLogger.UpdateUsedForkedSolutionCounter(isForked);

return hostWorkspaceSolution;
Expand All @@ -184,7 +184,7 @@ public void UpdateTrackedDocument(Uri uri, SourceText newSourceText)
var document = documents.FindDocumentInProjectContext(textDocumentIdentifier);

// Record metadata on how we got this document.
var workspaceKind = document.Project.Solution.Workspace.Kind;
var workspaceKind = document.Project.Solution.WorkspaceKind;
_requestTelemetryLogger.UpdateFindDocumentTelemetryData(success: true, workspaceKind);
_requestTelemetryLogger.UpdateUsedForkedSolutionCounter(isForked);
_logger.TraceInformation($"{document.FilePath} found in workspace {workspaceKind}");
Expand All @@ -194,7 +194,7 @@ public void UpdateTrackedDocument(Uri uri, SourceText newSourceText)
}

// We didn't find the document in any workspace, record a telemetry notification that we did not find it.
var searchedWorkspaceKinds = string.Join(";", lspSolutions.SelectAsArray(lspSolution => lspSolution.Solution.Workspace.Kind));
var searchedWorkspaceKinds = string.Join(";", lspSolutions.SelectAsArray(lspSolution => lspSolution.Solution.WorkspaceKind));
_logger.TraceError($"Could not find '{uri}'. Searched {searchedWorkspaceKinds}");
_requestTelemetryLogger.UpdateFindDocumentTelemetryData(success: false, workspaceKind: null);

Expand Down Expand Up @@ -293,7 +293,7 @@ private async Task<bool> DoesAllTextMatchWorkspaceSolutionAsync(ImmutableDiction

if (!isTextEquivalent)
{
_logger.TraceWarning($"Text for {uriInWorkspace} did not match document text {firstDocument.Id} in workspace's {firstDocument.Project.Solution.Workspace.Kind} current solution");
_logger.TraceWarning($"Text for {uriInWorkspace} did not match document text {firstDocument.Id} in workspace's {firstDocument.Project.Solution.WorkspaceKind} current solution");
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected override async Task ProduceTagsAsync(
if (document == null)
return;

if (document.Project.Solution.Workspace.Kind == WorkspaceKind.Interactive)
if (document.Project.Solution.WorkspaceKind == WorkspaceKind.Interactive)
return;

var inheritanceMarginInfoService = document.GetLanguageService<IInheritanceMarginService>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ await TestServices.SolutionExplorer.OpenFileAsync(

var document = await TestServices.Editor.GetActiveDocumentAsync(HangMitigatingCancellationToken);
RoslynDebug.AssertNotNull(document);
Assert.NotEqual(WorkspaceKind.MetadataAsSource, document.Project.Solution.Workspace.Kind);
Assert.NotEqual(WorkspaceKind.MetadataAsSource, document.Project.Solution.WorkspaceKind);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public IEnumerator GetEnumerator()

var document = await TestServices.Editor.GetActiveDocumentAsync(HangMitigatingCancellationToken);
RoslynDebug.AssertNotNull(document);
Assert.Equal(WorkspaceKind.MetadataAsSource, document.Project.Solution.Workspace.Kind);
Assert.Equal(WorkspaceKind.MetadataAsSource, document.Project.Solution.WorkspaceKind);
}

[IdeFact(Skip = "https://github.com/dotnet/roslyn/issues/62286")]
Expand Down Expand Up @@ -160,7 +160,7 @@ class Implementation : IBar

var document = await TestServices.Editor.GetActiveDocumentAsync(HangMitigatingCancellationToken);
RoslynDebug.AssertNotNull(document);
Assert.NotEqual(WorkspaceKind.MetadataAsSource, document.Project.Solution.Workspace.Kind);
Assert.NotEqual(WorkspaceKind.MetadataAsSource, document.Project.Solution.WorkspaceKind);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Namespace Microsoft.VisualStudio.LanguageServices.VisualBasic.Help
End If

If token.Span.IntersectsWith(span) OrElse token.GetAncestor(Of XmlElementSyntax)() IsNot Nothing Then
Dim visitor = New Visitor(token.Span, Await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(False), document.Project.Solution.Workspace.Kind <> WorkspaceKind.MetadataAsSource, Me, cancellationToken)
Dim visitor = New Visitor(token.Span, Await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(False), document.Project.Solution.WorkspaceKind <> WorkspaceKind.MetadataAsSource, Me, cancellationToken)
visitor.Visit(token.Parent)
Return visitor.result
End If
Expand Down
2 changes: 1 addition & 1 deletion src/Workspaces/Core/Portable/FindSymbols/SymbolFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ internal static async Task<ImmutableArray<ISymbol>> FindLinkedSymbolsAsync(
// to fetch the #load'ed tree's Document once https://github.com/dotnet/roslyn/issues/5260 is fixed.
if (originalDocument == null)
{
Debug.Assert(solution.Workspace.Kind is WorkspaceKind.Interactive or WorkspaceKind.MiscellaneousFiles);
Debug.Assert(solution.WorkspaceKind is WorkspaceKind.Interactive or WorkspaceKind.MiscellaneousFiles);
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private Solution(SolutionState state)
}

internal Solution(Workspace workspace, SolutionInfo.SolutionAttributes solutionAttributes, SolutionOptionSet options, IReadOnlyList<AnalyzerReference> analyzerReferences)
: this(new SolutionState(workspace.PrimaryBranchId, workspace.Services, solutionAttributes, options, analyzerReferences))
: this(new SolutionState(workspace.PrimaryBranchId, workspace.Kind, workspace.Services, solutionAttributes, options, analyzerReferences))
{
}

Expand All @@ -49,6 +49,8 @@ internal Solution(Workspace workspace, SolutionInfo.SolutionAttributes solutionA

internal HostWorkspaceServices Services => _state.Services;

internal string? WorkspaceKind => _state.WorkspaceKind;

internal BranchId BranchId => _state.BranchId;

internal ProjectState? GetProjectState(ProjectId projectId) => _state.GetProjectState(projectId);
Expand Down
Loading