Skip to content

Request textDocument/inlayHint failed #13372

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

Closed
RalfJung opened this issue Oct 9, 2022 · 8 comments · Fixed by #14359
Closed

Request textDocument/inlayHint failed #13372

RalfJung opened this issue Oct 9, 2022 · 8 comments · Fixed by #14359
Labels
A-inlay-hints inlay/inline hints Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug

Comments

@RalfJung
Copy link
Member

RalfJung commented Oct 9, 2022

When working in rustc, I often see an error pop up in the corner which says "Request textDocument/inlayHint failed". I am not entirely sure how to reproduce this, or what it even is talking about. The pop up has a "show output" button, and when I press that button I see a log which ends in

[Error - 11:55:04 AM] Request textDocument/inlayHint failed.
  Message: Invalid offset
  Code: -32603 

I think I also saw this in Miri, but I am not entirely sure about that.

rust-analyzer version: rust-analyzer version: 0.3.1221-standalone

rustc version: rustc 1.66.0-nightly (c97d02cdb 2022-10-05)

relevant settings:
user settings

    "rust-analyzer.lens.enable": false,
    "rust-analyzer.cachePriming.enable": false,
    "rust-analyzer.cargo.buildScripts.useRustcWrapper": false,
    "rust-analyzer.cargo.buildScripts.enable": true,
    "rust-analyzer.procMacro.enable": true,
    //
    "rust-analyzer.diagnostics.disabled": [
        "unlinked-file", // I guess for "normal" projects unlinked files are strange, for me they are common
        "unresolved-module", // https://github.com/rust-lang/rust-analyzer/issues/9173
        "unresolved-extern-crate", // https://github.com/rust-lang/rust-analyzer/issues/12926
        "type-mismatch", // https://github.com/rust-lang/rust-analyzer/issues/1109
    ],

workspace settings

    "rust-analyzer.rustc.source": "./Cargo.toml",
    "rust-analyzer.linkedProjects": [
        "./Cargo.toml",
    ],
    "rust-analyzer.checkOnSave.overrideCommand": [
        "./x.py",
        "check",
        "--json-output",
        "library/std",
    ],
    "rust-analyzer.rustfmt.overrideCommand": [
        "./build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt",
        "--edition=2021"
    ],
    "rust-analyzer.cargo.buildScripts.overrideCommand": ["false"],
    "rust-analyzer.cargo.buildScripts.enable": false,
    "rust-analyzer.procMacro.enable": false,
@Veykril
Copy link
Member

Veykril commented Oct 9, 2022

This is caused by our inlay hint resolve payload not being "versioned", that is a client might ask for a resolve of an inlay hint and change the text content right after/before such that r-a tries to resolve the inlay hint on a different document version.

@Veykril Veykril added Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug labels Oct 9, 2022
@Veykril Veykril added the A-inlay-hints inlay/inline hints label Nov 4, 2022
@matklad
Copy link
Member

matklad commented Nov 4, 2022

that is a client might ask for a resolve of an inlay hint and change the text content right after/before such that r-a tries to resolve the inlay hint on a different document version.

To properly assign the blame here, the client is right. For "two-phase lookups" with resolve, it is in genera not possible to guarantee that there are no intervening changes which would invalidated the lookup. That's why:

  • for resolve, it is preferable to use ids resilient to changes (eg, for code actions we use name of the action, not the position in the action list)
  • even with resilient ids, this can fail, which should return a null result to the client, it definietly shouldn't crash (well, we should never crash, but we could be bit obnoxious about the clients in the wrong, but in this case this is a totally normal operation)

@Veykril
Copy link
Member

Veykril commented Nov 7, 2022

Turns out what I wrote here is a different issue, #13170 is the issue that I was describing. Whats happening here I think is that we get an inlay hints request, then the client sends a document changed notification causing us to cancel the inlay hints request, change the docs and then retry the inlay hints request, now with outdated document positions ... So our request retrying breaks down hmm ...

bors added a commit that referenced this issue Nov 29, 2022
…a, r=jonas-schievink

internal: Version the inlay hint resolve data

cc #13657
cc #13372
cc #13170

This will make us log an error and return the unmodified inlay hints when the client attempts to resolve inlay hints in a file that has since been modified.
bors added a commit that referenced this issue Nov 29, 2022
…a, r=jonas-schievink

internal: Version the inlay hint resolve data

cc #13657
cc #13372
cc #13170

This will make us log an error and return the unmodified inlay hints when the client attempts to resolve inlay hints in a file that has since been modified.
@Doomwhite
Copy link

Doomwhite commented Feb 4, 2023

I have the same problem even with basic code in Bevy:

use bevy::{ecs::system::Commands, prelude::*};

#[derive(Component)]
struct Person;

#[derive(Component)]
struct Name(String);

fn main() {
    App::new()
        .add_plugins(DefaultPlugins)
        .add_plugins(HelloPlugin)
        .run();
}

fn hello_world() {
    println!("Hello World!");
}

fn add_people(mut commands: Commands) {
    commands.spawn((Person, Name("Elaine".to_string())));
    commands.spawn((Person, Name("Renzo".to_string())));
    commands.spawn((Person, Name("Zayna".to_string())));
}

fn greet_people(query: Query<&Name, With<Person>>) {
    for name in query.iter() {
        println!("hello {}!", name.0);
    }
}

pub struct HelloPlugin;

impl Plugin for HelloPlugin {
    fn build(&self, app: &mut App) {
        app::new()
            .add_startup_system(add_people)
            .add_system(hello_world)
            .add_system(greet_people)
    }
}

Rust: 1.67.0
Rust-analyzer: v0.3.1386

@dxnxk-0
Copy link

dxnxk-0 commented Mar 10, 2023

Is there any workaround ? That popups are very annoying. Thanks,

@lnicola
Copy link
Member

lnicola commented Mar 10, 2023

@pascaldanek what's the full error you are getting, and when?

@dxnxk-0
Copy link

dxnxk-0 commented Mar 10, 2023

@lnicola it seems to be totaly random when I edit Rust code:

[Error - 18:25:22] Request textDocument/inlayHint failed.
  Message: Invalid offset
  Code: -32603 

PS: I add that since a few days my rust dev experience in vscode has become very slow for a (yet) unknown reason.

bors added a commit that referenced this issue Mar 15, 2023
fix: Do not retry inlay hint requests

Should close #13372, retrying the way its currently implemented is not ideal as we do not adjust offsets in the requests, but doing that is a major PITA, so this should at least work around one of the more annoying issues stemming from it.
@bors bors closed this as completed in adbda94 Mar 15, 2023
@ShayBox
Copy link

ShayBox commented May 23, 2023

Can this popup be removed or disabled, it's constantly getting in the way, I don't care if it fails because it took too long and got outdated information, it can retry again next save, just stop stacking popups that don't disappear on the screen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-inlay-hints inlay/inline hints Broken Window Bugs / technical debt to be addressed immediately C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants