question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(csharp) Contextual keywords are highlighted incorrectly

See original GitHub issue

Describe the issue

In C#, there are “contextual keywords”, which are not always treated as keywords. They are highlighted incorrectly in a context where they are not treated as a keyword.

Sample Code to Reproduce

public class Move
{
    public Move(Point from, Point to) // from should not be highlighted here.
    {
        var x = from x in y where x.z == 0 select x; // from is highlighted here. (Note that GitHub handles it correctly)
    }
}

Expected behavior

from isn’t highlighted as a keyword.

Additional context

In other contexts (LINQ query), from should be highlighted as a keyword.

Note: This issue may not be limited to from.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
joshgoebelcommented, Oct 7, 2021

Tagging auto-close… we’re no longing going to leave hard contextual parsing issues open as these are by their nature impossible to fix fully without a full parser. If someone would like to work on a PR for the few simple cases, this would be welcome, but it’s not a reason for such issues to become zombie issues forever.

0reactions
joshgoebelcommented, Oct 4, 2021

@Youssef1313 Want to try your hand at a PR? I feel like we need a special rule just for from or join that looks ahead and makes sure it has word word? in and then remove them from the regular keyword list.

I think in could stay in the regular list, correct?

Read more comments on GitHub >

github_iconTop Results From Across the Web

C# syntax highlighting incorrect in 1.56 · Issue #123333 - GitHub
The new keyword and constructor name are highlighted incorrectly when a variable is assigned after being declared. When assigned and declared in ...
Read more >
C# Keywords - Microsoft Learn
Contextual keywords ​​ A contextual keyword is used to provide a specific meaning in the code, but it isn't a reserved word in...
Read more >
Could using yield as a contextual keyword ever cause an issue
So my question is: Are there any situations where using yield instead of yield return in C# would have broken backwards compatibility, or ......
Read more >
Ten C# Keywords That You Shouldn't Be Using - Simple Thread
1) sealed – I went ahead and put what is probably the most controversial keyword in this list first. Sealed.
Read more >
C# syntax highlighting not working - Visual Studio Feedback
I've noticed hit-or-miss C# syntax highlighting in Microsoft Visual Studio Community 2019 Version 16.6. 0. After last update 16.6.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found