-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 artificial CURSOR
added to code in the completions
#20899
Conversation
presentation-compiler/src/main/dotty/tools/pc/AutoImportsProvider.scala
Outdated
Show resolved
Hide resolved
presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionSuite.scala
Show resolved
Hide resolved
|until(end: Long): Exclusive[Long] | ||
|until(end: Long, step: Long): Exclusive[Long] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change probably was caused by fact, that ImplicitSearch now worked with a fully typed trees (with CURSOR it was an error), and this was the match. I'm curious tho what would be the output for 1.unt@@
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this completion is run on 1.unt
, it shows old results too. This is a limitation / bug of current completion members coming from extension methods.
The underlying issue is a fact that we're fetching all matching implicits instead of only the best ones that will be used in that exact context.
presentation-compiler/test/dotty/tools/pc/tests/completion/CompletionArgSuite.scala
Show resolved
Hide resolved
presentation-compiler/src/main/dotty/tools/pc/completions/CompletionProvider.scala
Show resolved
Hide resolved
presentation-compiler/src/main/dotty/tools/pc/completions/CompletionProvider.scala
Outdated
Show resolved
Hide resolved
presentation-compiler/test/dotty/tools/pc/tests/CompilerCachingSuite.scala
Outdated
Show resolved
Hide resolved
presentation-compiler/test/dotty/tools/pc/tests/CompilerCachingSuite.scala
Outdated
Show resolved
Hide resolved
presentation-compiler/test/dotty/tools/pc/tests/CompilerCachingSuite.scala
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I think this would be a great improvement. I don't have anything to add aside from what @kasiaMarek already commented
a4ad2a5
to
a9ac829
Compare
IMPORTANT: When backporting make sure that #21438 is backported before this PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This PR aims to remove the need for artificial
CURSOR
identifier which was appended after current cursor position:Would result in code:
This lead to super inefficient IDE experience in terms of number of compilations done after each change, but let's be a bit more specific. Let's imagine that we have 2 scenarios in which IDE events arrive to metals:
On top of that, we've implemented a compilation caching, where code snippet and compiler configuration is a key. Now you should notice the issue, that adding a CURSOR into a code has different compilation result with cache invalidations.
In theory, we could handle CURSOR compilation as normal ones, but in reality it is a completely different run with different result (for example in diagnostics, as each one will contain CURSOR in the message). This is a no-go, especially if we would want to have diagnostics coming from presentation compiler in the future.
Because of that, each keypress results in at least 2 compilation and in the worst case scenario in 3. This also make metals way more battery heavy.
This PR is an attempt to drop CURSOR insertion for most cases.
A bit of history, how we ended up with CURSOR in a first place.
Most of the reasons are caused by parser and its recovery.
For example, finding a proper scope in this snippet:
We have to find the correct scope in which we are (inner vs outer). We can achieve this in multiple ways, for example, count indents. This solution may not be so straightforward, as there can be different indentations etc. Inserting a synthetic
CURSOR
into this place:Will actually parse into an identifier with scope provided to us by Scala compiler. This is way easier and will always be correct.
Second example are keywords, let's say we have the following snippet:
This code will expect a type, as the parser found a new keyword. Adding a
CURSOR
here resolves the problem, as now we're dealing withnewCURSOR
, notnew
keyword (identifier vs keyword).This PR is basically a change, which disables adding a CURSOR in all cases but 2 mentioned above. Those cases are very, very, very rare and is something that we can deal with. With this change, each compilation will now be cached and reused as intended resulting in way longer battery life, performance, response times and will enable us to access diagnostics for free without risking recompilation.
TODO:
I'd also love to have this backported to LTS, as it is a significant performance tweak and will allow me to add diagnostics on the fly for the Scastie.
[test_windows_full]