Retry inlay hints on content modified error
This commit is contained in:
parent
08c5d157f9
commit
23bac12062
@ -709,16 +709,11 @@ fn result_to_task<R>(id: RequestId, result: Result<R::Result>) -> Task
|
||||
Ok(lsp_error) => Response::new_err(id, lsp_error.code, lsp_error.message),
|
||||
Err(e) => {
|
||||
if is_canceled(&e) {
|
||||
// FIXME: When https://github.com/Microsoft/vscode-languageserver-node/issues/457
|
||||
// gets fixed, we can return the proper response.
|
||||
// This works around the issue where "content modified" error would continuously
|
||||
// show an message pop-up in VsCode
|
||||
// Response::err(
|
||||
// id,
|
||||
// ErrorCode::ContentModified as i32,
|
||||
// "content modified".to_string(),
|
||||
// )
|
||||
Response::new_ok(id, ())
|
||||
Response::new_err(
|
||||
id,
|
||||
ErrorCode::ContentModified as i32,
|
||||
"content modified".to_string(),
|
||||
)
|
||||
} else {
|
||||
Response::new_err(id, ErrorCode::InternalError as i32, e.to_string())
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ export default {
|
||||
commonjs({
|
||||
namedExports: {
|
||||
// squelch missing import warnings
|
||||
'vscode-languageclient': ['CreateFile', 'RenameFile']
|
||||
'vscode-languageclient': ['CreateFile', 'RenameFile', 'ErrorCodes']
|
||||
}
|
||||
})
|
||||
],
|
||||
|
@ -61,6 +61,21 @@ export class Ctx {
|
||||
pushCleanup(d: { dispose(): any }) {
|
||||
this.extCtx.subscriptions.push(d);
|
||||
}
|
||||
|
||||
async sendRequestWithRetry<R>(method: string, param: any): Promise<R> {
|
||||
await this.client.onReady();
|
||||
const nRetries = 3;
|
||||
for (let triesLeft = nRetries; ; triesLeft--) {
|
||||
try {
|
||||
return await this.client.sendRequest(method, param);
|
||||
} catch (e) {
|
||||
if (e.code === lc.ErrorCodes.ContentModified && triesLeft > 0) {
|
||||
continue;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type Cmd = (...args: any[]) => any;
|
||||
|
@ -5,8 +5,6 @@ import { Ctx } from './ctx';
|
||||
|
||||
export function activateInlayHints(ctx: Ctx) {
|
||||
const hintsUpdater = new HintsUpdater(ctx);
|
||||
console.log('activateInlayHints');
|
||||
|
||||
vscode.window.onDidChangeVisibleTextEditors(async _ => {
|
||||
await hintsUpdater.refresh();
|
||||
}, ctx.subscriptions);
|
||||
@ -69,7 +67,6 @@ class HintsUpdater {
|
||||
|
||||
private async refreshEditor(editor: vscode.TextEditor): Promise<void> {
|
||||
const newHints = await this.queryHints(editor.document.uri.toString());
|
||||
|
||||
const newDecorations = (newHints ? newHints : []).map(hint => ({
|
||||
range: hint.range,
|
||||
renderOptions: {
|
||||
@ -101,9 +98,7 @@ class HintsUpdater {
|
||||
const request: InlayHintsParams = {
|
||||
textDocument: { uri: documentUri },
|
||||
};
|
||||
await this.ctx.client.onReady();
|
||||
|
||||
return this.ctx.client.sendRequest<InlayHint[] | null>(
|
||||
return this.ctx.sendRequestWithRetry<InlayHint[] | null>(
|
||||
'rust-analyzer/inlayHints',
|
||||
request,
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user