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

Improve tab completion and code assist in REPL #9656

Merged
merged 8 commits into from Aug 9, 2021

Conversation

retronym
Copy link
Member

@retronym retronym commented Jun 5, 2021

Re-enable acronym-style completion, e.g. getClass.gdm offers getDeclaredMethod[s].

Under JLine completion, move all filtering up in the UI layer. Reimplement #9510 (dealing with overloads that contain some deprecated alternatives) in the UI layer

Fix completion of keyword-starting-idents (e.g. this.for<TAB> offers formatted.

Register a widget on CTRL-ALT-T that prints the type of the expression at the cursor. A second invocation prints the desugared AST.

Enable Levenshtein based typo matching, but disable it for short strings which IMO tends to offer confusing results.

scala> scala.tools.nsc.util.EditDistance.levenshtien<TAB>

scala> scala.tools.nsc.util.EditDistance.levenshtein

Includes upgrade to JLine 3.20 (was 3.19)

@scala-jenkins scala-jenkins added this to the 2.13.7 milestone Jun 5, 2021
@retronym retronym requested a review from SethTisue June 5, 2021 04:31
@retronym retronym force-pushed the ticket/12267-completion-matcher branch 3 times, most recently from bed3381 to f2c9727 Compare June 5, 2021 04:33
@@ -345,7 +345,8 @@ trait Positions extends api.Positions { self: SymbolTable =>
if (t.pos includes pos) {
if (isEligible(t)) last = t
super.traverse(t)
} else t match {
}
t match {
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe this was a latent bug in the presentation compiler. It became apparent in the REPL completion tests after I (mostly) removed the hack of inserting __DUMMY__ at the cursor in this PR.

In erroneous code, the range position of the TypeDef of an annotated parameter can contain the annotation itself. So we should always try traversing into .symbol.annotations.map(_.original).

@retronym retronym force-pushed the ticket/12267-completion-matcher branch 6 times, most recently from cb974fe to b93e04e Compare June 6, 2021 06:35
Re-enable acronym-style completion, e.g. getClass.gdm`
offers `getDeclaredMethod[s]`.

Under JLine completion, move all filtering up in the UI layer.
Reimplement scala#9510 (dealing with overloads that contain some
deprecated alternatives) in the UI layer

Fix completion of keyword-starting-idents (e.g. `this.for<TAB>` offers
`formatted`.

Register a widget on CTRL-SHIFT-T that prints the type of the
expression at the cursor. A second invokation prints the
desugared AST.

Enable levenstien based typo matching, but disable it for short strings
which IMO tends to offer confusing results.

Enable levenstien based typo matching:

```
scala> scala.tools.nsc.util.EditDistance.levenshtien<TAB>

scala> scala.tools.nsc.util.EditDistance.levenshtein
```
@retronym retronym marked this pull request as ready for review June 9, 2021 03:39
@SethTisue SethTisue added the tool:REPL Changes in the Scala REPL Interpreter label Aug 2, 2021
@SethTisue SethTisue changed the title Improvements to code assist in the REPL Improvements to tab completion and code assist in the REPL Aug 2, 2021
@SethTisue
Copy link
Member

SethTisue commented Aug 2, 2021

@retronym this looks great (and feels great, I tried all the new behaviors)

One question: you've documented (in the PR description, but also in the help text in the PR) the new "show type" feature as control-shift-T, but in my terminal (Terminal app in MacOS 11.5.1), just plain control-T works, whereas control-shift-T just beeps at me. Is that not the behavior you're experiencing?

Second question: according to the JLine 3.20 release notes, they've upgraded JNA to 5.8.0: jline/jline3@8e9fc36 ; can you include that bump here, too?

No other concerns before merging.

@retronym
Copy link
Member Author

retronym commented Aug 4, 2021

just plain control-T works, whereas control-shift-T just beeps at me. Is that not the behavior you're experiencing?

Just retested. Both work for me. I've updated the docs to control-T.

I think its okay for us to hijack this keybinding. The T=type mnemonic is nice, and the existing behaviour is pretty niche.

scala> abc<C-T>def

scala> abdcef

@SethTisue
Copy link
Member

Hmm, not sure what I think about the hijacking... I actually use control-T to swap (t for transpose?) characters, I'm accustomed to that being available. Not sure how typical I am.

@retronym
Copy link
Member Author

retronym commented Aug 4, 2021

I've changed it to CTRL-ALT-T. WDYT?

@SethTisue
Copy link
Member

Yeah that works 👍

Did you see my suggestion about the JNA version?

@SethTisue

This comment has been minimized.

@retronym

This comment has been minimized.

@retronym

This comment has been minimized.

@retronym

This comment has been minimized.

@retronym

This comment has been minimized.

@retronym retronym force-pushed the ticket/12267-completion-matcher branch 4 times, most recently from 1bb2c1c to d200f2a Compare August 5, 2021 06:01
@retronym

This comment has been minimized.

@retronym retronym force-pushed the ticket/12267-completion-matcher branch from d200f2a to 34f1d09 Compare August 5, 2021 06:15
@SethTisue
Copy link
Member

fyi @eed3si9n on the JLine version bump... not sure if there are implications for sbt

@retronym retronym merged commit 0e77c42 into scala:2.13.x Aug 9, 2021
@retronym retronym deleted the ticket/12267-completion-matcher branch August 9, 2021 01:25
@SethTisue SethTisue added the release-notes worth highlighting in next release notes label Aug 9, 2021
@bjornregnell
Copy link
Contributor

Nice features! But I think CTRL+ALT+T is so much connected to "Start terminal" in Ubuntu and flavors so this will be a big clash. I would really suggest finding something else -- everything else would be almost less of a clash even if keystrokes are overloaded...

@SethTisue SethTisue changed the title Improvements to tab completion and code assist in the REPL Improve tab completion and code assist in REPL Oct 29, 2021
@SethTisue
Copy link
Member

does an .inputrc file (#9518) have the power to resolve a clash like this for an individual user?

@Sciss
Copy link

Sciss commented Nov 5, 2021

I run into missing API when updating from Scala 2.13.6 to 2.13.7 - method camelMatch has been removed. Please advise:

        def tryCamelStuff: Completion.Result = {
          // Lenient matching based on camel case and on eliding JavaBean "get" / "is" boilerplate
          val camelMatches      : List[c.Member ] = r.matchingResults(c.CompletionResult.camelMatch(_)).filterNot(shouldHide)
          val memberCompletions : List[String   ] = camelMatches.map(_.symNameDropLocal.decoded).distinct.sorted

          def allowCompletion: Boolean =
            (memberCompletions.size == 1) ||
              c.CompletionResult.camelMatch(r.name).apply {
                val pre = longestCommonPrefix(memberCompletions)
                r.name.newName(pre)
              }

          val memberCompletionsF: List[Completion.Candidate] =
            memberCompletions.map(Completion.Simple)

          if (memberCompletions.isEmpty) {
            Completion.NoResult
          } else if (allowCompletion) {
            Completion.Result(offset - r.positionDelta, memberCompletionsF)
          } else {
            // XXX TODO : why is this used in the original code, but does not appear in the results?
            //              val empty: Completion.Candidate = new Completion.Candidate {
            //                def stringRep: String = ""
            //              } // ""
            Completion.Result(offset, /* empty :: */ memberCompletionsF)
          }
        }

do I just ditch tryCamelStuff. Sadly, I don't remember the genealogy of this code, only that it no longer compiles.

@Sciss
Copy link

Sciss commented Nov 5, 2021

This was cross compiling code for Scala 2.12 and 2.13, so I have to fork that into two :-/

@SethTisue
Copy link
Member

Sciss we don't even guarantee API stability of compiler and REPL internals between minor Scala versions, let alone between major versions. So I'm sorry for the inconvenience, but I consider it normal that you might need separate 2.12-specific and 2.13-specific code from time to time.

As for what can be done on the 2.13 side specifically: It's rather unexpected that anyone was even using camelMatch from outside, to be honest.

Does it appear to you that the logic in it was removed entirely, or was it merely refactored so that it's no longer easily accessible? If the former, perhaps you could paste the logic into your own codebase. If the latter, perhaps the REPL code could be refactored to expose it again. (As for who would do the refactoring, personally I'm inclined to say "pull request welcome" to such a refactoring, but I'm not sure what Jason's own take might be.)

@xuwei-k
Copy link
Contributor

xuwei-k commented Nov 11, 2021

scala/bug#12491 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-notes worth highlighting in next release notes tool:REPL Changes in the Scala REPL Interpreter
Projects
None yet
6 participants