I've been looking at the LLDB REPL code completion (with the eventual goal of exposing it in the jupyter kernel that I'm working on), and I had a thought about how to improve its implementation, and I wanted to ask what others think about it.
Right now, the REPL accumulates all the code that you type in. When you ask for a completion, it sends all the accumulated code to REPLCodeCompletion.h, which calculates the completions. I see two disadvantages to this approach:
Efficiency: If you have a really long REPL session with a lot of code, the completer will have to process a lot of code to make a completion. (Though does it cache anything to make this faster?)
Correctness: LLDB lets you redeclare things that you woudn't normally be able to redeclare in Swift. For example, you can do:
1> let x: Int = 1 x: Int = 1 2> let x: Float = 1 x: Float = 1
This seems to confuse the completer. For example, when you do the above redeclaration and then ask it for completions for
x., it gives you
Int methods rather than
Instead of giving the completer the accumulated code, maybe we could give the completer: (1) the state of the declarations that LLDB is storing (SwiftPersistentExpressionState), and (2) just the current line of code.
Doing it this way should fix both problems.
Does this seem like a reasonable approach?
I might try to implement this soon. Would you be interested in accepting some PRs into master that do this?