Skip to content

Fix FAR for less than operator and add tests for all operators#52656

Merged
CyrusNajmabadi merged 5 commits intodotnet:mainfrom
Youssef1313:patch-17
Apr 16, 2021
Merged

Fix FAR for less than operator and add tests for all operators#52656
CyrusNajmabadi merged 5 commits intodotnet:mainfrom
Youssef1313:patch-17

Conversation

@Youssef1313
Copy link
Member

@Youssef1313 Youssef1313 commented Apr 15, 2021

Fixes #52654
Closes #39177 (this was already partially working (the > part) - and this PR fixed the <)

@ghost ghost added the Area-IDE label Apr 15, 2021
@Youssef1313 Youssef1313 changed the title Draft Fix FAR for less than operator and add tests for all operators Apr 15, 2021
@Youssef1313 Youssef1313 marked this pull request as ready for review April 15, 2021 11:38
@Youssef1313 Youssef1313 requested a review from a team as a code owner April 15, 2021 11:38

var syntaxFacts = document.GetLanguageService<ISyntaxFactsService>();
if (syntaxFacts.IsOperator(token) || syntaxFacts.IsPredefinedOperator(token) || SyntaxFacts.IsAssignmentExpressionOperatorToken(token.Kind()))
if (syntaxFacts.IsOperator(token) || SyntaxFacts.IsAssignmentExpressionOperatorToken(token.Kind()))
Copy link
Member Author

Choose a reason for hiding this comment

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

"IsPredefinedOperator" only checks the token kind regardless its context. This caused < of type argument list (e.g, in List<int>) to be classified as less than.

The check of "IsOperator" should handle everything with respect to the token context. I also think IsAssignmentExpressionOperatorToken should be removed, but will leave that for now because a test will fail, and F1 isn't the main change intended with this PR.

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 touch this function at all in this pr. It seems to be fixing two unrelated issues.

Copy link
Member Author

@Youssef1313 Youssef1313 Apr 15, 2021

Choose a reason for hiding this comment

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

@CyrusNajmabadi I had to touch it to fix test failure:

[Fact, Trait(Traits.Feature, Traits.Features.F1Help)]
public async Task TestGenericAngle()
{
await TestAsync(
@"class Program
{
static void generic<T>(T t)
{
generic[||]<int>(0);
}
}", "Program.generic``1");
}

Copy link
Contributor

Choose a reason for hiding this comment

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

the change feels dangerous. i'm ont sure what unintended consequences tehre would be by removing this case here. Instead of removing htis, could we instead have the C# f1 helper check if this a < in a generic name and not in a regular expression?

Copy link
Member Author

@Youssef1313 Youssef1313 Apr 15, 2021

Choose a reason for hiding this comment

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

That way I'll have to special case multiple things:

  • TypeArgumentListSyntax (This one is enough to make tests pass - but below will still have bugs)
  • TypeParameterListSyntax
  • FunctionPointerParameterListSyntax
  • XmlElementStartTagSyntax
  • OperatorMemberCref
  • XmlEmptyElementSyntax

This doesn't look neat IMO.

Either way, F1 help service isn't accurate and has bugs.

Does adding more tests to cover all operators that are in the deleted checks make the change more comfortable?

Copy link
Contributor

Choose a reason for hiding this comment

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

or just say that < is only an operator here if it's parent is a binaryexpression

…Service.cs

Co-authored-by: CyrusNajmabadi <cyrus.najmabadi@gmail.com>
auto-merge was automatically disabled April 16, 2021 06:47

Head branch was pushed to by a user without write access

@Youssef1313
Copy link
Member Author

@CyrusNajmabadi This should be ready to merge.

@CyrusNajmabadi
Copy link
Contributor

Thanks!

@CyrusNajmabadi CyrusNajmabadi merged commit 4b27a2d into dotnet:main Apr 16, 2021
@ghost ghost added this to the Next milestone Apr 16, 2021
@Youssef1313 Youssef1313 deleted the patch-17 branch April 16, 2021 17:12
@jinujoseph jinujoseph added the Community The pull request was submitted by a contributor who is not a Microsoft employee. label Apr 19, 2021
@dibarbet dibarbet modified the milestones: Next, 16.10.P3 Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE Community The pull request was submitted by a contributor who is not a Microsoft employee.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codelens doesn't count references for operator < C# reference count shown as 0 for operators <, >

4 participants