Skip to content

Commit

Permalink
Merge pull request #54425 from dotnet/merges/main-to-main-vs-deps
Browse files Browse the repository at this point in the history
Merge main to main-vs-deps
  • Loading branch information
msftbot[bot] authored Jun 27, 2021
2 parents c1a11ab + 7cf4162 commit cf20979
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 4 deletions.
4 changes: 3 additions & 1 deletion azure-pipelines-official.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,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

0 comments on commit cf20979

Please sign in to comment.