未验证 提交 6d317555 编写于 作者: T Tomáš Matoušek 提交者: GitHub

ActiveStatementTagger Nullable annotations (#44053)

上级 458b0ded
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using Microsoft.VisualStudio.Text.Tagging;
namespace Microsoft.CodeAnalysis.Editor.Implementation.EditAndContinue
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
......@@ -20,7 +22,9 @@ internal sealed class ActiveStatementTagger : ForegroundThreadAffinitizedObject,
private readonly WorkspaceRegistration _workspaceRegistration;
private readonly ITextBuffer _buffer;
private IActiveStatementTrackingService _trackingServiceOpt;
private IActiveStatementTrackingService? _trackingService;
public event EventHandler<SnapshotSpanEventArgs>? TagsChanged;
public ActiveStatementTagger(IThreadingContext threadingContext, ITextBuffer buffer)
: base(threadingContext)
......@@ -35,21 +39,21 @@ public ActiveStatementTagger(IThreadingContext threadingContext, ITextBuffer buf
_buffer = buffer;
}
private void OnWorkspaceChanged(object sender, EventArgs e)
private void OnWorkspaceChanged(object? sender, EventArgs e)
=> ConnectToWorkspace(_workspaceRegistration.Workspace);
private void ConnectToWorkspace(Workspace workspaceOpt)
private void ConnectToWorkspace(Workspace? workspace)
{
var newServiceOpt = workspaceOpt?.Services.GetService<IActiveStatementTrackingService>();
if (newServiceOpt != null)
var newService = workspace?.Services.GetService<IActiveStatementTrackingService>();
if (newService != null)
{
newServiceOpt.TrackingSpansChanged += OnTrackingSpansChanged;
newService.TrackingSpansChanged += OnTrackingSpansChanged;
}
var previousServiceOpt = Interlocked.Exchange(ref _trackingServiceOpt, newServiceOpt);
if (previousServiceOpt != null)
var previousService = Interlocked.Exchange(ref _trackingService, newService);
if (previousService != null)
{
previousServiceOpt.TrackingSpansChanged -= OnTrackingSpansChanged;
previousService.TrackingSpansChanged -= OnTrackingSpansChanged;
}
}
......@@ -58,11 +62,9 @@ public void Dispose()
AssertIsForeground();
_workspaceRegistration.WorkspaceChanged -= OnWorkspaceChanged;
ConnectToWorkspace(workspaceOpt: null);
ConnectToWorkspace(workspace: null);
}
public event EventHandler<SnapshotSpanEventArgs> TagsChanged;
private void OnTrackingSpansChanged(bool leafChanged)
{
var handler = TagsChanged;
......@@ -78,7 +80,7 @@ public IEnumerable<ITagSpan<ITextMarkerTag>> GetTags(NormalizedSnapshotSpanColle
{
AssertIsForeground();
var service = _trackingServiceOpt;
var service = _trackingService;
if (service == null)
{
yield break;
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
......@@ -26,7 +28,7 @@ internal sealed class ActiveStatementTaggerProvider : ITaggerProvider
public ActiveStatementTaggerProvider(IThreadingContext threadingContext)
=> _threadingContext = threadingContext;
public ITagger<T> CreateTagger<T>(ITextBuffer buffer) where T : ITag
public ITagger<T>? CreateTagger<T>(ITextBuffer buffer) where T : ITag
=> new ActiveStatementTagger(_threadingContext, buffer) as ITagger<T>;
}
}
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Composition;
using Microsoft.CodeAnalysis.EditAndContinue;
......
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System.ComponentModel.Composition;
using Microsoft.VisualStudio.Text.Adornments;
using Microsoft.VisualStudio.Utilities;
......@@ -14,6 +16,6 @@ internal static class EditAndContinueErrorTypeDefinition
[Export(typeof(ErrorTypeDefinition))]
[Name(Name)]
internal static ErrorTypeDefinition Definition;
internal static ErrorTypeDefinition? Definition;
}
}
......@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis.Host.Mef;
......
......@@ -2,7 +2,10 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using Microsoft.CodeAnalysis.Text;
......@@ -17,7 +20,7 @@ public abstract partial class Workspace
/// <summary>
/// Gets the workspace associated with the specific text container.
/// </summary>
public static bool TryGetWorkspace(SourceTextContainer textContainer, out Workspace workspace)
public static bool TryGetWorkspace(SourceTextContainer textContainer, [NotNullWhen(true)] out Workspace? workspace)
{
if (textContainer == null)
{
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册