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

Remove Razor and editor inference document option providers #61091

Merged
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 @@ -9,6 +9,7 @@
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.EditorConfigSettings.Extensions;
Expand Down Expand Up @@ -51,10 +52,9 @@ protected void Update()
return;
}

var configOptionsProvider = new ProjectState.ProjectAnalyzerConfigOptionsProvider(project.State);
var workspaceOptions = configOptionsProvider.GetOptionsForSourcePath(givenFolder.FullName);
var configData = project.State.GetAnalyzerOptionsForPath(givenFolder.FullName, CancellationToken.None);
var result = project.GetAnalyzerConfigOptions();
var options = new CombinedAnalyzerConfigOptions(workspaceOptions, result);
var options = new CombinedAnalyzerConfigOptions(configData.ConfigOptions, result);
UpdateOptions(options, Workspace.Options);
}

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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.ErrorReporting;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Host.Mef;
using Microsoft.CodeAnalysis.Text;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;

namespace Microsoft.CodeAnalysis.Formatting;

[ExportWorkspaceService(typeof(ILegacyIndentationManagerWorkspaceService)), Shared]
internal sealed class LegacyIndentationManagerWorkspaceService : ILegacyIndentationManagerWorkspaceService
{
private readonly IIndentationManagerService _indentationManagerService;

[ImportingConstructor]
[Obsolete(MefConstruction.ImportingConstructorMessage, error: true)]
public LegacyIndentationManagerWorkspaceService(IIndentationManagerService indentationManagerService)
{
_indentationManagerService = indentationManagerService;
}

private static ITextBuffer GetRequiredTextBuffer(SourceText text)
=> text.Container.TryGetTextBuffer() ?? throw new InvalidOperationException(
"We had an open document but it wasn't associated with a buffer. That meant we couldn't apply formatting settings.");

public bool UseSpacesForWhitespace(SourceText text)
=> _indentationManagerService.UseSpacesForWhitespace(GetRequiredTextBuffer(text), explicitFormat: false);

public int GetTabSize(SourceText text)
=> _indentationManagerService.GetTabSize(GetRequiredTextBuffer(text), explicitFormat: false);

public int GetIndentSize(SourceText text)
=> _indentationManagerService.GetIndentSize(GetRequiredTextBuffer(text), explicitFormat: false);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

using System;
using System.Composition;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Host.Mef;

namespace Microsoft.CodeAnalysis.Options
Expand All @@ -22,5 +23,11 @@ public LegacyGlobalOptionsWorkspaceService(IGlobalOptionService globalOptions)
{
GlobalOptions = globalOptions;
}

public bool RazorUseTabs
=> GlobalOptions.GetOption(RazorLineFormattingOptionsStorage.UseTabs);

public int RazorTabSize
=> GlobalOptions.GetOption(RazorLineFormattingOptionsStorage.TabSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public abstract partial class AbstractLanguageServerProtocolTests

private class TestSpanMapperProvider : IDocumentServiceProvider
{
TService IDocumentServiceProvider.GetService<TService>()
=> (TService)(object)new TestSpanMapper();
TService? IDocumentServiceProvider.GetService<TService>() where TService : class
=> typeof(TService) == typeof(ISpanMappingService) ? (TService)(object)new TestSpanMapper() : null;
}

internal class TestSpanMapper : ISpanMappingService
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -372,16 +372,12 @@ private IReadOnlyList<StateSet> GetStateSetsForFullSolutionAnalysis(IEnumerable<
stateSets = stateSets.Where(s => !s.FromBuild(project.Id));
}

// Compute analyzer config options for computing effective severity.
// Note that these options are not cached onto the project, so we compute it once upfront.
var analyzerConfigOptions = project.GetAnalyzerConfigOptions();

// Include only analyzers we want to run for full solution analysis.
// Analyzers not included here will never be saved because result is unknown.
return stateSets.Where(s => IsCandidateForFullSolutionAnalysis(s.Analyzer, project, analyzerConfigOptions)).ToList();
return stateSets.Where(s => IsCandidateForFullSolutionAnalysis(s.Analyzer, project)).ToList();
}

private bool IsCandidateForFullSolutionAnalysis(DiagnosticAnalyzer analyzer, Project project, AnalyzerConfigData? analyzerConfigOptions)
private bool IsCandidateForFullSolutionAnalysis(DiagnosticAnalyzer analyzer, Project project)
{
// PERF: Don't query descriptors for compiler analyzer or workspace load analyzer, always execute them.
if (analyzer == FileContentLoadAnalyzer.Instance ||
Expand Down Expand Up @@ -413,7 +409,9 @@ private bool IsCandidateForFullSolutionAnalysis(DiagnosticAnalyzer analyzer, Pro

// For most of analyzers, the number of diagnostic descriptors is small, so this should be cheap.
var descriptors = DiagnosticAnalyzerInfoCache.GetDiagnosticDescriptors(analyzer);
return descriptors.Any(d => d.GetEffectiveSeverity(project.CompilationOptions!, analyzerConfigOptions?.Result) != ReportDiagnostic.Hidden);
var analyzerConfigOptions = project.GetAnalyzerConfigOptions();

return descriptors.Any(d => d.GetEffectiveSeverity(project.CompilationOptions!, analyzerConfigOptions?.AnalyzerOptions, analyzerConfigOptions?.TreeOptions) != ReportDiagnostic.Hidden);
}

private void RaiseProjectDiagnosticsIfNeeded(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ private void UpdateSeverityMenuItemsChecked()

foreach (var diagnosticItem in group)
{
var severity = diagnosticItem.Descriptor.GetEffectiveSeverity(project.CompilationOptions, analyzerConfigOptions?.Result);
var severity = diagnosticItem.Descriptor.GetEffectiveSeverity(project.CompilationOptions, analyzerConfigOptions?.AnalyzerOptions, analyzerConfigOptions?.TreeOptions);
selectedItemSeverities.Add(severity);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private BulkObservableCollection<BaseItem> CreateDiagnosticAndGeneratorItems(Pro
.Select(g =>
{
var selectedDiagnostic = g.OrderBy(d => d, s_comparer).First();
var effectiveSeverity = selectedDiagnostic.GetEffectiveSeverity(options, analyzerConfigOptions?.Result);
var effectiveSeverity = selectedDiagnostic.GetEffectiveSeverity(options, analyzerConfigOptions?.AnalyzerOptions, analyzerConfigOptions?.TreeOptions);
return new DiagnosticItem(projectId, AnalyzerReference, selectedDiagnostic, effectiveSeverity, CommandHandler);
}));

Expand Down Expand Up @@ -183,7 +183,7 @@ void OnProjectConfigurationChanged()

foreach (var item in _items.OfType<DiagnosticItem>())
{
var effectiveSeverity = item.Descriptor.GetEffectiveSeverity(project.CompilationOptions, newAnalyzerConfigOptions?.Result);
var effectiveSeverity = item.Descriptor.GetEffectiveSeverity(project.CompilationOptions, newAnalyzerConfigOptions?.AnalyzerOptions, newAnalyzerConfigOptions?.TreeOptions);
item.UpdateEffectiveSeverity(effectiveSeverity);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Roslyn.Utilities;
using Microsoft.CodeAnalysis.ErrorReporting;
using Microsoft.CodeAnalysis.Diagnostics;
using static Microsoft.CodeAnalysis.ProjectState;

namespace Microsoft.CodeAnalysis.Options.EditorConfig
{
Expand All @@ -22,8 +23,9 @@ private sealed class EditorConfigDocumentOptionsProvider : IDocumentOptionsProvi
{
public async Task<IDocumentOptions?> GetOptionsForDocumentAsync(Document document, CancellationToken cancellationToken)
{
var data = await document.GetAnalyzerOptionsAsync(cancellationToken).ConfigureAwait(false);
return new DocumentOptions(data?.AnalyzerConfigOptions);
var provider = (ProjectAnalyzerConfigOptionsProvider)document.Project.State.AnalyzerOptions.AnalyzerConfigOptionsProvider;
var options = await provider.GetOptionsAsync(document.DocumentState, cancellationToken).ConfigureAwait(false);
return new DocumentOptions(options);
}

private sealed class DocumentOptions : IDocumentOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ namespace Microsoft.CodeAnalysis.Options
internal interface ILegacyGlobalOptionsWorkspaceService : IWorkspaceService
{
public IGlobalOptionService GlobalOptions { get; }

public bool RazorUseTabs { get; }
public int RazorTabSize { get; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 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.Text;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Text;

namespace Microsoft.CodeAnalysis.Formatting;

/// <summary>
/// Enables legacy APIs to access indentation inference editor APIs from workspace.
/// https://github.com/dotnet/roslyn/issues/61109
/// </summary>
internal interface ILegacyIndentationManagerWorkspaceService : IWorkspaceService
{
bool UseSpacesForWhitespace(SourceText text);
int GetTabSize(SourceText text);
int GetIndentSize(SourceText text);
}
Loading