-
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
Unify completion pos usage, fix presentation compiler crash in interpolation #19614
Conversation
presentation-compiler/src/main/dotty/tools/pc/completions/CompletionPos.scala
Outdated
Show resolved
Hide resolved
offsetParams: OffsetParams, | ||
adjustedPath: List[Tree] | ||
)(using Context): CompletionPos = | ||
infer(cursorPos, offsetParams.uri().nn, offsetParams.text().nn, adjustedPath) | ||
infer(sourcePosition, offsetParams.uri().nn, String(sourcePosition.source.content()), adjustedPath) |
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 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.
sourcePosition contains artificial "CURSOR", offsetparams.text() is plain sourcecode
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.
Actually looks like text
is unused and we should remove it
presentation-compiler/src/main/dotty/tools/pc/completions/ScalaCliCompletions.scala
Outdated
Show resolved
Hide resolved
infer(cursorPos, offsetParams.uri().nn, offsetParams.text().nn, adjustedPath) | ||
val identEnd = adjustedPath match | ||
case (ident: Ident) :: _ if ident.toString.contains(Cursor.value) => | ||
ident.span.end - Cursor.value.length |
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.
What about e.g. Select
? Wouldn't you have to consider all possible trees for this to work this way?
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.
RefTree.name should handle all the cases
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.
including import
, export
?
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.
Actually yes. I think that it is impossible for pathTo
to return ImportSelector or ExportSelector as head as there are only 2 cases:
- we do normal import, and this Identifier has the same span as this ImportSelector
- we do a rename, which has another Identifier that will be matched in
pathTo
if we are inside it.
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.
Unless it is empty ? Maybe a test like this will ensure its correctness.
@@ -107,7 +106,7 @@ class Completions( | |||
end includeSymbol | |||
|
|||
def completions(): (List[CompletionValue], SymbolSearch.Result) = | |||
val (advanced, exclusive) = advancedCompletions(path, pos, completionPos) | |||
val (advanced, exclusive) = advancedCompletions(path, completionPos.originalCursorPosition, completionPos) |
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.
val (advanced, exclusive) = advancedCompletions(path, completionPos.originalCursorPosition, completionPos) | |
val (advanced, exclusive) = advancedCompletions(path, completionPos) |
And to avoid too many changes in advancedCompletions
just do:
val pos = completionPos.originalCursorPosition
79325bf
to
86bf70d
Compare
case untpd.Ident(_) :: untpd.Import(_, _) :: _ => Mode.ImportOrExport | ||
case untpd.Ident(_) :: (_: untpd.ImportSelector) :: _ => Mode.ImportOrExport | ||
case untpd.Literal(Constants.Constant(_: String)) :: _ => Mode.Term // literal completions | ||
case untpd.Ident(_) :: (_: untpd.ImportSelector) :: _ => Mode.ImportOrExport // import scala.@@ |
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.
possibly also should be member?
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.
As far as I know member completions are fetched from symbol search. They are also source of extension methods outside the scope. ain this scenario we can only complete with direct members
@@ -211,7 +194,6 @@ object Completion: | |||
case tpd.Select(qual, _) :: _ if qual.typeOpt.hasSimpleKind => completer.selectionCompletions(qual) | |||
case tpd.Select(qual, _) :: _ => Map.empty | |||
case (tree: tpd.ImportOrExport) :: _ => completer.directMemberCompletions(tree.expr) |
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.
Is this case needed?
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.
Yes, those are typed Trees, and this is the head of the path. We need it to find package members
|unshared - scala.annotation.internal | ||
|unspecialized - scala.annotation""".stripMargin, | ||
topLines = Some(5) | ||
"", |
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.
these are illegal completions at this position, it expects the name. On the other hand you can add annotations in this position. I'll add tests that ensure that they are present if we start a query with @
I also removed 2 files: Custom completions and its Tests. They were added to the compiler for ammonite, but after all they were also never used. They failed the tests, and the reason behind it that the file hasn't been updated for 3 years, and getting it up to date is too much costs / not worth. |
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.
They were added to the compiler for ammonite, but after all they were also never used. They failed the tests, and the reason behind it that the file hasn't been updated for 3 years, and getting it up to date is too much costs / not worth.
We also have AmmoniteIvyCompletions
now, which should do the same thing.
presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala
Show resolved
Hide resolved
|
||
case (sel: untpd.ImportSelector) :: _ => | ||
if sel.imported.span.contains(pos.span) then Mode.ImportOrExport |
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 remove this check?
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.
Actually I have to revert it. I was tricked by our tests, as they don't enter completions in this position for some reason. We should probably also add check to not compute any completions when mode is None...
This is actually a bit different. They planned to use this in repl completions. |
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
90e950f
to
27acfd9
Compare
Fixes crash for added tests in
CompletionInterpolatorSuite
along with unification and better naming for completion pos, source pos, and span usage.