提交 46e069ae 编写于 作者: C CyrusNajmabadi

Place caret in parameter list when generating constructors.

上级 9e67e472
...@@ -33,7 +33,7 @@ class Z ...@@ -33,7 +33,7 @@ class Z
{ {
int a; int a;
public Z(int a) public Z(int a{|Navigation:)|}
{ {
this.a = a; this.a = a;
} }
...@@ -56,7 +56,7 @@ class Z ...@@ -56,7 +56,7 @@ class Z
{ {
int a; int a;
public Z(int a) => this . a = a ; public Z(int a{|Navigation:)|} => this . a = a ;
}", }",
options: Option(CSharpCodeStyleOptions.PreferExpressionBodiedConstructors, CSharpCodeStyleOptions.WhenPossibleWithNoneEnforcement)); options: Option(CSharpCodeStyleOptions.PreferExpressionBodiedConstructors, CSharpCodeStyleOptions.WhenPossibleWithNoneEnforcement));
} }
...@@ -77,7 +77,7 @@ class Z ...@@ -77,7 +77,7 @@ class Z
{ {
int a; int a;
public Z(int a) => this . a = a ; public Z(int a{|Navigation:)|} => this . a = a ;
}", }",
options: Option(CSharpCodeStyleOptions.PreferExpressionBodiedConstructors, CSharpCodeStyleOptions.WhenOnSingleLineWithNoneEnforcement)); options: Option(CSharpCodeStyleOptions.PreferExpressionBodiedConstructors, CSharpCodeStyleOptions.WhenOnSingleLineWithNoneEnforcement));
} }
...@@ -100,7 +100,7 @@ class Z ...@@ -100,7 +100,7 @@ class Z
int a; int a;
int b; int b;
public Z(int a, int b) public Z(int a, int b{|Navigation:)|}
{ {
this . a = a ; this . a = a ;
this . b = b ; this . b = b ;
...@@ -127,7 +127,7 @@ class Z ...@@ -127,7 +127,7 @@ class Z
int a; int a;
string b; string b;
public Z(int a, string b) public Z(int a, string b{|Navigation:)|}
{ {
this.a = a; this.a = a;
this.b = b; this.b = b;
...@@ -163,7 +163,7 @@ public Z(int a) ...@@ -163,7 +163,7 @@ public Z(int a)
this.a = a; this.a = a;
} }
public Z(string b) public Z(string b{|Navigation:)|}
{ {
this.b = b; this.b = b;
} }
...@@ -198,7 +198,7 @@ public Z(int a) ...@@ -198,7 +198,7 @@ public Z(int a)
this.a = a; this.a = a;
} }
public Z(int a, string b) public Z(int a, string b{|Navigation:)|}
{ {
this.a = a; this.a = a;
this.b = b; this.b = b;
...@@ -234,7 +234,7 @@ public Z(int a) ...@@ -234,7 +234,7 @@ public Z(int a)
this.a = a; this.a = a;
} }
public Z(int a, string b) public Z(int a, string b{|Navigation:)|}
{ {
this.a = a; this.a = a;
this.b = b; this.b = b;
...@@ -270,7 +270,7 @@ public Z(int a) ...@@ -270,7 +270,7 @@ public Z(int a)
this.a = a; this.a = a;
} }
public Z(int a, string b) : this(a) public Z(int a, string b{|Navigation:)|} : this(a)
{ {
this.b = b; this.b = b;
} }
...@@ -294,7 +294,7 @@ public Z(int a) ...@@ -294,7 +294,7 @@ public Z(int a)
this.a = a; this.a = a;
} }
public Z(int a, string b) public Z(int a, string b{|Navigation:)|}
{ {
this.a = a; this.a = a;
this.b = b; this.b = b;
...@@ -313,7 +313,7 @@ public async Task TestMultipleProperties() ...@@ -313,7 +313,7 @@ public async Task TestMultipleProperties()
}", }",
@"class Z @"class Z
{ {
public Z(int a, string b) public Z(int a, string b{|Navigation:)|}
{ {
A = a; A = a;
B = b; B = b;
...@@ -335,7 +335,7 @@ public async Task TestMultiplePropertiesWithQualification() ...@@ -335,7 +335,7 @@ public async Task TestMultiplePropertiesWithQualification()
}", }",
@"class Z @"class Z
{ {
public Z(int a, string b) public Z(int a, string b{|Navigation:)|}
{ {
this.A = a; this.A = a;
this.B = b; this.B = b;
...@@ -362,7 +362,7 @@ struct S ...@@ -362,7 +362,7 @@ struct S
{ {
int i; int i;
public S(int i) public S(int i{|Navigation:)|}
{ {
this.i = i; this.i = i;
} }
...@@ -383,7 +383,7 @@ struct S ...@@ -383,7 +383,7 @@ struct S
struct S struct S
{ {
public S(int i) : this() public S(int i{|Navigation:)|} : this()
{ {
this.i = i; this.i = i;
} }
...@@ -412,7 +412,7 @@ struct S ...@@ -412,7 +412,7 @@ struct S
int y; int y;
public S(int y) : this() public S(int y{|Navigation:)|} : this()
{ {
this.y = y; this.y = y;
} }
...@@ -439,7 +439,7 @@ struct S ...@@ -439,7 +439,7 @@ struct S
int y; int y;
public S(int i) : this() public S(int i{|Navigation:)|} : this()
{ {
this.i = i; this.i = i;
} }
...@@ -462,7 +462,7 @@ class Program<T> ...@@ -462,7 +462,7 @@ class Program<T>
{ {
int i; int i;
public Program(int i) public Program(int i{|Navigation:)|}
{ {
this.i = i; this.i = i;
} }
...@@ -534,7 +534,7 @@ public async Task TestContextualKeywordName() ...@@ -534,7 +534,7 @@ public async Task TestContextualKeywordName()
{ {
int yield; int yield;
public Program(int yield) public Program(int yield{|Navigation:)|}
{ {
this.yield = yield; this.yield = yield;
} }
...@@ -577,7 +577,7 @@ class Z ...@@ -577,7 +577,7 @@ class Z
{ {
(int, string) a; (int, string) a;
public Z((int, string) a) public Z((int, string) a{|Navigation:)|}
{ {
this.a = a; this.a = a;
} }
...@@ -597,7 +597,7 @@ public async Task TestUnderscoreInName1() ...@@ -597,7 +597,7 @@ public async Task TestUnderscoreInName1()
{ {
int _field; int _field;
public Program(int field) public Program(int field{|Navigation:)|}
{ {
_field = field; _field = field;
} }
...@@ -617,7 +617,7 @@ public async Task TestUnderscoreInName_PreferThis() ...@@ -617,7 +617,7 @@ public async Task TestUnderscoreInName_PreferThis()
{ {
int _field; int _field;
public Program(int field) public Program(int field{|Navigation:)|}
{ {
this._field = field; this._field = field;
} }
...@@ -637,7 +637,7 @@ public async Task TestGetter_Only_Auto_Props() ...@@ -637,7 +637,7 @@ public async Task TestGetter_Only_Auto_Props()
}", }",
@"abstract class Contribution @"abstract class Contribution
{ {
public Contribution(string title, int number) public Contribution(string title, int number{|Navigation:)|}
{ {
Title = title; Title = title;
Number = number; Number = number;
...@@ -679,7 +679,7 @@ class Z ...@@ -679,7 +679,7 @@ class Z
{ {
int a; int a;
public Z(int a) public Z(int a{|Navigation:)|}
{ {
this.a = a; this.a = a;
} }
...@@ -703,7 +703,7 @@ class Z ...@@ -703,7 +703,7 @@ class Z
{ {
int a; int a;
public Z(int a) public Z(int a{|Navigation:)|}
{ {
this.a = a; this.a = a;
} }
...@@ -741,7 +741,7 @@ class Z ...@@ -741,7 +741,7 @@ class Z
{ {
int a; int a;
public Z() public Z({|Navigation:)|}
{ {
} }
}", }",
...@@ -767,7 +767,7 @@ class Z ...@@ -767,7 +767,7 @@ class Z
int a; int a;
string b; string b;
public Z(string b, int a) public Z(string b, int a{|Navigation:)|}
{ {
this.b = b; this.b = b;
this.a = a; this.a = a;
...@@ -799,7 +799,7 @@ class Z ...@@ -799,7 +799,7 @@ class Z
int a; int a;
string b; string b;
public Z(int a, string b) public Z(int a, string b{|Navigation:)|}
{ {
this.a = a; this.a = a;
this.b = b ?? throw new ArgumentNullException(nameof(b)); this.b = b ?? throw new ArgumentNullException(nameof(b));
...@@ -832,7 +832,7 @@ class Z ...@@ -832,7 +832,7 @@ class Z
int a; int a;
string b; string b;
public Z(int a, string b) public Z(int a, string b{|Navigation:)|}
{ {
if (b == null) if (b == null)
{ {
...@@ -897,6 +897,30 @@ public void M() ...@@ -897,6 +897,30 @@ public void M()
} }
public void N() { } public void N() { }
}");
}
[WorkItem(21067, "https://github.com/dotnet/roslyn/pull/21067")]
[Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateConstructorFromMembers)]
public async Task TestFinalCaretPosition()
{
await TestInRegularAndScriptAsync(
@"using System.Collections.Generic;
class Z
{
[|int a;|]
}",
@"using System.Collections.Generic;
class Z
{
int a;
public Z(int a{|Navigation:)|}
{
this.a = a;
}
}"); }");
} }
} }
......
...@@ -176,7 +176,7 @@ internal class CodeActionEditHandlerService : ForegroundThreadAffinitizedObject, ...@@ -176,7 +176,7 @@ internal class CodeActionEditHandlerService : ForegroundThreadAffinitizedObject,
} }
var updatedSolution = operations.OfType<ApplyChangesOperation>().FirstOrDefault()?.ChangedSolution ?? oldSolution; var updatedSolution = operations.OfType<ApplyChangesOperation>().FirstOrDefault()?.ChangedSolution ?? oldSolution;
TryStartRenameSession(workspace, oldSolution, updatedSolution, cancellationToken); TryNavigateToLocationOrStartRenameSession(workspace, oldSolution, updatedSolution, cancellationToken);
} }
private TextDocument TryGetSingleChangedText( private TextDocument TryGetSingleChangedText(
...@@ -259,7 +259,7 @@ internal class CodeActionEditHandlerService : ForegroundThreadAffinitizedObject, ...@@ -259,7 +259,7 @@ internal class CodeActionEditHandlerService : ForegroundThreadAffinitizedObject,
} }
} }
private void TryStartRenameSession(Workspace workspace, Solution oldSolution, Solution newSolution, CancellationToken cancellationToken) private void TryNavigateToLocationOrStartRenameSession(Workspace workspace, Solution oldSolution, Solution newSolution, CancellationToken cancellationToken)
{ {
var changedDocuments = newSolution.GetChangedDocuments(oldSolution); var changedDocuments = newSolution.GetChangedDocuments(oldSolution);
foreach (var documentId in changedDocuments) foreach (var documentId in changedDocuments)
...@@ -272,9 +272,16 @@ private void TryStartRenameSession(Workspace workspace, Solution oldSolution, So ...@@ -272,9 +272,16 @@ private void TryStartRenameSession(Workspace workspace, Solution oldSolution, So
var root = document.GetSyntaxRootSynchronously(cancellationToken); var root = document.GetSyntaxRootSynchronously(cancellationToken);
var renameTokenOpt = root.GetAnnotatedNodesAndTokens(RenameAnnotation.Kind) var navigationTokenOpt = root.GetAnnotatedTokens(NavigationAnnotation.Kind)
.Where(s => s.IsToken) .FirstOrNullable();
.Select(s => s.AsToken()) if (navigationTokenOpt.HasValue)
{
var navigationService = workspace.Services.GetService<IDocumentNavigationService>();
navigationService.TryNavigateToPosition(workspace, documentId, navigationTokenOpt.Value.SpanStart);
return;
}
var renameTokenOpt = root.GetAnnotatedTokens(RenameAnnotation.Kind)
.FirstOrNullable(); .FirstOrNullable();
if (renameTokenOpt.HasValue) if (renameTokenOpt.HasValue)
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.ChangeSignature; using Microsoft.CodeAnalysis.ChangeSignature;
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions; using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Notification; using Microsoft.CodeAnalysis.Notification;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities; using Roslyn.Utilities;
using Xunit; using Xunit;
...@@ -39,9 +40,11 @@ protected override ParseOptions GetScriptOptions() ...@@ -39,9 +40,11 @@ protected override ParseOptions GetScriptOptions()
var codeIssueOrRefactoring = await GetCodeRefactoringAsync(workspace, testOptions); var codeIssueOrRefactoring = await GetCodeRefactoringAsync(workspace, testOptions);
await TestActionsAsync(workspace, expectedCode, index, codeIssueOrRefactoring.Actions, await TestActionsAsync(workspace, expectedCode, index, codeIssueOrRefactoring.Actions,
conflictSpans: ImmutableArray<Text.TextSpan>.Empty, conflictSpans: ImmutableArray<TextSpan>.Empty,
renameSpans: ImmutableArray<Text.TextSpan>.Empty, renameSpans: ImmutableArray<TextSpan>.Empty,
warningSpans: ImmutableArray<Text.TextSpan>.Empty, ignoreTrivia: true); warningSpans: ImmutableArray<TextSpan>.Empty,
navigationSpans: ImmutableArray<TextSpan>.Empty,
ignoreTrivia: true);
} }
} }
else else
......
...@@ -364,11 +364,13 @@ public TestParameters WithFixProviderData(object fixProviderData) ...@@ -364,11 +364,13 @@ public TestParameters WithFixProviderData(object fixProviderData)
TestParameters parameters) TestParameters parameters)
{ {
MarkupTestFile.GetSpans( MarkupTestFile.GetSpans(
expectedMarkup.NormalizeLineEndings(), out var expected, out IDictionary<string, ImmutableArray<TextSpan>> spanMap); expectedMarkup.NormalizeLineEndings(),
out var expected, out IDictionary<string, ImmutableArray<TextSpan>> spanMap);
var conflictSpans = spanMap.GetOrAdd("Conflict", _ => ImmutableArray<TextSpan>.Empty); var conflictSpans = spanMap.GetOrAdd("Conflict", _ => ImmutableArray<TextSpan>.Empty);
var renameSpans = spanMap.GetOrAdd("Rename", _ => ImmutableArray<TextSpan>.Empty); var renameSpans = spanMap.GetOrAdd("Rename", _ => ImmutableArray<TextSpan>.Empty);
var warningSpans = spanMap.GetOrAdd("Warning", _ => ImmutableArray<TextSpan>.Empty); var warningSpans = spanMap.GetOrAdd("Warning", _ => ImmutableArray<TextSpan>.Empty);
var navigationSpans = spanMap.GetOrAdd("Navigation", _ => ImmutableArray<TextSpan>.Empty);
using (var workspace = CreateWorkspaceFromOptions(initialMarkup, parameters)) using (var workspace = CreateWorkspaceFromOptions(initialMarkup, parameters))
{ {
...@@ -380,7 +382,7 @@ public TestParameters WithFixProviderData(object fixProviderData) ...@@ -380,7 +382,7 @@ public TestParameters WithFixProviderData(object fixProviderData)
await TestActionsAsync( await TestActionsAsync(
workspace, expected, index, workspace, expected, index,
actions, actions,
conflictSpans, renameSpans, warningSpans, conflictSpans, renameSpans, warningSpans, navigationSpans,
ignoreTrivia: ignoreTrivia, ignoreTrivia: ignoreTrivia,
parseOptions: parameters.parseOptions, parseOptions: parameters.parseOptions,
priority: priority); priority: priority);
...@@ -393,12 +395,15 @@ public TestParameters WithFixProviderData(object fixProviderData) ...@@ -393,12 +395,15 @@ public TestParameters WithFixProviderData(object fixProviderData)
ImmutableArray<TextSpan> conflictSpans, ImmutableArray<TextSpan> conflictSpans,
ImmutableArray<TextSpan> renameSpans, ImmutableArray<TextSpan> renameSpans,
ImmutableArray<TextSpan> warningSpans, ImmutableArray<TextSpan> warningSpans,
ImmutableArray<TextSpan> navigationSpans,
bool ignoreTrivia, bool ignoreTrivia,
ParseOptions parseOptions = null, ParseOptions parseOptions = null,
CodeActionPriority? priority = null) CodeActionPriority? priority = null)
{ {
var operations = await VerifyInputsAndGetOperationsAsync(index, actions, priority); var operations = await VerifyInputsAndGetOperationsAsync(index, actions, priority);
return await TestOperationsAsync(workspace, expected, operations, conflictSpans, renameSpans, warningSpans, ignoreTrivia, expectedChangedDocumentId: null, parseOptions: parseOptions); return await TestOperationsAsync(
workspace, expected, operations, conflictSpans, renameSpans,
warningSpans, navigationSpans, ignoreTrivia, expectedChangedDocumentId: null, parseOptions: parseOptions);
} }
protected async Task<Tuple<Solution, Solution>> TestOperationsAsync( protected async Task<Tuple<Solution, Solution>> TestOperationsAsync(
...@@ -408,6 +413,7 @@ public TestParameters WithFixProviderData(object fixProviderData) ...@@ -408,6 +413,7 @@ public TestParameters WithFixProviderData(object fixProviderData)
ImmutableArray<TextSpan> conflictSpans, ImmutableArray<TextSpan> conflictSpans,
ImmutableArray<TextSpan> renameSpans, ImmutableArray<TextSpan> renameSpans,
ImmutableArray<TextSpan> warningSpans, ImmutableArray<TextSpan> warningSpans,
ImmutableArray<TextSpan> navigationSpans,
bool ignoreTrivia, bool ignoreTrivia,
DocumentId expectedChangedDocumentId, DocumentId expectedChangedDocumentId,
ParseOptions parseOptions = null) ParseOptions parseOptions = null)
...@@ -439,6 +445,7 @@ public TestParameters WithFixProviderData(object fixProviderData) ...@@ -439,6 +445,7 @@ public TestParameters WithFixProviderData(object fixProviderData)
TestAnnotations(conflictSpans, ConflictAnnotation.Kind); TestAnnotations(conflictSpans, ConflictAnnotation.Kind);
TestAnnotations(renameSpans, RenameAnnotation.Kind); TestAnnotations(renameSpans, RenameAnnotation.Kind);
TestAnnotations(warningSpans, WarningAnnotation.Kind); TestAnnotations(warningSpans, WarningAnnotation.Kind);
TestAnnotations(navigationSpans, NavigationAnnotation.Kind);
return Tuple.Create(oldSolution, newSolution); return Tuple.Create(oldSolution, newSolution);
......
...@@ -372,6 +372,7 @@ protected Document GetDocumentAndAnnotatedSpan(TestWorkspace workspace, out stri ...@@ -372,6 +372,7 @@ protected Document GetDocumentAndAnnotatedSpan(TestWorkspace workspace, out stri
conflictSpans: ImmutableArray<TextSpan>.Empty, conflictSpans: ImmutableArray<TextSpan>.Empty,
renameSpans: ImmutableArray<TextSpan>.Empty, renameSpans: ImmutableArray<TextSpan>.Empty,
warningSpans: ImmutableArray<TextSpan>.Empty, warningSpans: ImmutableArray<TextSpan>.Empty,
navigationSpans: ImmutableArray<TextSpan>.Empty,
ignoreTrivia: false, expectedChangedDocumentId: testState.ExistingDocument.Id); ignoreTrivia: false, expectedChangedDocumentId: testState.ExistingDocument.Id);
} }
else else
...@@ -393,7 +394,9 @@ protected Document GetDocumentAndAnnotatedSpan(TestWorkspace workspace, out stri ...@@ -393,7 +394,9 @@ protected Document GetDocumentAndAnnotatedSpan(TestWorkspace workspace, out stri
await TestOperationsAsync(testState.Workspace, expectedTextWithUsings, operations, await TestOperationsAsync(testState.Workspace, expectedTextWithUsings, operations,
conflictSpans: ImmutableArray<TextSpan>.Empty, conflictSpans: ImmutableArray<TextSpan>.Empty,
renameSpans: ImmutableArray<TextSpan>.Empty, renameSpans: ImmutableArray<TextSpan>.Empty,
warningSpans: ImmutableArray<TextSpan>.Empty, ignoreTrivia: false, warningSpans: ImmutableArray<TextSpan>.Empty,
navigationSpans: ImmutableArray<TextSpan>.Empty,
ignoreTrivia: false,
expectedChangedDocumentId: testState.InvocationDocument.Id); expectedChangedDocumentId: testState.InvocationDocument.Id);
} }
......
...@@ -137,6 +137,7 @@ protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspa ...@@ -137,6 +137,7 @@ protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspa
conflictSpans: ImmutableArray<TextSpan>.Empty, conflictSpans: ImmutableArray<TextSpan>.Empty,
renameSpans: ImmutableArray<TextSpan>.Empty, renameSpans: ImmutableArray<TextSpan>.Empty,
warningSpans: ImmutableArray<TextSpan>.Empty, warningSpans: ImmutableArray<TextSpan>.Empty,
navigationSpans: ImmutableArray<TextSpan>.Empty,
ignoreTrivia: ignoreTrivia, ignoreTrivia: ignoreTrivia,
expectedChangedDocumentId: null); expectedChangedDocumentId: null);
} }
......
...@@ -21,7 +21,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.GenerateConstructo ...@@ -21,7 +21,7 @@ Namespace Microsoft.CodeAnalysis.Editor.VisualBasic.UnitTests.GenerateConstructo
End Class", End Class",
"Class Program "Class Program
Private i As Integer Private i As Integer
Public Sub New(i As Integer) Public Sub New(i As Integer{|Navigation:)|}
Me.i = i Me.i = i
End Sub End Sub
End Class") End Class")
...@@ -37,7 +37,7 @@ End Class", ...@@ -37,7 +37,7 @@ End Class",
"Class Program "Class Program
Private i As Integer Private i As Integer
Private b As String Private b As String
Public Sub New(i As Integer, b As String) Public Sub New(i As Integer, b As String{|Navigation:)|}
Me.i = i Me.i = i
Me.b = b Me.b = b
End Sub End Sub
...@@ -60,7 +60,7 @@ End Class", ...@@ -60,7 +60,7 @@ End Class",
Public Sub New(i As Integer) Public Sub New(i As Integer)
Me.i = i Me.i = i
End Sub End Sub
Public Sub New(b As String) Public Sub New(b As String{|Navigation:)|}
Me.b = b Me.b = b
End Sub End Sub
End Class") End Class")
...@@ -82,7 +82,7 @@ End Class", ...@@ -82,7 +82,7 @@ End Class",
Public Sub New(i As Integer) Public Sub New(i As Integer)
Me.i = i Me.i = i
End Sub End Sub
Public Sub New(i As Integer, b As String) Public Sub New(i As Integer, b As String{|Navigation:)|}
Me.i = i Me.i = i
Me.b = b Me.b = b
End Sub End Sub
...@@ -113,7 +113,7 @@ End Class") ...@@ -113,7 +113,7 @@ End Class")
End Structure", End Structure",
"Structure S "Structure S
Private i As Integer Private i As Integer
Public Sub New(i As Integer) Public Sub New(i As Integer{|Navigation:)|}
Me.i = i Me.i = i
End Sub End Sub
End Structure") End Structure")
...@@ -127,7 +127,7 @@ End Structure") ...@@ -127,7 +127,7 @@ End Structure")
End Class", End Class",
"Class Program(Of T) "Class Program(Of T)
Private i As Integer Private i As Integer
Public Sub New(i As Integer) Public Sub New(i As Integer{|Navigation:)|}
Me.i = i Me.i = i
End Sub End Sub
End Class") End Class")
...@@ -150,7 +150,7 @@ End Class", ...@@ -150,7 +150,7 @@ End Class",
Public Sub New(i As Integer) Public Sub New(i As Integer)
Me.i = i Me.i = i
End Sub End Sub
Public Sub New(i As Integer, b As String) Public Sub New(i As Integer, b As String{|Navigation:)|}
Me.New(i) Me.New(i)
Me.b = b Me.b = b
End Sub End Sub
...@@ -167,7 +167,7 @@ index:=1) ...@@ -167,7 +167,7 @@ index:=1)
Public Property B As String|] Public Property B As String|]
End Class", End Class",
"Class Z "Class Z
Public Sub New(a As Integer, b As String) Public Sub New(a As Integer, b As String{|Navigation:)|}
Me.A = a Me.A = a
Me.B = b Me.B = b
End Sub End Sub
...@@ -185,7 +185,7 @@ End Class") ...@@ -185,7 +185,7 @@ End Class")
ReadOnly Property Number As Integer|] ReadOnly Property Number As Integer|]
End Class", End Class",
"Class Contribution "Class Contribution
Public Sub New(title As String, number As Integer) Public Sub New(title As String, number As Integer{|Navigation:)|}
Me.Title = title Me.Title = title
Me.Number = number Me.Number = number
End Sub End Sub
...@@ -214,7 +214,7 @@ End Class") ...@@ -214,7 +214,7 @@ End Class")
End Class", End Class",
"Class Program "Class Program
Private i As Integer Private i As Integer
Public Sub New(i As Integer) Public Sub New(i As Integer{|Navigation:)|}
Me.i = i Me.i = i
End Sub End Sub
End Class", chosenSymbols:={"i"}) End Class", chosenSymbols:={"i"})
...@@ -229,7 +229,7 @@ End Class", chosenSymbols:={"i"}) ...@@ -229,7 +229,7 @@ End Class", chosenSymbols:={"i"})
End Class", End Class",
"Class Program "Class Program
Private i As Integer Private i As Integer
Public Sub New() Public Sub New({|Navigation:)|}
End Sub End Sub
End Class", chosenSymbols:={}) End Class", chosenSymbols:={})
End Function End Function
...@@ -245,7 +245,7 @@ End Class", ...@@ -245,7 +245,7 @@ End Class",
"Class Program "Class Program
Private i As Integer Private i As Integer
Private j As String Private j As String
Public Sub New(j As String, i As Integer) Public Sub New(j As String, i As Integer{|Navigation:)|}
Me.j = j Me.j = j
Me.i = i Me.i = i
End Sub End Sub
...@@ -260,7 +260,7 @@ End Class", chosenSymbols:={"j", "i"}) ...@@ -260,7 +260,7 @@ End Class", chosenSymbols:={"j", "i"})
End Class", End Class",
"Class Program "Class Program
Private i As Integer Private i As Integer
Public Sub New(i As Integer) Public Sub New(i As Integer{|Navigation:)|}
Me.i = i Me.i = i
End Sub End Sub
End Class", chosenSymbols:={"i"}) End Class", chosenSymbols:={"i"})
......
...@@ -103,7 +103,7 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke ...@@ -103,7 +103,7 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
afterThisLocation: afterThisLocation), afterThisLocation: afterThisLocation),
cancellationToken: cancellationToken).ConfigureAwait(false); cancellationToken: cancellationToken).ConfigureAwait(false);
return result; return await AddNavigationAnnotationAsync(result, cancellationToken).ConfigureAwait(false);
} }
public override string Title public override string Title
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
...@@ -84,7 +85,7 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke ...@@ -84,7 +85,7 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
afterThisLocation: afterThisLocation), afterThisLocation: afterThisLocation),
cancellationToken).ConfigureAwait(false); cancellationToken).ConfigureAwait(false);
return result; return await AddNavigationAnnotationAsync(result, cancellationToken).ConfigureAwait(false);
} }
public override string Title public override string Title
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CodeActions; using Microsoft.CodeAnalysis.CodeActions;
using Microsoft.CodeAnalysis.CodeGeneration;
using Microsoft.CodeAnalysis.CodeRefactorings; using Microsoft.CodeAnalysis.CodeRefactorings;
using Microsoft.CodeAnalysis.GenerateFromMembers; using Microsoft.CodeAnalysis.GenerateFromMembers;
using Microsoft.CodeAnalysis.Internal.Log; using Microsoft.CodeAnalysis.Internal.Log;
...@@ -165,5 +166,26 @@ private ImmutableArray<CodeAction> GetCodeActions(Document document, State state ...@@ -165,5 +166,26 @@ private ImmutableArray<CodeAction> GetCodeActions(Document document, State state
return result.ToImmutableAndFree(); return result.ToImmutableAndFree();
} }
private static async Task<Document> AddNavigationAnnotationAsync(Document document, CancellationToken cancellationToken)
{
var root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);
var nodes = root.GetAnnotatedNodes(CodeGenerator.Annotation);
var syntaxFacts = document.GetLanguageService<ISyntaxFactsService>();
foreach (var node in nodes)
{
var parameterList = syntaxFacts.GetParameterList(node);
if (parameterList != null)
{
var closeParen = parameterList.GetLastToken();
var newRoot = root.ReplaceToken(closeParen, closeParen.WithAdditionalAnnotations(NavigationAnnotation.Create()));
return document.WithSyntaxRoot(newRoot);
}
}
return document;
}
} }
} }
...@@ -2610,7 +2610,7 @@ public override SyntaxToken VisitToken(SyntaxToken token) ...@@ -2610,7 +2610,7 @@ public override SyntaxToken VisitToken(SyntaxToken token)
} }
} }
private static BaseParameterListSyntax GetParameterList(SyntaxNode declaration) internal static BaseParameterListSyntax GetParameterList(SyntaxNode declaration)
{ {
switch (declaration.Kind()) switch (declaration.Kind())
{ {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using Microsoft.CodeAnalysis.Collections; using Microsoft.CodeAnalysis.Collections;
using Microsoft.CodeAnalysis.CSharp.CodeGeneration;
using Microsoft.CodeAnalysis.CSharp.Extensions; using Microsoft.CodeAnalysis.CSharp.Extensions;
using Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery; using Microsoft.CodeAnalysis.CSharp.Extensions.ContextQuery;
using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.CSharp.Syntax;
...@@ -207,6 +208,9 @@ public bool IsNamedParameter(SyntaxNode node) ...@@ -207,6 +208,9 @@ public bool IsNamedParameter(SyntaxNode node)
public SyntaxNode GetDefaultOfParameter(SyntaxNode node) public SyntaxNode GetDefaultOfParameter(SyntaxNode node)
=> (node as ParameterSyntax)?.Default; => (node as ParameterSyntax)?.Default;
public SyntaxNode GetParameterList(SyntaxNode node)
=> CSharpSyntaxGenerator.GetParameterList(node);
public bool IsSkippedTokensTrivia(SyntaxNode node) public bool IsSkippedTokensTrivia(SyntaxNode node)
{ {
return node is SkippedTokensTriviaSyntax; return node is SkippedTokensTriviaSyntax;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.CodeAnalysis.CodeActions namespace Microsoft.CodeAnalysis.CodeActions
{ {
/// <summary> /// <summary>
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.CodeAnalysis.CodeActions
{
/// <summary>
/// Apply this annotation to an appropriate Syntax element to request that it should be
/// navigated to by the user after the action.
/// </summary>
internal static class NavigationAnnotation
{
public const string Kind = "CodeAction_Navigation";
public static SyntaxAnnotation Create()
=> new SyntaxAnnotation(Kind);
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.CodeAnalysis.CodeActions namespace Microsoft.CodeAnalysis.CodeActions
{ {
/// <summary> /// <summary>
......
...@@ -49,7 +49,7 @@ public static TSyntaxNode AddAnnotationsTo<TSyntaxNode>(ISymbol symbol, TSyntaxN ...@@ -49,7 +49,7 @@ public static TSyntaxNode AddAnnotationsTo<TSyntaxNode>(ISymbol symbol, TSyntaxN
public static TSyntaxNode AddCleanupAnnotationsTo<TSyntaxNode>(TSyntaxNode node) where TSyntaxNode : SyntaxNode public static TSyntaxNode AddCleanupAnnotationsTo<TSyntaxNode>(TSyntaxNode node) where TSyntaxNode : SyntaxNode
{ {
return node.WithAdditionalAnnotations(Formatter.Annotation); return node.WithAdditionalAnnotations(Formatter.Annotation, CodeGenerator.Annotation);
} }
public static void CheckNodeType<TSyntaxNode1>(SyntaxNode node, string argumentName) public static void CheckNodeType<TSyntaxNode1>(SyntaxNode node, string argumentName)
...@@ -215,9 +215,9 @@ public static T GetReuseableSyntaxNodeForSymbol<T>(ISymbol symbol, CodeGeneratio ...@@ -215,9 +215,9 @@ public static T GetReuseableSyntaxNodeForSymbol<T>(ISymbol symbol, CodeGeneratio
{ {
Contract.ThrowIfNull(symbol); Contract.ThrowIfNull(symbol);
return options != null && options.ReuseSyntax && symbol.DeclaringSyntaxReferences.Length == 1 ? return options != null && options.ReuseSyntax && symbol.DeclaringSyntaxReferences.Length == 1
symbol.DeclaringSyntaxReferences[0].GetSyntax() as T : ? symbol.DeclaringSyntaxReferences[0].GetSyntax() as T
null; : null;
} }
public static T GetReuseableSyntaxNodeForAttribute<T>(AttributeData attribute, CodeGenerationOptions options) public static T GetReuseableSyntaxNodeForAttribute<T>(AttributeData attribute, CodeGenerationOptions options)
......
...@@ -11,6 +11,11 @@ namespace Microsoft.CodeAnalysis.CodeGeneration ...@@ -11,6 +11,11 @@ namespace Microsoft.CodeAnalysis.CodeGeneration
/// </summary> /// </summary>
internal static class CodeGenerator internal static class CodeGenerator
{ {
/// <summary>
/// Annotation placed on generated syntax.
/// </summary>
public static readonly SyntaxAnnotation Annotation = new SyntaxAnnotation(nameof(CodeGenerator));
private static ICodeGenerationService GetCodeGenerationService(Workspace workspace, string language) private static ICodeGenerationService GetCodeGenerationService(Workspace workspace, string language)
{ {
return workspace.Services.GetLanguageServices(language).GetService<ICodeGenerationService>(); return workspace.Services.GetLanguageServices(language).GetService<ICodeGenerationService>();
......
...@@ -132,6 +132,7 @@ internal interface ISyntaxFactsService : ILanguageService ...@@ -132,6 +132,7 @@ internal interface ISyntaxFactsService : ILanguageService
bool IsNamedParameter(SyntaxNode node); bool IsNamedParameter(SyntaxNode node);
SyntaxNode GetDefaultOfParameter(SyntaxNode node); SyntaxNode GetDefaultOfParameter(SyntaxNode node);
SyntaxNode GetParameterList(SyntaxNode node);
bool IsSkippedTokensTrivia(SyntaxNode node); bool IsSkippedTokensTrivia(SyntaxNode node);
......
...@@ -3063,7 +3063,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration ...@@ -3063,7 +3063,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
statement.CaseBlocks.InsertRange(index, switchSections.Cast(Of CaseBlockSyntax))) statement.CaseBlocks.InsertRange(index, switchSections.Cast(Of CaseBlockSyntax)))
End Function End Function
Private Function GetParameterList(declaration As SyntaxNode) As ParameterListSyntax Friend Shared Function GetParameterList(declaration As SyntaxNode) As ParameterListSyntax
Select Case declaration.Kind Select Case declaration.Kind
Case SyntaxKind.SubBlock, Case SyntaxKind.SubBlock,
SyntaxKind.FunctionBlock SyntaxKind.FunctionBlock
......
...@@ -10,6 +10,7 @@ Imports Microsoft.CodeAnalysis.Host.Mef ...@@ -10,6 +10,7 @@ Imports Microsoft.CodeAnalysis.Host.Mef
Imports Microsoft.CodeAnalysis.LanguageServices Imports Microsoft.CodeAnalysis.LanguageServices
Imports Microsoft.CodeAnalysis.PooledObjects Imports Microsoft.CodeAnalysis.PooledObjects
Imports Microsoft.CodeAnalysis.Text Imports Microsoft.CodeAnalysis.Text
Imports Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
Imports Microsoft.CodeAnalysis.VisualBasic.Extensions.ContextQuery Imports Microsoft.CodeAnalysis.VisualBasic.Extensions.ContextQuery
Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Imports Microsoft.CodeAnalysis.VisualBasic.Syntax
Imports Microsoft.CodeAnalysis.VisualBasic.SyntaxFacts Imports Microsoft.CodeAnalysis.VisualBasic.SyntaxFacts
...@@ -202,6 +203,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic ...@@ -202,6 +203,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return TryCast(node, ParameterSyntax)?.Default Return TryCast(node, ParameterSyntax)?.Default
End Function End Function
Public Function GetParameterList(node As SyntaxNode) As SyntaxNode Implements ISyntaxFactsService.GetParameterList
Return VisualBasicSyntaxGenerator.GetParameterList(node)
End Function
Public Function IsSkippedTokensTrivia(node As SyntaxNode) As Boolean Implements ISyntaxFactsService.IsSkippedTokensTrivia Public Function IsSkippedTokensTrivia(node As SyntaxNode) As Boolean Implements ISyntaxFactsService.IsSkippedTokensTrivia
Return TypeOf node Is SkippedTokensTriviaSyntax Return TypeOf node Is SkippedTokensTriviaSyntax
End Function End Function
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册