-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Pressing enter only results in inserting a newline after more than half a minute #1331
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
Comments
Assuming vscode, is there anything showing in the output / traces? |
I sometimes get this. A temporary workaround of using ctrl+enter rather than just ctrl has worked for me. |
@memoryruins Yes, it is vscode. Sorry for not mentioning that. I had a look at issue #1259. I am not sure whether there is any difference between his project or mine. I have a workspace crate that contains four crates, which are used as dependencies amongst each other (very similar to RA's structure) The reported error seems different from #1259 though. From what I could determine from the log, it consistently takes about 15 seconds for the server to respond to a request. Sometimes the server reports that the client cancelled a request. The reception of a response doesn't directly result in the addition of a newline. Eventually all enters are processed and cause newlines to occur at the original location of execution. Some additional observations:
This is just me hypothesizing, but it almost seems like some work is happening in the background that stalls requests. As requests start racking up, this causes further delays. When left for a while, the queue slowly empties. After this further requests can happen directly again. Could it maybe be caused by the initial loading of modules, as that might take some time. It's weird that I can type other symbols than Enter without any issues though. @DJMcNab Thank you! Pressing Ctrl + Enter actually works :) The trace reports the following: EDIT(@matklad): hide the trace under
```
[Trace - 18:23:04] Sending request 'rust-analyzer/onEnter - (38)'.
Params: {
"textDocument": {
"uri": "file:///e%3A/dev/src/se4_core/crates/se4_db/src/lib.rs"
},
"position": {
"line": 26,
"character": 5
}
}
[Trace - 18:23:16] Received response 'textDocument/codeAction - (29)' in 13268ms. Request failed: canceled by client (-32800). [Trace - 18:23:18] Received response 'textDocument/codeLens - (27)' in 16760ms. [Trace - 18:23:18] Received response 'textDocument/codeLens - (26)' in 16762ms. [Trace - 18:23:18] Received response 'codeLens/resolve - (25)' in 16762ms. Request failed: canceled by client (-32800). [Trace - 18:23:18] Received response 'textDocument/codeLens - (33)' in 14768ms. [Trace - 18:23:18] Received response 'textDocument/codeLens - (35)' in 14765ms. [Trace - 18:23:18] Received response 'rust-analyzer/onEnter - (37)' in 14589ms. [Trace - 18:23:18] Received response 'rust-analyzer/onEnter - (38)' in 14357ms.
|
No problem! I'm afraid I can't really help with the underlying issue. |
It's a know problem, I hope to look into this soon. The crux of the issue is that we don't implement any kind of request prioritization, so things like "handle enter" could be blocked on the background analysis |
1334: check for cancellation during macro expansion r=matklad a=matklad closes #1331 Co-authored-by: Aleksey Kladov <[email protected]>
@matklad - I'm still seeing this issue with the latest rust-analyzer |
I'm also experiencing this issue quite commonly. Will gladly help if pointed in the right direction :) |
@kiljacken the steps to handle this problem:
#1334 contains all those steps Docs for our profiling infra are here: https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/dev/README.md#profiling |
To clarify, on the high level, the problem isn't that handling Enter is slow, the problem is that handling Enter is blocked on some other stuff, and we should make sure that "other stuff" is properly canceled or does not block high-priority operations in the first place. Another pointer would be our main loop: Here, you can see on the highest level the order and timings of various events. |
Also, setting |
I also started experiencing this a couple of days ago. The one thing that a text editor should be able to do flawlessly is handle my keystrokes, so needless to say, it's very frustrating when it does not. I can confirm that the issue is present on commit 854dac3. I haven't yet tried whether the issue persists with #1334 or with |
I've looked into this, and, while I can't reproduce mulit-seconds hangs after #1334, I've fixed a couple of potential problems:
(
I wonder if folks still can reproduce the problem after cb21a21 |
Yes, I can still reproduce it. If you open https://github.com/wycats/nushell and open src/commands/split.rs, try to hit enter towards the top of the file. Especially if you tell it to run cargo check, I'm seeing pretty long delays after hitting enter. Sometimes the delays are multiple seconds. |
I'm also looking at the "Rust Analyzer Language Server Trace" and don't see any output like you mention above. It's possible I'm not installing something correctly? I've been using |
The screenshot is from Rust Analyzer: Status VS Code command. The hierarchical profiling is printed only if you set |
Just wondering, can a user request trigger a long-running computation (due to the lazy nature of RA) that isn't attributed properly in the profiler? EDIT: E.g. I open a file and the highlighter wants semanatic information, which triggers analysis of most of the code in the project, and bad luck if you're opening it from a network share. |
That is possible, though most of the stuff should be profiled. The notable thing which takes time, but is not present in the profile is salsa's overhead for validation, see https://salsa.zulipchat.com/#narrow/stream/145099-general/topic/Some.20Profiling.20data/near/166644275. Though ideally this shouldn't be a problem. Rust Analyzer is explicitly architectured with arbitrary-long background computations in mind, so what should happen in this case is that, while one thread computes long-running task, another thread handles on-enter. After that, the client sends changes from on-enter, and the long-running task is automatically canceled. But, as we clearly from profile data, the theory does not work in practice :D My next hypothesis is that we handle onEnter asynchronously, so we recieve request and send response on different event loop turns, and something in between blocks the event loop. I'll try to handle onEnter synchronously, on the same turn of the event loop: really, there's no reason to offload it to background thread, and this naturally gives us that "task prioritization" I alluded to before. |
Found it! It's salsa! Specifically, what I am seeing is this:
diagnostics kick in after a change and compute name resolution. We see that something has changed, so we kick nameres for the current crate (which, really shouldn't be the case I think for adding a blank like, but that's a separate issue). That name res kicks resolution of other crates, notably of std, in |
The reason for that is if we happen to cancel a subquery when the parent query is validated, we completely remove the parent query, instead of marking it as not-validated |
Is there an issue in Salsa to track this slowness? Edit: or, if it is unavoidable (which I doubt based on your comment), to discuss what we can do to make it better on our end. |
Closed by #1348, I hope 😅 If you still see hangs after that, please reopen :-)
no, but I've found a work-around, and we are discussing stuff in Zulip: https://salsa.zulipchat.com/#narrow/stream/145099-general/topic/Some.20Profiling.20data and https://salsa.zulipchat.com/#narrow/stream/184114-rfcs.2Fdrafts-and-proposals/topic/mutable.20constants |
On my laptop nothing else works fine while |
@jonathandturner what happens if you disable cargo watch though? |
I'm not using
Edit: another time that seemed like 5 to 10 seconds:
|
Status update: I still haven't looked closely into this particular issue, as I can't get a reproduction on a local machine. My current thoughts:
|
Status update: @jminer and @lnicola discovered that this is a windows specific issues, caused by the fact that our cancellation mechanism triggers collection of backtraces. I am pushing a hot-fix for this in #1401 (basically, don't force backtrace), the proper solution is presumably #1400 (we need to verify though that just |
It doesn't print anything, so no backtrace either. I used it in |
Ok, as an old Russian tale goes,
If you are still seeing this, please reopen :) |
There's a 5 seconds lag between pressing enter and having the new line inserted. It's also related to #3212 because I had the "Command 'rust-analyzer.onEnter' not found" message when I deactivated rust-analyzer to check if it was the culprit. That binding is automatically added so I can't remove it, even after having deactivated rust-analyzer, and even after reloading VSCode in safe mode!. I had to close VSCode and edit my keybdings.json in Sublime Text. All that so I can get rid of that latency :/ |
The onEnter command hasn't been automatically added for more than 2 years. What version of the extension do you have installed? |
VSCode says v0.3.1123 |
Well, that's up to date. Maybe you started out with a very old version? |
I checked, and my oldest rust work dates from Jan/Feb 2021. So let's say not sooner than late 2020 🤷♂️ I guess I'm good for some deep cleaning and reinstallations? |
Probably. |
Well, the issue went away after a clean uninstall. No idea what was causing it though :/ |
Uh oh!
There was an error while loading. Please reload this page.
After installing the latest version of rust analyzer, I noticed that pressing Enter (either the default or numpad Enter) doesn't result in a newline. After a seemingly arbitrary delay of over 30 seconds, a new line is inserted after all.
I also tried copying and pasting a newline, which works without any trouble.
It seems like it is a regression from my previous install (last week). Currently I am on commit
91bd783273477d
.The text was updated successfully, but these errors were encountered: