-
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 2 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,21 @@ | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using System.Collections.Generic; | ||
|
||
namespace OmniSharp.Roslyn.CSharp.Services.Signatures | ||
{ | ||
|
||
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 lines 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. lots of extra whitespace here. |
||
|
||
internal class InvocationContext | ||
{ | ||
public SemanticModel SemanticModel { get; set; } | ||
public int Position { 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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yes , it works with get-only. |
||
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 lines |
||
|
||
} | ||
|
||
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,8 +58,9 @@ 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; | ||
|
||
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 empty lines |
||
|
||
|
||
foreach (var methodOverload in GetMethodOverloads(invocation.SemanticModel, invocation.Receiver)) | ||
{ | ||
|
@@ -96,27 +97,43 @@ private async Task<InvocationContext> GetInvocation(Document document, Request r | |
var invocation = node as InvocationExpressionSyntax; | ||
if (invocation != null && invocation.ArgumentList.Span.Contains(position)) | ||
{ | ||
var i = await document.GetSemanticModelAsync(); | ||
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. probably give 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. Call this 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. unused? |
||
return new InvocationContext() | ||
{ | ||
SemanticModel = await document.GetSemanticModelAsync(), | ||
Position = position, | ||
Receiver = invocation.Expression, | ||
ArgumentList = invocation.ArgumentList | ||
ArgumentTypes = invocation.ArgumentList.Arguments.Select(argument => i.GetTypeInfo(argument.Expression)), | ||
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. Is the expression here getting complex enough to extract into a local? |
||
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 i = await document.GetSemanticModelAsync(); | ||
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.
|
||
return new InvocationContext() | ||
{ | ||
SemanticModel = await document.GetSemanticModelAsync(), | ||
SemanticModel = i, | ||
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. Oh, I see--can you make this consistent with above, either with "i" or just calling GetSemanticModel? 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. Also "i" is probably not the best name :) |
||
Position = position, | ||
Receiver = objectCreation, | ||
ArgumentList = objectCreation.ArgumentList | ||
ArgumentTypes = objectCreation.ArgumentList.Arguments.Select(argument => i.GetTypeInfo(argument.Expression)), | ||
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 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. @akshita31 we can extract this logic into an extension method or a private function. 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'd consider adding two constructor overloads to InvocationContext which will deal with this initialization. If we want to keep InvocationContext a POCO [Plain Old C# Object] then we can put this logic into a factory method instead. I don't have a strong preference. |
||
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 i = await document.GetSemanticModelAsync(); | ||
return new InvocationContext() | ||
{ | ||
SemanticModel = i, | ||
Position = position, | ||
Receiver = attributeSyntax, | ||
ArgumentTypes = attributeSyntax.ArgumentList.Arguments.Select(argument => i.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 |
---|---|---|
|
@@ -153,6 +153,7 @@ private async Task<IEnumerable<ISymbol>> FindImplementationsAsync(string code, s | |
} | ||
} | ||
|
||
|
||
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. Extra whitespace 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 |
||
private async Task<IEnumerable<ISymbol>> SymbolsFromQuickFixesAsync(OmniSharpWorkspace workspace, IEnumerable<QuickFix> quickFixes) | ||
{ | ||
var symbols = new List<ISymbol>(); | ||
|
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,42 @@ private int Foo(int one, int two, int three) | |
Assert.Equal(0, actual.ActiveParameter); | ||
} | ||
|
||
[Fact] | ||
public async Task AttributeConstructorSignatureHelp() | ||
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. What about the second parameter, or if there aren't any? 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. @rchande the tests for signatures in Constructor/Method invocations cover a bunch of scenarios. Is this single test sufficient to cover attribute signatures? 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. @akshita31 the test name here seems misaligned with the names of other tests in this file. Since we're replicating a test behavior in a new syntax node, can you align the test names between this and constructor/method signatures? 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 was confused by the "1st position" comment, but looks like there is plenty of other coverage. |
||
{ | ||
// 1st position, a | ||
const string source = | ||
@"using System; | ||
|
||
namespace New_folder | ||
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. Can you align the quoted string to the left margin? Makes it easier to tell what the test contents are |
||
{ | ||
using System; | ||
[MyTest($$)] | ||
public class TestClass { | ||
int value; | ||
public static void Main(){ | ||
} | ||
void TestMethod(int value){ | ||
this.value = value; | ||
} | ||
public class MyTestAttribute : Attribute { | ||
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. newline here 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. C# code typically puts opening |
||
int value; | ||
public MyTestAttribute(int value) | ||
{ | ||
this.value =value; | ||
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. please add a space between |
||
} | ||
} | ||
}"; | ||
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); | ||
|
||
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 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.
nit: System namespaces should be sorted on top.