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 eng/config/BannedSymbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ M:Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxTree.Create(Microsoft.Code
M:Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxTree.Create(Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxNode,Microsoft.CodeAnalysis.VisualBasic.VisualBasicParseOptions,System.String,System.Text.Encoding); Use VisualBasicSyntaxTree sublass that takes checksum algorithm
M:Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxTree.ParseText(System.String,Microsoft.CodeAnalysis.VisualBasic.VisualBasicParseOptions,System.String,System.Text.Encoding,System.Collections.Immutable.ImmutableDictionary{System.String,Microsoft.CodeAnalysis.ReportDiagnostic},System.Threading.CancellationToken); Use overload with SourceText
M:Microsoft.CodeAnalysis.Workspaces.Workspace.SetCurrentSolution(Microsoft.CodeAnalysis.Solution); Use SetCurrentSolutionEx instead.
M:Microsoft.CodeAnalysis.Project.AddDocument(System.String,System.String,System.Collections.Generic.IEnumerable{System.String},System.String); Use overload that takes SourceText. Make sure SourceText is created with encoding and checksum algorithm.
M:System.Enum.GetHashCode(); Cast to integral type to avoid boxing on .NET Framework
M:Microsoft.CodeAnalysis.CodeActions.CodeAction.PostProcessAsync(System.Collections.Generic.IEnumerable{Microsoft.CodeAnalysis.CodeActions.CodeActionOperation},System.Threading.CancellationToken); Use overload that takes a solution
M:Microsoft.CodeAnalysis.CodeActions.CodeAction.PostProcessChangesAsync(Microsoft.CodeAnalysis.Solution,System.Threading.CancellationToken); Use overload that takes a solution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,7 @@ await TestMissingInRegularAndScriptAsync(
"""
<Workspace>
<Project Language = "C#" AssemblyName="Assembly1" CommonReferences="true">
<Document FilePath = "z:\\File1.cs">
<Document FilePath = "File1.cs">
public sealed partial class Test
{
private int [|_value|];
Expand All @@ -2021,7 +2021,7 @@ public static void M()
=> _ = new Test { Value = 1 };
}
</Document>
<Document FilePath = "z:\\File2.g.cs">
<Document FilePath = "File2.g.cs">
using System.CodeDom.Compiler;

[GeneratedCode(null, null)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2751,15 +2751,15 @@ await TestInRegularAndScript1Async(
"""
<Workspace>
<Project Language = "C#" AssemblyName="Assembly1" CommonReferences="true">
<Document FilePath = "z:\\file.cs">
<Document FilePath = "file.cs">
public class Foo
{
private readonly object o;

[||]public object O => o;
}
</Document>
<AnalyzerConfigDocument FilePath = "z:\\.editorconfig">
<AnalyzerConfigDocument FilePath = ".editorconfig">
[*]
indent_style = tab
</AnalyzerConfigDocument>
Expand All @@ -2769,13 +2769,13 @@ public class Foo
"""
<Workspace>
<Project Language = "C#" AssemblyName="Assembly1" CommonReferences="true">
<Document FilePath = "z:\\file.cs">
<Document FilePath = "file.cs">
public class Foo
{
public object O { get; }
}
</Document>
<AnalyzerConfigDocument FilePath = "z:\\.editorconfig">
<AnalyzerConfigDocument FilePath = ".editorconfig">
[*]
indent_style = tab
</AnalyzerConfigDocument>
Expand All @@ -2791,15 +2791,15 @@ await TestInRegularAndScript1Async(
"""
<Workspace>
<Project Language = "C#" AssemblyName="Assembly1" CommonReferences="true">
<Document FilePath = "z:\\file.cs">
<Document FilePath = "file.cs">
public class Foo
{
private readonly object o;

[||]public object O => o;
}
</Document>
<AnalyzerConfigDocument FilePath = "z:\\.editorconfig">
<AnalyzerConfigDocument FilePath = ".editorconfig">
[*]
indent_style = space
</AnalyzerConfigDocument>
Expand All @@ -2809,13 +2809,13 @@ public class Foo
"""
<Workspace>
<Project Language = "C#" AssemblyName="Assembly1" CommonReferences="true">
<Document FilePath = "z:\\file.cs">
<Document FilePath = "file.cs">
public class Foo
{
public object O { get; }
}
</Document>
<AnalyzerConfigDocument FilePath = "z:\\.editorconfig">
<AnalyzerConfigDocument FilePath = ".editorconfig">
[*]
indent_style = space
</AnalyzerConfigDocument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ End Class", options:=[Option](FormattingOptions2.UseTabs, False))
Await TestInRegularAndScriptAsync(
"<Workspace>
<Project Language = ""Visual Basic"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath = ""z:\\file.vb"">
<Document FilePath = ""file.vb"">
Public Class Foo
[||]Private ReadOnly o2 As Object

Expand All @@ -1137,20 +1137,20 @@ Public Class Foo
End Property
End Class
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">
<AnalyzerConfigDocument FilePath = "".editorconfig"">
[*]
indent_style = tab
</AnalyzerConfigDocument>
</Project>
</Workspace>",
"<Workspace>
<Project Language = ""Visual Basic"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath = ""z:\\file.vb"">
<Document FilePath = ""file.vb"">
Public Class Foo
Public ReadOnly Property O As Object
End Class
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">
<AnalyzerConfigDocument FilePath = "".editorconfig"">
[*]
indent_style = tab
</AnalyzerConfigDocument>
Expand All @@ -1163,7 +1163,7 @@ indent_style = tab
Await TestInRegularAndScriptAsync(
"<Workspace>
<Project Language = ""Visual Basic"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath = ""z:\\file.vb"">
<Document FilePath = ""file.vb"">
Public Class Foo
[||]Private ReadOnly o2 As Object

Expand All @@ -1174,20 +1174,20 @@ Public Class Foo
End Property
End Class
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">
<AnalyzerConfigDocument FilePath = "".editorconfig"">
[*]
indent_style = space
</AnalyzerConfigDocument>
</Project>
</Workspace>",
"<Workspace>
<Project Language = ""Visual Basic"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath = ""z:\\file.vb"">
<Document FilePath = ""file.vb"">
Public Class Foo
Public ReadOnly Property O As Object
End Class
</Document>
<AnalyzerConfigDocument FilePath = ""z:\\.editorconfig"">
<AnalyzerConfigDocument FilePath = "".editorconfig"">
[*]
indent_style = space
</AnalyzerConfigDocument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,15 +516,15 @@ public async Task AddParameter_Formatting_PreserveIndentBraces_Editorconfig()
var markup = @"
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document FilePath=""z:\\file.cs"">
<Document FilePath=""file.cs"">
public class C
{
public void M$$()
{
}
}
</Document>
<AnalyzerConfigDocument FilePath=""z:\\.editorconfig"">[*.cs]
<AnalyzerConfigDocument FilePath="".editorconfig"">[*.cs]
csharp_indent_braces = true
</AnalyzerConfigDocument>
</Project>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,7 @@ public async Task RemoveEnumeratorCancellationAttribute()
var markup = """
<Workspace>
<Project Language="C#" AssemblyName="Assembly1" CommonReferencesNet8="true">
<Document FilePath="z:\\file.cs"><![CDATA[using System;
<Document FilePath="file.cs"><![CDATA[using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ void assertDescription(string label, string value)
Assert.Equal(value, descriptionItem.Details.Single().Text);
}

assertDescription("File:", w.Documents.Single().Name);
assertDescription("File:", w.Documents.Single().FilePath);
assertDescription("Line:", "3"); // one based line number
assertDescription("Project:", "Test");
});
Expand Down
4 changes: 2 additions & 2 deletions src/EditorFeatures/CSharpTest/NavigateTo/NavigateToTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1029,13 +1029,13 @@ await TestAsync(testHost, composition, """

var descriptionItems = itemDisplay.DescriptionItems;

void assertDescription(string label, string value)
void assertDescription(string label, string? value)
{
var descriptionItem = descriptionItems.Single(i => i.Category.Single().Text == label);
Assert.Equal(value, descriptionItem.Details.Single().Text);
}

assertDescription("File:", w.Documents.Single().Name);
assertDescription("File:", w.Documents.Single().FilePath);
assertDescription("Line:", "3"); // one based line number
assertDescription("Project:", "Test");
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Threading;
Expand Down Expand Up @@ -77,16 +78,21 @@ private static async Task VerifyGetRenameContextAsync(
[WorkItem("https://github.com/dotnet/roslyn/issues/74545")]
public async Task VerifyContextReachEndOfFile()
{
var markup = @"
public class Sampl$$eClass()
{
}";
var markup = """
public class Sampl$$eClass()
{
}
""";

var escapedPath = Path.Combine(TestWorkspace.RootDirectory, "test1.cs").Replace("\\", "\\\\");

await VerifyGetRenameContextAsync(
markup,
@"
{
""definition"" : [ {""Item1"":""test1.cs"", ""Item2"":""public class SampleClass()\r\n{\r\n}""} ]
}",
$$"""
{
"definition": [{"Item1":"{{escapedPath}}", "Item2":"public class SampleClass()\r\n{\r\n}"}]
}
""",
new SymbolRenameOptions(),
CancellationToken.None);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ await TestAddDocument(
}
}

protected async Task<Tuple<Solution, Solution>> TestAddDocumentAsync(
protected async Task<(Solution oldSolution, Solution newSolution)> TestAddDocumentAsync(
TestParameters parameters,
EditorTestWorkspace workspace,
string expectedMarkup,
Expand Down Expand Up @@ -71,7 +71,7 @@ await TestAddDocument(
expectedDocumentName, action);
}

private async Task<Tuple<Solution, Solution>> TestAddDocument(
private async Task<(Solution oldSolution, Solution newSolution)> TestAddDocument(
EditorTestWorkspace workspace,
string expectedMarkup,
ImmutableArray<string> expectedFolders,
Expand All @@ -89,7 +89,7 @@ private async Task<Tuple<Solution, Solution>> TestAddDocument(
expectedDocumentName: expectedDocumentName);
}

protected static async Task<Tuple<Solution, Solution>> TestAddDocument(
protected static async Task<(Solution oldSolution, Solution newSolution)> TestAddDocument(
EditorTestWorkspace workspace,
string expected,
ImmutableArray<CodeActionOperation> operations,
Expand All @@ -98,9 +98,7 @@ protected static async Task<Tuple<Solution, Solution>> TestAddDocument(
ImmutableArray<string> expectedFolders,
string expectedDocumentName)
{
var appliedChanges = await ApplyOperationsAndGetSolutionAsync(workspace, operations);
var oldSolution = appliedChanges.Item1;
var newSolution = appliedChanges.Item2;
var (oldSolution, newSolution) = await ApplyOperationsAndGetSolutionAsync(workspace, operations);

Document addedDocument = null;
if (!hasProjectChange)
Expand Down Expand Up @@ -155,6 +153,6 @@ protected static async Task<Tuple<Solution, Solution>> TestAddDocument(
Assert.True(hasPreview);
}

return Tuple.Create(oldSolution, newSolution);
return (oldSolution, newSolution);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,11 @@ internal async Task TestWithMockedGenerateTypeDialog(
Assert.Equal(action.Title, FeaturesResources.Generate_new_type);
var operations = await action.GetOperationsAsync(
workspace.CurrentSolution, CodeAnalysisProgress.None, CancellationToken.None);
Tuple<Solution, Solution> oldSolutionAndNewSolution = null;
Solution oldSolution, newSolution;

if (!isNewFile)
{
oldSolutionAndNewSolution = await TestOperationsAsync(
(oldSolution, newSolution) = await TestOperationsAsync(
testState.Workspace, expected, operations,
conflictSpans: [],
renameSpans: [],
Expand All @@ -113,11 +113,11 @@ internal async Task TestWithMockedGenerateTypeDialog(
}
else
{
oldSolutionAndNewSolution = await TestAddDocument(
(oldSolution, newSolution) = await TestAddDocument(
testState.Workspace,
expected,
operations,
projectName != null,
hasProjectChange: projectName != null,
testState.ProjectToBeModified.Id,
newFileFolderContainers,
newFileName);
Expand All @@ -136,8 +136,6 @@ await TestOperationsAsync(testState.Workspace, expectedTextWithUsings, operation

if (checkIfUsingsNotIncluded)
{
var oldSolution = oldSolutionAndNewSolution.Item1;
var newSolution = oldSolutionAndNewSolution.Item2;
var changedDocumentIds = SolutionUtilities.GetChangedDocuments(oldSolution, newSolution);

Assert.False(changedDocumentIds.Contains(testState.InvocationDocument.Id));
Expand All @@ -147,7 +145,6 @@ await TestOperationsAsync(testState.Workspace, expectedTextWithUsings, operation
if (projectName != null)
{
var appliedChanges = await ApplyOperationsAndGetSolutionAsync(testState.Workspace, operations);
var newSolution = appliedChanges.Item2;
var triggeredProject = newSolution.GetProject(testState.TriggeredProject.Id);

// Make sure the Project reference is present
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.CodeRefactorings.MoveType;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.UnitTests;
using Roslyn.Test.Utilities;
Expand Down Expand Up @@ -159,19 +161,26 @@ private protected async Task TestMoveTypeToNewFileAsync(
var sourceDocumentId = workspace.Documents[0].Id;

// Verify the newly added document and its text
var oldSolutionAndNewSolution = await TestAddDocumentAsync(
var (oldSolution, newSolution) = await TestAddDocumentAsync(
testOptions, workspace, destinationDocumentText,
expectedDocumentName, destinationDocumentContainers);

// Verify source document's text after moving type.
var oldSolution = oldSolutionAndNewSolution.Item1;
var newSolution = oldSolutionAndNewSolution.Item2;
var changedDocumentIds = SolutionUtilities.GetChangedDocuments(oldSolution, newSolution);
Assert.True(changedDocumentIds.Contains(sourceDocumentId), "source document was not changed.");

var modifiedSourceDocument = newSolution.GetDocument(sourceDocumentId);
var actualSourceTextAfterRefactoring = (await modifiedSourceDocument.GetTextAsync()).ToString();
AssertEx.Equal(expectedSourceTextAfterRefactoring, actualSourceTextAfterRefactoring);
var addedDocument = SolutionUtilities.GetSingleAddedDocument(oldSolution, newSolution);
var addedSourceText = await addedDocument.GetTextAsync();
var oldSourceDocument = oldSolution.GetRequiredDocument(sourceDocumentId);
var oldSourceText = await oldSourceDocument.GetTextAsync();
var newSourceDocument = newSolution.GetRequiredDocument(sourceDocumentId);
var newSourceText = await newSourceDocument.GetTextAsync();

Assert.Equal(Path.Combine(Path.GetDirectoryName(addedDocument.FilePath), expectedDocumentName), addedDocument.FilePath);
Assert.Equal(oldSourceText.Encoding, addedSourceText.Encoding);
Assert.Equal(oldSourceText.ChecksumAlgorithm, addedSourceText.ChecksumAlgorithm);

AssertEx.Equal(expectedSourceTextAfterRefactoring, newSourceText.ToString());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ internal Document GetDocument(MetadataAsSourceFile file)

internal async Task<ISymbol> GetNavigationSymbolAsync()
{
var testDocument = Workspace.Documents.Single(d => d.FilePath == "SourceDocument");
var testDocument = Workspace.Documents.Single(d => d.Name == "SourceDocument");
var document = Workspace.CurrentSolution.GetRequiredDocument(testDocument.Id);

var syntaxRoot = await document.GetRequiredSyntaxRootAsync(CancellationToken.None);
Expand Down
Loading