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

Merge main to main-vs-deps #54425

Merged
4 commits merged into from
Jun 27, 2021
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
4 changes: 3 additions & 1 deletion azure-pipelines-official.yml
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ stages:
vmImage: vs2017-win2016

- stage: insert
dependsOn: build
dependsOn:
- build
- publish_using_darc
displayName: Insert to VS

jobs:
Expand Down
4 changes: 2 additions & 2 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
<Sha>7e80445ee82adbf9a8e6ae601ac5e239d982afaa</Sha>
<SourceBuild RepoName="xliff-tasks" ManagedOnly="true" />
</Dependency>
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build" Version="0.1.0-alpha.1.21323.2">
<Dependency Name="Microsoft.SourceBuild.Intermediate.source-build" Version="0.1.0-alpha.1.21325.1">
<Uri>https://github.com/dotnet/source-build</Uri>
<Sha>c35d744cbe24f85d2165a5edb1730355b8cb916f</Sha>
<Sha>0655d162f86955d32d9e564024beb8abecc171d2</Sha>
<SourceBuild RepoName="source-build" ManagedOnly="true" />
</Dependency>
</ProductDependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1408,5 +1408,51 @@ record CacheContext(String Message);

await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)]
public async Task MoveClassInTopLevelStatements()
{
var code = @"
using ConsoleApp1;
using System;

var c = new C();
Console.WriteLine(c.Hello);

class [||]C
{
public string Hello => ""Hello"";
}";

var codeAfterMove = @"
using ConsoleApp1;
using System;

var c = new C();
Console.WriteLine(c.Hello);
";

var expectedDocumentName = "C.cs";
var destinationDocumentText = @"class C
{
public string Hello => ""Hello"";
}";

await TestMoveTypeToNewFileAsync(code, codeAfterMove, expectedDocumentName, destinationDocumentText);
}

[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)]
public async Task MissingInTopLevelStatementsOnly()
{
var code = @"
using ConsoleApp1;
using System;

var c = new object();
[||]Console.WriteLine(c.ToString());
";

await TestMissingAsync(code);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.PooledObjects;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;

Expand Down Expand Up @@ -107,6 +109,11 @@ private ImmutableArray<CodeAction> CreateActions(State state, CancellationToken
var manyTypes = MultipleTopLevelTypeDeclarationInSourceDocument(state.SemanticDocument.Root);
var isNestedType = IsNestedType(state.TypeNode);

var syntaxFacts = state.SemanticDocument.Document.GetRequiredLanguageService<ISyntaxFactsService>();
var isClassNextToGlobalStatements = manyTypes
? false
: ClassNextToGlobalStatements(state.SemanticDocument.Root, syntaxFacts);

var suggestedFileNames = GetSuggestedFileNames(
state.TypeNode,
isNestedType,
Expand All @@ -120,7 +127,9 @@ private ImmutableArray<CodeAction> CreateActions(State state, CancellationToken
// case 2: This is a nested type, offer to move to new file.
// case 3: If there is a single type decl in current file, *do not* offer move to new file,
// rename actions are sufficient in this case.
if (manyTypes || isNestedType)
// case 4: If there are top level statements(Global statements) offer to move even
// in cases where there are only one class in the file.
if (manyTypes || isNestedType || isClassNextToGlobalStatements)
{
foreach (var fileName in suggestedFileNames)
{
Expand Down Expand Up @@ -152,6 +161,9 @@ private ImmutableArray<CodeAction> CreateActions(State state, CancellationToken
return actions.ToImmutable();
}

private static bool ClassNextToGlobalStatements(SyntaxNode root, ISyntaxFactsService syntaxFacts)
=> syntaxFacts.ContainsGlobalStatement(root);

private CodeAction GetCodeAction(State state, string fileName, MoveTypeOperationKind operationKind) =>
new MoveTypeCodeAction((TService)this, state, operationKind, fileName);

Expand Down