`Interactive.pathTo` contains `Literal(Constant(null))` as a head of path for incomplete program
See original GitHub issuearea:ide
Compiler version
3.1.3-RC2 and later
Minimized code
val sourceDefinition = "object Definition { def x }"
val uriDefinition = new URI("file:///def")
driver.run(uriDefinition, sourceDefinition) // where driver: InteractiveDriver
given ctx: Context = driver.currentCtx
val pos = new SourcePosition(driver.openedFiles(uriDefinition), Spans.Span(sourceDefinition.indexOf("def x") + "def x".length))
val path = Interactive.pathTo(driver.openedTrees(uriDefinition), pos)
path.foreach(println)
Output
with 3.1.3-RC2
or later
Literal(Constant(null))
DefDef(x,List(),...)
Template(...)
TypeDef(...)
with 3.1.2
DefDef(x,List(),...)
Template(...)
TypeDef(...)
Expectation
Scala 3.1.3 should return the same result as Scala 3.1.2. There shouldn’t be a Literal(Constant(null))
.
Additional context
This is a bit of a problem for Metals, for example, when Metals try to invoke advanced completion based on the path to the cursor position something like def |
(|
represents the cursor position).
As a workaround Metals ignore Literas(Constant(null))
.
https://github.com/scalameta/metals/blob/92d8d9ecdaead1a6db2a9ebb1a85500c22c4714d/mtags/src/main/scala-3/scala/meta/internal/pc/completions/Completions.scala#L136-L139
Issue Analytics
- State:
- Created a year ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
Build settings reference | Apple Developer Documentation
A detailed list of individual Xcode build settings that control or change the way a target is built.
Read more >openresty/lua-nginx-module: Embed the Power of ... - GitHub
Name. ngx_http_lua_module - Embed the power of Lua into Nginx HTTP Servers. This module is a core component of OpenResty. If you are...
Read more >Linter rules - Dart
Tip: Linter rules (sometimes called lints) can have false positives, and they don't all agree with each other. For example, some rules are...
Read more >Language Support for Java(TM) by Red Hat
Absolute path to JDK home folder used to launch the Java Language Server. Requires VS Code restart. java.jdt.ls.lombokSupport.enabled : Whether to enable lombok ......
Read more >SQL0000 - SQL0249 - IBM
You can process an application program source file containing embedded SQL statements and create a package in the database using the PRECOMPILE command....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Off-topic, but this is intriguing 😃, is this something you could share more information on?
More on-topic: I think it’s worth adding a comment to pathTo mentioning that it might return
errorTermTree
(but presumably only ifctx.reporter.errorsReported
is true), and it seems like we could then close this issue.@tanishiking I think this is at least arguably working as intended? I recently made some changes (some of which @odersky largely rewrote) to add the errorTermTree in more places for incomplete parses. The motivation in those PRs (e.g. https://github.com/lampepfl/dotty/pull/14463) was to differentiate between e.g.
foo(x,<EOF>
andfoo(x)
. Before the PR, these two had the same parse, but the PR changed it so that the former givesfoo(x, Literal(Constant(null))
.I think Metals should expect to see the
errorTermTree
(Literal(Constant(null))
) and ignore it? Note that I did not adderrorTermTree
, I just made it occur in more places. It’s possible some of my changes caused this particular change, but I’m not sure.