-
Notifications
You must be signed in to change notification settings - Fork 420
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
Omnisharp VS Code Issue 1814 Fix #1007
Changes from 5 commits
868c002
debcfec
71a318b
e74060a
f8e6896
94459ae
c33df39
cd8954f
978efe6
f7ac87b
ace2701
9a1e814
9445b4b
c91c3f0
fff464b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
|
||
|
||
namespace OmniSharp.Roslyn.CSharp.Services.Signatures | ||
{ | ||
internal class InvocationContext | ||
{ | ||
public SemanticModel SemanticModel { get; set; } | ||
public int Position { get; set; } | ||
public SyntaxNode Receiver { get; set; } | ||
public ArgumentListSyntax ArgumentList { get; set; } | ||
} | ||
public IEnumerable<TypeInfo> ArgumentTypes { get; set; } | ||
public IEnumerable<SyntaxToken> Separators { get; set; } | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blank line |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,7 @@ public async Task<SignatureHelpResponse> Handle(SignatureHelpRequest request) | |
var response = new SignatureHelpResponse(); | ||
|
||
// define active parameter by position | ||
foreach (var comma in invocations.First().ArgumentList.Arguments.GetSeparators()) | ||
foreach (var comma in invocations.First().Separators) | ||
{ | ||
if (comma.Span.Start > invocations.First().Position) | ||
{ | ||
|
@@ -58,9 +58,7 @@ public async Task<SignatureHelpResponse> Handle(SignatureHelpRequest request) | |
|
||
foreach (var invocation in invocations) | ||
{ | ||
var types = invocation.ArgumentList.Arguments | ||
.Select(argument => invocation.SemanticModel.GetTypeInfo(argument.Expression)); | ||
|
||
var types = invocation.ArgumentTypes; | ||
foreach (var methodOverload in GetMethodOverloads(invocation.SemanticModel, invocation.Receiver)) | ||
{ | ||
var signature = BuildSignature(methodOverload); | ||
|
@@ -74,7 +72,6 @@ public async Task<SignatureHelpResponse> Handle(SignatureHelpRequest request) | |
} | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leave this blank line here (the brace is followed by a statement). |
||
var signaturesList = signaturesSet.ToList(); | ||
response.Signatures = signaturesList; | ||
response.ActiveSignature = signaturesList.IndexOf(bestScoredItem); | ||
|
@@ -96,27 +93,42 @@ private async Task<InvocationContext> GetInvocation(Document document, Request r | |
var invocation = node as InvocationExpressionSyntax; | ||
if (invocation != null && invocation.ArgumentList.Span.Contains(position)) | ||
{ | ||
var semanticModel = await document.GetSemanticModelAsync(); | ||
return new InvocationContext() | ||
{ | ||
SemanticModel = await document.GetSemanticModelAsync(), | ||
SemanticModel = semanticModel, | ||
Position = position, | ||
Receiver = invocation.Expression, | ||
ArgumentList = invocation.ArgumentList | ||
ArgumentTypes = invocation.ArgumentList.Arguments.Select(argument => semanticModel.GetTypeInfo(argument.Expression)), | ||
Separators = invocation.ArgumentList.Arguments.GetSeparators() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as above |
||
}; | ||
} | ||
|
||
var objectCreation = node as ObjectCreationExpressionSyntax; | ||
if (objectCreation != null && objectCreation.ArgumentList.Span.Contains(position)) | ||
{ | ||
var semanticModel = await document.GetSemanticModelAsync(); | ||
return new InvocationContext() | ||
{ | ||
SemanticModel = await document.GetSemanticModelAsync(), | ||
SemanticModel = semanticModel, | ||
Position = position, | ||
Receiver = objectCreation, | ||
ArgumentList = objectCreation.ArgumentList | ||
ArgumentTypes = objectCreation.ArgumentList.Arguments.Select(argument => semanticModel.GetTypeInfo(argument.Expression)), | ||
Separators = objectCreation.ArgumentList.Arguments.GetSeparators() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here |
||
}; | ||
} | ||
var attributeSyntax = node as AttributeSyntax; | ||
if (attributeSyntax != null && attributeSyntax.ArgumentList.Span.Contains(position)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can make this a little cleaner by using a pattern match expression: |
||
{ | ||
var semanticModel = await document.GetSemanticModelAsync(); | ||
return new InvocationContext() | ||
{ | ||
SemanticModel = semanticModel, | ||
Position = position, | ||
Receiver = attributeSyntax, | ||
ArgumentTypes = attributeSyntax.ArgumentList.Arguments.Select(argument => semanticModel.GetTypeInfo(argument.Expression)), | ||
Separators = attributeSyntax.ArgumentList.Arguments.GetSeparators() | ||
}; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments as above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you avoid copying and pasting the same code multiple times? |
||
|
||
node = node.Parent; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't remove this line (the rule is to leave a blank line between a close brace and a statement). |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,7 +115,7 @@ public async Task TestForParameterLabels() | |
public static void Main(){ | ||
Foo($$); | ||
} | ||
pubic static Foo(bool b, int n = 1234) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol |
||
public static Foo(bool b, int n = 1234) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have we verified that this code was not intentionally invalid previously? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, didn't verify that. Should I revert it back to the previous state ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't think so. This doesn't look intentional to me based on the test name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should look at the test and decide whether the typo was intentional :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My guess, based on what's being tested, is that it was unintentional. |
||
{ | ||
} | ||
}"; | ||
|
@@ -152,6 +152,109 @@ private int Foo(int one, int two, int three) | |
Assert.Equal(0, actual.ActiveParameter); | ||
} | ||
|
||
[Fact] | ||
public async Task SignatureHelpforAttCtorSingleParam() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer that we not abbreviate "attribute". |
||
{ | ||
const string source = | ||
@"using System; | ||
[MyTest($$)] | ||
public class TestClass | ||
{ | ||
int value; | ||
|
||
public static void Main() | ||
{ | ||
var attributes= typeof(TestClass).CustomAttributes; | ||
foreach (var attribute in attributes) | ||
{ | ||
Console.WriteLine(attribute); | ||
} | ||
} | ||
void TestMethod(int value) | ||
{ | ||
this.value = value; | ||
} | ||
} | ||
public class MyTestAttribute : Attribute | ||
{ | ||
int value; | ||
public MyTestAttribute(int value) | ||
{ | ||
this.value = value; | ||
} | ||
}"; | ||
var actual = await GetSignatureHelp(source); | ||
Assert.Equal(0, actual.ActiveParameter); | ||
|
||
var signature = actual.Signatures.ElementAt(0); | ||
Assert.Single(signature.Parameters); | ||
Assert.Equal("value", signature.Parameters.ElementAt(0).Name); | ||
Assert.Equal("int value", signature.Parameters.ElementAt(0).Label); | ||
} | ||
[Fact] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing blank line before method. Should be between close brace and |
||
public async Task SignatureHelpforAttCtorMultipleParam() | ||
{ | ||
const string source = | ||
@"using System; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this pass? It doesn't look like there's a "$$" anywhere in the markup? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad, I see it. Anyway, it seems like the test is called "MultipleParam", but you're only testing in the first parameter position. |
||
[MyTest($$)] | ||
public class TestClass | ||
{ | ||
public static void Main() | ||
{ | ||
} | ||
} | ||
public class MyTestAttribute : Attribute | ||
{ | ||
int value1; | ||
double value2; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove these. |
||
public MyTestAttribute(int value1,double value2) | ||
{ | ||
this.value1 = value1; | ||
this.value2 = value2; | ||
} | ||
} | ||
"; | ||
var actual = await GetSignatureHelp(source); | ||
Assert.Equal(0, actual.ActiveParameter); | ||
|
||
var signature = actual.Signatures.ElementAt(0); | ||
Assert.Equal(2, signature.Parameters.Count()); | ||
Assert.Equal("value1", signature.Parameters.ElementAt(0).Name); | ||
Assert.Equal("int value1", signature.Parameters.ElementAt(0).Label); | ||
Assert.Equal("value2", signature.Parameters.ElementAt(1).Name); | ||
Assert.Equal("double value2", signature.Parameters.ElementAt(1).Label); | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unnecessary blank line |
||
[Fact] | ||
public async Task SignatureHelpforAttCtorNoParam() | ||
{ | ||
const string source = | ||
@"using System; | ||
[MyTest($$)] | ||
public class TestClass | ||
{ | ||
public static void Main() | ||
{ | ||
} | ||
} | ||
public class MyTestAttribute : Attribute | ||
{ | ||
int value1; | ||
double value2; | ||
public MyTestAttribute() | ||
{ | ||
this.value1 = 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can delete all the "value1" and "value2" related stuff since this test doesn't use them. |
||
this.value2 = 2; | ||
} | ||
}"; | ||
var actual = await GetSignatureHelp(source); | ||
Assert.Single(actual.Signatures); | ||
Assert.Equal(0, actual.ActiveParameter); | ||
Assert.Equal(0, actual.ActiveSignature); | ||
Assert.Equal("MyTestAttribute", actual.Signatures.ElementAt(0).Name); | ||
Assert.Empty(actual.Signatures.ElementAt(0).Parameters); | ||
} | ||
|
||
[Fact] | ||
public async Task ActiveParameterIsBasedOnComma2() | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not your fault, but do these properties actually need to be mutable? Can we have them be get-only?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes , it works with get-only.