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

Fix reporting IsFromComputationExpression for inappropriate symbols #17375

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

DedSec256
Copy link
Contributor

@DedSec256 DedSec256 commented Jul 2, 2024

Description

Upon investigating the syntax highlighting issue for CE code in Rider, I found that FCS reports a separate SymbolUse for expressions that are not a constructor invocation of the CE builder type or an associated with it let-binding:

image

This behavior seems incorrect because the Object.Prop expression does not appear to require highlighting as a CE keyword. Unexpected case, and therefore it may not be properly handled, which can lead to incorrect overlapped code highlighting, for example, like this

image

or even worse

image

and can also lead to navigation errors in the 'go to definition' due to overlapping SymbolUse ranges.

The same issue is reproducible in VS/VS Code.

member _.IsFromComputationExpression =
match symbol.Item, itemOcc with
// 'seq' in 'seq { ... }' gets colored as keywords
| Item.Value vref, ItemOccurence.Use when valRefEq denv.g denv.g.seq_vref vref -> true
// custom builders, custom operations get colored as keywords
| (Item.CustomBuilder _ | Item.CustomOperation _), ItemOccurence.Use -> true
| _ -> false

Also, I did not find any tests confirming that IsFromComputationExpression should be true for such expressions.

Fix

This PR suggests reporting IsFromComputationExpression only for CE Builder type constructors and let-bindings.

Checklist

  • Test cases added
  • Release notes entry updated

@DedSec256 DedSec256 requested a review from a team as a code owner July 2, 2024 00:18
Copy link
Contributor

github-actions bot commented Jul 2, 2024

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/8.0.400.md

@DedSec256 DedSec256 force-pushed the ber.a/fixCeBuilderReporting branch from 5e7c8ac to c14a435 Compare July 2, 2024 00:32
@brianrourkeboll
Copy link
Contributor

Hmm, VS does not colorize things like A.Builder { return 3 } or System.Object.Builder { return 3 } as keywords. Does Rider currently do so? Or are you just saying that the extra SymbolUse shouldn't be there?

image

@DedSec256
Copy link
Contributor Author

DedSec256 commented Jul 3, 2024

@brianrourkeboll,

You can notice incorrect coloring of parentheses as CE keyword color there.

image

It also seems incorrect for a more complex case (tested on VS v17.10.3):

image

There is also the issue in VS Code:

image

I did not research the logic of how Visual Studio/VS Code maps symbols to highlightings; however, the extra SymbolUse with IsFromComputationExpression indeed shouldn't be listed for cases from this PR.

As a result, it will also fix highlightings in Rider (and, hopefully, in VS/VS Code)

PS. Thanks, I updated the PR description a little bit

@DedSec256
Copy link
Contributor Author

DedSec256 commented Jul 3, 2024

Perhaps this case is OK 🤔

image

@brianrourkeboll
Copy link
Contributor

Perhaps this case is OK 🤔

image

Hmm, yeah, I mean how far do we want to go? :)

image

@baronfel
Copy link
Member

baronfel commented Jul 3, 2024

For context, here's how FSAC does semantic tokenization.

Generally we take the classifications directly from FCS via the SemanticClassificationType that is determined for a range, but we have to map those SemanticClassificationTypes to a set of SemanticTokenType and SemanticTokenModifier that are defined partially in the LSP spec and partially in FSAC's LSP bindings. This combination of token type + token modifier is mapped to predefined and user-defined editor styling.

So in general we assume FSC is true/correct, and try to do the most minimal mapping/handling possible for this feature area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

Successfully merging this pull request may close these issues.

None yet

4 participants