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
PY-10985/IDEA-104596: Prefix based console history #593
Conversation
d5fa5bc
to
38afd5c
Compare
@Traff ping |
Hi Yuli! |
@Elizaveta239 My main motivation is not really performance -- there are really no CPU intensive tasks here. I'm using pcollections to make it simplify reasoning about concurrency in places where state may be updated by multiple threads/consoles. Also to avoid placing unnecessary locks or making defensive copies. I thought this library is ok to include because the kotlin guys find it reliable enough to implement kotlin persistent collections based on it: https://github.com/Kotlin/kotlinx.collections.immutable. Also the jar is tiny (under 40KB). Could you ask Ilya Gorbunov( @ilya-g ) if the library is reliable enough? I assume he knows more about it than we do. If it's not reliable or we can't include it for some reason I can re-implement without it. Also please let me know if you find any other issues. Thanks! |
@fitermay If so, why don't you want to use this Kotlin library? During the next two weeks I will be on vacation, and after that I'll finish reviewing. |
@Elizaveta239 I'd rather use the Kotlin library. Are you ok with using it? Not sure of the right way to add a kotlin lib to the project. Do I just drop the jar into lib? |
38afd5c
to
971673d
Compare
@Elizaveta239 Replaced pcollections with kotlix.immutable, fixed issue caused by kotlin compiler bug and rebased onto latest master. |
Currently the kotlinx.collections.immutable library doesn't offer the performance better than pcollections, as it is built on top of pcollections. That library was chosen as the implementation not because of its outstanding reliability, but because it's just easier to adapt it to the proposed API and the library itself is rather small. @fitermay Regarding the usage of the immutable persistent list in this PR, I don't see a big need in that, so that it could justify adding another library to the IDEA codebase. You can use any read-only |
|
||
|
||
override fun addToHistory(statement: String?) { | ||
val stmt = statement ?: return |
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.
You can just check if (statement == null) return
and it will be smart-casted further. It's more clear and there's no need in an additional local val.
@ilya-g I could use a read only list but then I would have to make a copy each time I need to mutate state. This isn't a big deal IMO because the lists are small but there was some discussion about performance so I don't know if that will be accepted. |
Anyways I will rewrite with regular mutable collections. Most of the operations here must be on the EDT anyways. No idea why the original model used those unnecessary locks but it had me in the beginning. |
Hi @fitermay! I'm back and I'm ready to continue a review. I like the idea to use regular collections. I haven't passed a build to our QA team yet, but I've met a strange behaviour after a short testing.
if True:
print("Hello")
If in the state 4 you decide to delete the command and just press enter, it doesn't execute empty command, but it prints "..." for entering a multiline command. It looks like a bug as well. As far as I understand, in the current implementation you assume that the prefix for a history search is a substring of the first line from the beginning to the caret position. It works fine when you navigate through the history to the older commands (the caret is always on the first line). But if you decide to go back to the most recent command (press "down" many times), the console should show you only commands, which you've already seen. And your caret position on the first line shouldn't affect the commands order. I mean if I searched for commands with |
} | ||
newEntries += stmt | ||
|
||
return@updateAtomically State(newEntries, newEntries.size) |
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.
Minor: here and in some other places you can remove return
, since it's a last statement in a lambda and it will be implicitly returned.
@Elizaveta239 Yes, it depends on the caret position on the first line. Like I said I copied the behavior of QtConsole. I think the behavior you want is more intuitive though. I will fix it. However, please do experiment with QtConsole and let me know which behavior you want. |
@fitermay Sorry, I missed your comment editing. Yes, I think, QtConsole isn't very intuitive. If you have time, it would be great if you implement another behaviour. Please, let me know if you're not going to change it - I'll do it on my own later. |
Replace kotlinx immutable with regular collections Change navigation to previous to be previous seen entries regardless of prefix
971673d
to
487783c
Compare
@Elizaveta239 Hi, Didn't have time to work in it until today. I've applied the changes we discussed. |
@fitermay Thank you! I'll review it this week. |
@fitermay It's ok, I've passed a build to our QA team. |
@Elizaveta239 Great, I think getting feedback from QA and EAP users ASAP is the best way to get this right. |
@fitermay Thank you for your contribution! Pull request is merged. |
…as the context fixed #593 GitOrigin-RevId: 5ceeb430a4ce9251aa4cd399a017c024255dc6be
Some notes: