Skip to content
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

Merged
merged 15 commits into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions package-lock.json

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;
Copy link
Contributor

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.


namespace OmniSharp.Roslyn.CSharp.Services.Signatures
{

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank lines

Choose a reason for hiding this comment

The 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; }
Copy link

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?

Copy link
Contributor Author

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.

public SyntaxNode Receiver { get; set; }
public ArgumentListSyntax ArgumentList { get; set; }
public IEnumerable<TypeInfo> ArgumentTypes { get; set; }
public IEnumerable<SyntaxToken> Separators { get; set; }
}


Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank lines


}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blank line

Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary empty lines



foreach (var methodOverload in GetMethodOverloads(invocation.SemanticModel, invocation.Receiver))
{
Expand Down Expand Up @@ -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();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably give i a slightly better name.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call this semanticaModel and replace the call to await document.GetSemanticModelAsync() below with the variable as well. There's no need to call it twice.

Copy link

Choose a reason for hiding this comment

The 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)),
Copy link
Contributor

Choose a reason for hiding this comment

The 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()
Copy link
Contributor

Choose a reason for hiding this comment

The 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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

semanticModel rather than i

return new InvocationContext()
{
SemanticModel = await document.GetSemanticModelAsync(),
SemanticModel = i,
Copy link

Choose a reason for hiding this comment

The 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?

Copy link

Choose a reason for hiding this comment

The 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)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

The 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()
Copy link
Contributor

Choose a reason for hiding this comment

The 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))
Copy link

Choose a reason for hiding this comment

The 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:
if (node is AttributeSyntax attributeSyntax && attributeSyntax ... )

{
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()
};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as above.

Copy link
Contributor

Choose a reason for hiding this comment

The 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;
}

Copy link

Choose a reason for hiding this comment

The 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).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ private async Task<IEnumerable<ISymbol>> FindImplementationsAsync(string code, s
}
}


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra whitespace

Copy link

Choose a reason for hiding this comment

The 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>();
Expand Down
38 changes: 37 additions & 1 deletion tests/OmniSharp.Roslyn.CSharp.Tests/SignatureHelpFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public async Task TestForParameterLabels()
public static void Main(){
Foo($$);
}
pubic static Foo(bool b, int n = 1234)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

public static Foo(bool b, int n = 1234)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have we verified that this code was not intentionally invalid previously?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 ?

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link

Choose a reason for hiding this comment

The 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 :)

Copy link

Choose a reason for hiding this comment

The 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.

{
}
}";
Expand Down Expand Up @@ -152,6 +152,42 @@ private int Foo(int one, int two, int three)
Assert.Equal(0, actual.ActiveParameter);
}

[Fact]
public async Task AttributeConstructorSignatureHelp()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the second parameter, or if there aren't any?

Choose a reason for hiding this comment

The 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?

Choose a reason for hiding this comment

The 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?

Copy link

Choose a reason for hiding this comment

The 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
Copy link

Choose a reason for hiding this comment

The 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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

newline here

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C# code typically puts opening { on a new line. Consider using VS to format the document as this will get your style in-line with C#.

int value;
public MyTestAttribute(int value)
{
this.value =value;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a space between = and 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);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary blank line

}

[Fact]
public async Task ActiveParameterIsBasedOnComma2()
{
Expand Down