Skip to content
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
1 change: 1 addition & 0 deletions SpellingExclusions.dic
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
awaitable
Refactorings
Infos
cref
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.RemoveUnnecessaryImport
CSharpRemoveUnnecessaryImportsCodeFixProvider>;

[Trait(Traits.Feature, Traits.Features.CodeActionsRemoveUnnecessaryImports)]
public class RemoveUnnecessaryImportsTests
public sealed class RemoveUnnecessaryImportsTests
{
private static readonly string s_tab = "\t";

[Fact]
public async Task TestNoReferences()
{
Expand Down Expand Up @@ -2246,4 +2248,36 @@ static void Main(string[] args)
"""
}.RunAsync();
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/65114")]
public async Task DoNotTouchInnerNamespaceWithoutUsings()
{
await VerifyCS.VerifyCodeFixAsync(
$$"""
[|{|IDE0005:using System;
using System.Collections.Generic;
using System.Linq;|}|]

namespace N
{
{{s_tab}}class Program
{
static void Main(string[] args)
{
}
}
}
""",
$$"""
namespace N
{
{{s_tab}}class Program
{
static void Main(string[] args)
{
}
}
}
""");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
// 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.Immutable;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeFixes;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Formatting;
using Microsoft.CodeAnalysis.Shared.Extensions;

Expand All @@ -30,19 +28,19 @@ public sealed override Task RegisterCodeFixesAsync(CodeFixContext context)
context.RegisterCodeFix(
CodeAction.Create(
title,
c => RemoveUnnecessaryImportsAsync(context.Document, c),
cancellationToken => RemoveUnnecessaryImportsAsync(context.Document, cancellationToken),
title),
context.Diagnostics);
return Task.CompletedTask;
}

protected abstract string GetTitle();

private static async Task<Document> RemoveUnnecessaryImportsAsync(
private static Task<Document> RemoveUnnecessaryImportsAsync(
Document document,
CancellationToken cancellationToken)
{
var service = document.GetRequiredLanguageService<IRemoveUnnecessaryImportsService>();
return await service.RemoveUnnecessaryImportsAsync(document, cancellationToken).ConfigureAwait(false);
return service.RemoveUnnecessaryImportsAsync(document, cancellationToken);
}
}
Loading
Loading