未验证 提交 db428852 编写于 作者: P Petr Houška 提交者: GitHub

Merge branch 'master' into SyntaxKindsService-cleanup

......@@ -74,23 +74,23 @@
"vsMajorVersion": 16,
"ibcSourceBranch": "master-vs-deps"
},
"features/lspSupport": {
"features/razorSupport2": {
"nugetKind": [ "Shipping", "NonShipping" ],
"version": "3.1.*",
"nuget": [ "https://dotnet.myget.org/F/roslyn/api/v2/package" ],
"vsix": [ "https://dotnet.myget.org/F/roslyn/vsix/upload" ],
"channels": [ "lspSupport" ],
"channels": [ "razorSupport2" ],
"vsBranch": "lab/d16.1stg",
"vsMajorVersion": 16,
"ibcSourceBranch": "master-vs-deps"
},
"features/razorSupport2": {
"features/compilerNext": {
"nugetKind": [ "Shipping", "NonShipping" ],
"version": "3.1.*",
"version": "3.4.*",
"nuget": [ "https://dotnet.myget.org/F/roslyn/api/v2/package" ],
"vsix": [ "https://dotnet.myget.org/F/roslyn/vsix/upload" ],
"channels": [ "razorSupport2" ],
"vsBranch": "lab/d16.1stg",
"channels": [ "compilerNext" ],
"vsBranch": "master",
"vsMajorVersion": 16,
"ibcSourceBranch": "master-vs-deps"
}
......
......@@ -3,6 +3,7 @@
using System.Collections.Immutable;
using System.Linq;
using System.Reflection.Metadata.Ecma335;
using Microsoft.CodeAnalysis.CodeGen;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.CSharp.UnitTests;
......@@ -172,6 +173,67 @@ void F()
Row(5, TableIndex.CustomAttribute, EditAndContinueOperation.Default));
}
[Fact]
public void MethodWithStaticLocalFunction_ChangeStatic()
{
var source0 = MarkedSource(@"
using System;
class C
{
void F()
{
<N:0>int x() => 1;</N:0>
}
}");
var source1 = MarkedSource(@"
using System;
class C
{
void F()
{
<N:0>static int x() => 1;</N:0>
}
}");
var compilation0 = CreateCompilation(source0.Tree, options: ComSafeDebugDll.WithMetadataImportOptions(MetadataImportOptions.All));
var compilation1 = compilation0.WithSource(source1.Tree);
var v0 = CompileAndVerify(compilation0);
var md0 = ModuleMetadata.CreateFromImage(v0.EmittedAssemblyData);
var reader0 = md0.MetadataReader;
var f0 = compilation0.GetMember<MethodSymbol>("C.F");
var f1 = compilation1.GetMember<MethodSymbol>("C.F");
var generation0 = EmitBaseline.CreateInitialBaseline(md0, v0.CreateSymReader().GetEncMethodDebugInfo);
var diff1 = compilation1.EmitDifference(
generation0,
ImmutableArray.Create(new SemanticEdit(SemanticEditKind.Update, f0, f1, GetSyntaxMapFromMarkers(source0, source1), preserveLocalVariables: true)));
diff1.VerifySynthesizedMembers(
"C: {<F>g__x|0_0}");
var md1 = diff1.GetMetadata();
var reader1 = md1.Reader;
// Method updates
CheckEncLogDefinitions(reader1,
Row(1, TableIndex.MethodDef, EditAndContinueOperation.Default),
Row(3, TableIndex.MethodDef, EditAndContinueOperation.Default),
Row(5, TableIndex.CustomAttribute, EditAndContinueOperation.Default));
var testData0 = new CompilationTestData();
var bytes0 = compilation0.EmitToArray(testData: testData0);
var localFunction0 = testData0.GetMethodData("C.<F>g__x|0_0").Method;
Assert.True(localFunction0.IsStatic);
var localFunction1 = diff1.TestData.GetMethodData("C.<F>g__x|0_0").Method;
Assert.True(localFunction1.IsStatic);
}
[Fact]
public void MethodWithStaticLambdaGeneric1()
{
......
......@@ -6816,6 +6816,92 @@ static void F()
});
}
[Fact]
public void LocalFunction_AddStatic()
{
var src1 = @"class Test { void M() { int local() { throw null; } } }";
var src2 = @"class Test { void M() { static int local() { throw null; } } }";
var edits = GetTopEdits(src1, src2);
edits.VerifyEdits(
"Update [void M() { int local() { throw null; } }]@13 -> [void M() { static int local() { throw null; } }]@13");
edits.VerifyRudeDiagnostics();
}
[Fact]
public void LocalFunction_RemoveStatic()
{
var src1 = @"class Test { void M() { static int local() { throw null; } } }";
var src2 = @"class Test { void M() { int local() { throw null; } } }";
var edits = GetTopEdits(src1, src2);
edits.VerifyEdits(
"Update [void M() { static int local() { throw null; } }]@13 -> [void M() { int local() { throw null; } }]@13");
edits.VerifyRudeDiagnostics();
}
[Fact]
public void LocalFunction_AddUnsafe()
{
var src1 = @"class Test { void M() { int local() { throw null; } } }";
var src2 = @"class Test { void M() { unsafe int local() { throw null; } } }";
var edits = GetTopEdits(src1, src2);
edits.VerifyEdits(
"Update [void M() { int local() { throw null; } }]@13 -> [void M() { unsafe int local() { throw null; } }]@13");
edits.VerifyRudeDiagnostics();
}
[Fact]
public void LocalFunction_RemoveUnsafe()
{
var src1 = @"class Test { void M() { unsafe int local() { throw null; } } }";
var src2 = @"class Test { void M() { int local() { throw null; } } }";
var edits = GetTopEdits(src1, src2);
edits.VerifyEdits(
"Update [void M() { unsafe int local() { throw null; } }]@13 -> [void M() { int local() { throw null; } }]@13");
edits.VerifyRudeDiagnostics();
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/37054")]
public void LocalFunction_AddAsync()
{
var src1 = @"class Test { void M() { int local() { throw null; } } }";
var src2 = @"class Test { void M() { async int local() { throw null; } } }";
var edits = GetTopEdits(src1, src2);
edits.VerifyEdits(
"Update [void M() { int local() { throw null; } }]@13 -> [void M() { async int local() { throw null; } }]@13");
edits.VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.ModifiersUpdate, "async int local() ", FeaturesResources.method));
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/37054")]
public void LocalFunction_RemoveAsync()
{
var src1 = @"class Test { void M() { async int local() { throw null; } } }";
var src2 = @"class Test { void M() { int local() { throw null; } } }";
var edits = GetTopEdits(src1, src2);
edits.VerifyEdits(
"Update [void M() { async int local() { throw null; } }]@13 -> [void M() { int local() { throw null; } }]@13");
edits.VerifyRudeDiagnostics(
Diagnostic(RudeEditKind.ModifiersUpdate, "int local() ", FeaturesResources.method));
}
#endregion
#region Queries
......@@ -8413,7 +8499,7 @@ static async Task<int> F()
}
}
";
var edits = GetTopEdits(src1, src2, CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview));
var edits = GetTopEdits(src1, src2);
// consider: these edits can be allowed if we get more sophisticated
edits.VerifyRudeDiagnostics(
......@@ -8956,7 +9042,7 @@ public void VarPattern_Update()
if (o3 is (string k, int l2, int m)) return;
";
var edits = GetMethodEdits(src1, src2, CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview));
var edits = GetMethodEdits(src1, src2);
edits.VerifyEdits(
"Update [if (o is (var x, var y)) return;]@4 -> [if (o is (int x, int y1)) return;]@4",
......@@ -8984,7 +9070,7 @@ public void PositionalPattern_Update1()
};
";
var edits = GetMethodEdits(src1, src2, CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview));
var edits = GetMethodEdits(src1, src2);
edits.VerifyEdits(
@"Update [r = (x, y, z) switch {
......@@ -9017,7 +9103,7 @@ public void PositionalPattern_Update2()
};
";
var edits = GetMethodEdits(src1, src2, CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview));
var edits = GetMethodEdits(src1, src2);
edits.VerifyEdits(
@"Update [r = (x, y, z) switch {
......@@ -9054,7 +9140,7 @@ public void PositionalPattern_Reorder()
};
";
var edits = GetMethodEdits(src1, src2, CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview));
var edits = GetMethodEdits(src1, src2);
edits.VerifyEdits(
@"Update [r = (x, y, z) switch {
......@@ -9089,7 +9175,7 @@ public void PropertyPattern_Update()
if (o is string { Length: 7 } s7) return 5;
";
var edits = GetMethodEdits(src1, src2, CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview));
var edits = GetMethodEdits(src1, src2);
edits.VerifyEdits(
"Update [if (address is { State: \"WA\" }) return 1;]@4 -> [if (address is { ZipCode: 98052 }) return 4;]@4",
......@@ -9127,7 +9213,7 @@ public void RecursivePatterns_Reorder()
};
";
var edits = GetMethodEdits(src1, src2, CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview));
var edits = GetMethodEdits(src1, src2);
edits.VerifyEdits(
@"Update [r = obj switch
......
......@@ -1638,7 +1638,7 @@ public void VarPattern()
if (!(o7 is var (g, e, f))) return;
if (!(o3 is (string k, int l2, int m))) return;
";
var match = GetMethodMatches(src1, src2, CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview), kind: MethodKind.Regular);
var match = GetMethodMatches(src1, src2, kind: MethodKind.Regular);
var actual = ToMatchingPairs(match);
var expected = new MatchingPairs {
......@@ -1687,7 +1687,7 @@ public void PositionalPattern()
};
";
var match = GetMethodMatches(src1, src2, CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview), kind: MethodKind.Regular);
var match = GetMethodMatches(src1, src2, kind: MethodKind.Regular);
var actual = ToMatchingPairs(match);
var expected = new MatchingPairs {
......@@ -1719,7 +1719,7 @@ public void PropertyPattern()
if (o is string { Length: 7 } s7) return 5;
";
var match = GetMethodMatches(src1, src2, CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview), kind: MethodKind.Regular);
var match = GetMethodMatches(src1, src2, kind: MethodKind.Regular);
var actual = ToMatchingPairs(match);
var expected = new MatchingPairs {
......@@ -1764,7 +1764,7 @@ public void RecursivePatterns()
};
";
var match = GetMethodMatches(src1, src2, CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.Preview), kind: MethodKind.Regular);
var match = GetMethodMatches(src1, src2, kind: MethodKind.Regular);
var actual = ToMatchingPairs(match);
var expected = new MatchingPairs {
......
......@@ -22,17 +22,11 @@ private CSharpSyntaxKindsService()
public override int LogicalOrExpression => (int)SyntaxKind.LogicalOrExpression;
public override int EndOfFileToken => (int)SyntaxKind.EndOfFileToken;
public override int AwaitKeyword => (int)SyntaxKind.AwaitKeyword;
public override int IdentifierToken => (int)SyntaxKind.IdentifierToken;
public override int GlobalKeyword => (int)SyntaxKind.GlobalKeyword;
public override int IncompleteMember => (int)SyntaxKind.IncompleteMember;
public override int UsingStatement => (int)SyntaxKind.UsingStatement;
public override int ReturnStatement => (int)SyntaxKind.ReturnStatement;
public override int HashToken => (int)SyntaxKind.HashToken;
}
}
......@@ -35,7 +35,7 @@ protected struct Indenter
(tk.LeadingTrivia.Any(tr => tr.IsDirective) || tk.TrailingTrivia.Any(tr => tr.IsDirective));
private readonly ISyntaxFactsService _syntaxFacts;
private readonly int TabSize;
private readonly int _tabSize;
public Indenter(
AbstractIndentationService<TSyntaxRoot> service,
......@@ -52,13 +52,13 @@ protected struct Indenter
this.OptionSet = optionSet;
this.Root = (TSyntaxRoot)document.Root;
this.LineToBeIndented = lineToBeIndented;
this.TabSize = this.OptionSet.GetOption(FormattingOptions.TabSize, Root.Language);
this._tabSize = this.OptionSet.GetOption(FormattingOptions.TabSize, Root.Language);
this.CancellationToken = cancellationToken;
this.Rules = rules;
this.Finder = new BottomUpBaseIndentationFinder(
new ChainedFormattingRules(this.Rules, OptionSet),
this.TabSize,
this._tabSize,
this.OptionSet.GetOption(FormattingOptions.IndentationSize, Root.Language),
tokenStream: null);
}
......
......@@ -44,7 +44,6 @@ internal abstract class AbstractSyntaxKindsService : ISyntaxKindsService
public abstract int LogicalAndExpression { get; }
public abstract int LogicalOrExpression { get; }
public abstract int EndOfFileToken { get; }
public abstract int IdentifierToken { get; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册