-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Retain position of extension function calls #11574
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
Conversation
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.
Thanks for taking this on!
I tried with right associative operator extension applications, which still have a zero length span, e.g.
package ext
extension (s: String)
def :*: (i: Int): (String, Int) = (s, i)
val b = "foo" :*: 23
yields
expect/Extension.scala
----------------------
Summary:
Schema => SemanticDB v4
Uri => Extension.scala
Text => empty
Language => Scala
Symbols => 5 entries
Occurrences => 14 entries
Symbols:
ext/Extension$package. => final package object ext
ext/Extension$package.`:*:`(). => method :*:
ext/Extension$package.`:*:`().(i) => param i
ext/Extension$package.`:*:`().(s) => param s
ext/Extension$package.b. => val method b
Occurrences:
[0:8..0:11): ext <- ext/
[2:0..2:0): <- ext/Extension$package.
[2:11..2:12): s <- ext/Extension$package.`:*:`().(s)
[2:14..2:20): String -> scala/Predef.String#
[3:6..3:9): :*: <- ext/Extension$package.`:*:`().
[3:11..3:12): i <- ext/Extension$package.`:*:`().(i)
[3:14..3:17): Int -> scala/Int#
[3:21..3:27): String -> scala/Predef.String#
[3:29..3:32): Int -> scala/Int#
[3:37..3:37): -> scala/Tuple2.apply().
[3:37..3:38): s -> ext/Extension$package.`:*:`().(s)
[3:40..3:41): i -> ext/Extension$package.`:*:`().(i)
[5:4..5:5): b <- ext/Extension$package.b.
[5:14..5:14): -> ext/Extension$package.`:*:`(). // Note: zero length span here
we should probably watch out for possible interaction with the selectSpan
method: https://github.com/lampepfl/dotty/blob/4ed026cb7c0e3e1f97456172e382f199c1aea8da/compiler/src/dotty/tools/dotc/semanticdb/ExtractSemanticDB.scala#L515
I solved the problem with inline operators by adding an attachment containing the original span of the operator. I don't think there is any nicer way of passing this information for synthesized selects. |
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, I have found an optimisation without attachments
@@ -415,6 +415,15 @@ object Trees { | |||
qualifier.typeOpt.member(name).atSignature(Signature.NotAMethod, name) | |||
case _ => | |||
super.denot | |||
|
|||
def nameSpan(using Context): Span = |
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.
I tried this which did not need any attachments (I don't think its that important to do the point span for synthetic):
def nameSpan(using Context): Span =
if span.exists then
val point = span.point
if name.toTermName == nme.ERROR then Span(point)
else if qualifier.span.start > span.start then // right associative
val realName = name.stripModuleClassSuffix.lastPart
Span(span.start, span.start + realName.length, point)
else
Span(point, span.end, point)
else span
- simplify select name span logic - add test for left associative operators
Fixes #11523.