aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-08-09 23:39:10 +0100
committerGitHub <[email protected]>2020-08-09 23:39:10 +0100
commitb1cb4ac13d5b625dd497692b6396287a30ff12e2 (patch)
tree6a3465bc8ef80890503c39945f2cfddb49044dae
parent9995e79cce548d43505d91653e2a1fdde8729134 (diff)
parentdbe7ede2eebc1301a40f0e1a3a408e11a86a0e84 (diff)
Merge #5693
5693: Fix no inlay hints / unresolved tokens until manual edit to refresh r=jonas-schievink a=Veetaha Fixes https://github.com/rust-analyzer/rust-analyzer/issues/5349 Now we return ContentModified during the workspace loading. This signifies the language client to retry the operation (i.e. the client will continue polling the server while it returns ContentModified). I believe that there might be cases of overly big projects where the backoff logic we have setup in `sendRequestWithRetry` (which we use for inlay hints) might bail too early (currently the largest retry standby time is 10 seconds). However, I've tried on one of my project with 500+ dependencies and it is still enough. Here are the examples before/after the change (the gifs are quite lengthy because they show testing rather large cargo workspace). <details> <summary>Before</summary> Here you can see that the client receives empty array of inlay hints and does nothing more. Same applies to semantic tokens. The client receives unresolved tokens and does nothing more. The user needs to do a manual edit to refresh the editor. ![prev-demo](https://user-images.githubusercontent.com/36276403/89717721-e4471280-d9c1-11ea-89ce-7dc3e83d9768.gif) </details> <details> <summary>After</summary> Here the server returns ContentModified, so the client periodically retries the requests and eventually receives the wellformed response. ![new-demo](https://user-images.githubusercontent.com/36276403/89717725-eb6e2080-d9c1-11ea-84c9-796bb2b22cec.gif) </details> Co-authored-by: Veetaha <[email protected]>
-rw-r--r--crates/rust-analyzer/src/main_loop.rs10
-rw-r--r--editors/code/src/util.ts6
2 files changed, 13 insertions, 3 deletions
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs
index 438e965e0..0ac6434dd 100644
--- a/crates/rust-analyzer/src/main_loop.rs
+++ b/crates/rust-analyzer/src/main_loop.rs
@@ -337,6 +337,16 @@ impl GlobalState {
337 fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> { 337 fn on_request(&mut self, request_received: Instant, req: Request) -> Result<()> {
338 self.register_request(&req, request_received); 338 self.register_request(&req, request_received);
339 339
340 if self.status == Status::Loading && req.method != "shutdown" {
341 self.respond(lsp_server::Response::new_err(
342 req.id,
343 // FIXME: i32 should impl From<ErrorCode> (from() guarantees lossless conversion)
344 lsp_server::ErrorCode::ContentModified as i32,
345 "Rust Analyzer is still loading...".to_owned(),
346 ));
347 return Ok(());
348 }
349
340 RequestDispatcher { req: Some(req), global_state: self } 350 RequestDispatcher { req: Some(req), global_state: self }
341 .on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| Ok(s.fetch_workspaces()))? 351 .on_sync::<lsp_ext::ReloadWorkspace>(|s, ()| Ok(s.fetch_workspaces()))?
342 .on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))? 352 .on_sync::<lsp_ext::JoinLines>(|s, p| handlers::handle_join_lines(s.snapshot(), p))?
diff --git a/editors/code/src/util.ts b/editors/code/src/util.ts
index 970fedb37..49d2d1c6f 100644
--- a/editors/code/src/util.ts
+++ b/editors/code/src/util.ts
@@ -64,7 +64,8 @@ export async function sendRequestWithRetry<TParam, TRet>(
64 param: TParam, 64 param: TParam,
65 token?: vscode.CancellationToken, 65 token?: vscode.CancellationToken,
66): Promise<TRet> { 66): Promise<TRet> {
67 for (const delay of [2, 4, 6, 8, 10, null]) { 67 // The sequence is `10 * (2 ** (2 * n))` where n is 1, 2, 3...
68 for (const delay of [40, 160, 640, 2560, 10240, null]) {
68 try { 69 try {
69 return await (token 70 return await (token
70 ? client.sendRequest(reqType, param, token) 71 ? client.sendRequest(reqType, param, token)
@@ -84,8 +85,7 @@ export async function sendRequestWithRetry<TParam, TRet>(
84 log.warn("LSP request failed", { method: reqType.method, param, error }); 85 log.warn("LSP request failed", { method: reqType.method, param, error });
85 throw error; 86 throw error;
86 } 87 }
87 88 await sleep(delay);
88 await sleep(10 * (1 << delay));
89 } 89 }
90 } 90 }
91 throw 'unreachable'; 91 throw 'unreachable';