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