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

Remove FCS syntax tree checks from typing assists #702

Merged
merged 4 commits into from
Dec 12, 2024

Conversation

DedSec256
Copy link
Contributor

No description provided.

@DedSec256 DedSec256 force-pushed the ber.a/rewriteAssists branch 3 times, most recently from 7fa91e9 to 61f5e39 Compare August 29, 2024 17:00
@DedSec256 DedSec256 force-pushed the ber.a/rewriteAssists branch from 96d60f8 to 3ac9a40 Compare October 23, 2024 22:48
@DedSec256 DedSec256 force-pushed the ber.a/rewriteAssists branch 2 times, most recently from 3fa45e1 to 07d1c49 Compare November 9, 2024 01:27
@DedSec256 DedSec256 changed the title Rewrite some typing assists with FSharp.Compiler.Syntax Remove FCS syntax tree checks from typing assists Dec 3, 2024
@auduchinok
Copy link
Member

@DedSec256 Is is possible to extract and merge some manageable parts of this PR? I'd like to work on the typing assists, but don't want to add conflicts or more code to rework later.

@DedSec256 DedSec256 force-pushed the ber.a/rewriteAssists branch from 07d1c49 to 7e20444 Compare December 10, 2024 16:04
@DedSec256 DedSec256 marked this pull request as ready for review December 10, 2024 16:55
@DedSec256 DedSec256 requested a review from auduchinok December 10, 2024 16:57

| _ -> defaultTraverse expr }
let range =
let inline checkExpr (expr: IFSharpExpression) (node: ITreeNode) =
Copy link
Member

Choose a reason for hiding this comment

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

What does checkExpr mean? Could then name convey what the function does actually?

Copy link
Contributor Author

@DedSec256 DedSec256 Dec 10, 2024

Choose a reason for hiding this comment

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

While I was coming up with a name for the function, I found an old bug for the case

for a = 0
        to 10 do  {caret}

which resulted in

for a = 0
        to 10 do
            {caret}

instead of

for a = 0
        to 10 do
    {caret}

its' because here
image
the range was taken not from to ... expr, but do ..., which could never be matched with prevTokenEnd.

Fixed, test added.

getEndOffset document lastRange = prevTokenEnd ->
Some range
let indentOffset =
let inline tryGetIndentOffset (exprBeforeKeyword: IFSharpExpression) (indentAnchor: ITreeNode) =
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason to inline it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In order not to allocate a closure for tokenBeforeKeywordEnd, used inside

Copy link
Member

Choose a reason for hiding this comment

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

Does it make any measurable difference?

Compared to reparsing the whole file after the Enter press, converting the resulting FCS tree into a R# one, type checking it, running the daemon, and calculating code completions, how much do we save here? I'd rather keep things simple and use the language default behavior, unless there's a convincing reason (e.g. we're going to allocate it hundreds/thousands times).

Copy link
Member

@auduchinok auduchinok Dec 12, 2024

Choose a reason for hiding this comment

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

And I also don't see where and how exactly it's allocated. Could you explain this, please? Thank you 🙂

Copy link
Contributor Author

@DedSec256 DedSec256 Dec 12, 2024

Choose a reason for hiding this comment

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

It could be viewed in Release mode in IL, since it has tokenBeforeKeywordEnd in closure

image
image

In any case, if this is an obstacle on the way to merge, I will remove inline, this is not so critical.

Copy link
Member

Choose a reason for hiding this comment

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

Wow, I'd not expect a closure there at all. Thanks for showing this!

Copy link
Member

Choose a reason for hiding this comment

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

Maybe it's worth trying to find a minimal repro and reporting it to the compiler team. Or is it expected and I'm missing something?

@auduchinok auduchinok merged commit f700f39 into main Dec 12, 2024
1 check passed
@DedSec256 DedSec256 deleted the ber.a/rewriteAssists branch December 13, 2024 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants