Skip to content

inlay hints broken #12066

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
swq123459 opened this issue Apr 23, 2022 · 30 comments
Closed

inlay hints broken #12066

swq123459 opened this issue Apr 23, 2022 · 30 comments
Labels
A-inlay-hints inlay/inline hints C-support Category: support questions

Comments

@swq123459
Copy link

rust-analyzer version: (eg. output of "Rust Analyzer: Show RA Version" command)
rust-analyzer version: 24cf957 2022-04-22 dev
rustc version: (eg. output of rustc -V)
rustc 1.60.0 (7737e0b5c 2022-04-04)
relevant settings: (eg. client settings, or environment variables like CARGO, RUSTUP_HOME or CARGO_HOME)

@swq123459
Copy link
Author

swq123459 commented Apr 23, 2022

INFO [4/23/2022, 11:30:01 PM]: Extension version: 0.2.1022
INFO [4/23/2022, 11:30:01 PM]: Using configuration {
  cargoRunner: null,
  runnableEnv: null,
  inlayHints: {
    enable: true,
    renderColons: true,
    maxLength: 25,
    parameterHints: true,
    typeHints: true,
    chainingHints: true,
    closureReturnTypeHints: false,
    reborrowHints: false,
    lifetimeElisionHints: { enable: 'never', useParameterNames: false },
    hideNamedConstructorHints: false
  },
  server: { path: '/usr/local/cargo/bin/rust-analyzer', extraEnv: null },
  trace: { server: 'off', extension: false },
  debug: {
    engine: 'auto',
    sourceFileMap: {
      '/rustc/<id>': '${env:USERPROFILE}/.rustup/toolchains/<toolchain-id>/lib/rustlib/src/rust'
    },
    openDebugPane: false,
    engineSettings: {}
  },
  assist: {
    exprFillDefault: 'todo',
    importGranularity: 'crate',
    importEnforceGranularity: false,
    importPrefix: 'plain',
    importGroup: true,
    allowMergingIntoGlobImports: true
  },
  cache: { warmup: true },
  callInfo: { full: true },
  cargo: {
    autoreload: true,
    allFeatures: false,
    unsetTest: [ 'core' ],
    features: [],
    runBuildScripts: true,
    runBuildScriptsCommand: null,
    useRustcWrapperForBuildScripts: true,
    noDefaultFeatures: false,
    target: null,
    noSysroot: false
  },
  checkOnSave: {
    enable: true,
    allFeatures: null,
    allTargets: true,
    command: 'clippy',
    noDefaultFeatures: null,
    target: null,
    extraArgs: [],
    features: null,
    overrideCommand: null
  },
  completion: {
    addCallArgumentSnippets: true,
    addCallParenthesis: true,
    snippets: {
      'Arc::new': {
        postfix: 'arc',
        body: 'Arc::new(${receiver})',
        requires: 'std::sync::Arc',
        description: 'Put the expression into an `Arc`',
        scope: 'expr'
      },
      'Rc::new': {
        postfix: 'rc',
        body: 'Rc::new(${receiver})',
        requires: 'std::rc::Rc',
        description: 'Put the expression into an `Rc`',
        scope: 'expr'
      },
      'Box::pin': {
        postfix: 'pinbox',
        body: 'Box::pin(${receiver})',
        requires: 'std::boxed::Box',
        description: 'Put the expression into a pinned `Box`',
        scope: 'expr'
      },
      Ok: {
        postfix: 'ok',
        body: 'Ok(${receiver})',
        description: 'Wrap the expression in a `Result::Ok`',
        scope: 'expr'
      },
      Err: {
        postfix: 'err',
        body: 'Err(${receiver})',
        description: 'Wrap the expression in a `Result::Err`',
        scope: 'expr'
      },
      Some: {
        postfix: 'some',
        body: 'Some(${receiver})',
        description: 'Wrap the expression in an `Option::Some`',
        scope: 'expr'
      }
    },
    postfix: { enable: true },
    autoimport: { enable: true },
    autoself: { enable: true },
    privateEditable: { enable: false }
  },
  diagnostics: {
    enable: true,
    enableExperimental: false,
    disabled: [],
    remapPrefix: {},
    warningsAsHint: [],
    warningsAsInfo: []
  },
  experimental: { procAttrMacros: true },
  files: { watcher: 'client', excludeDirs: [] },
  highlightRelated: {
    references: true,
    exitPoints: true,
    breakPoints: true,
    yieldPoints: true
  },
  highlighting: { strings: true },
  hover: { documentation: true, linksInHover: true },
  hoverActions: {
    debug: true,
    enable: true,
    gotoTypeDef: true,
    implementations: true,
    references: false,
    run: true
  },
  joinLines: {
    joinElseIf: true,
    removeTrailingComma: true,
    unwrapTrivialBlock: true,
    joinAssignments: true
  },
  lens: {
    debug: true,
    enable: true,
    implementations: true,
    run: true,
    methodReferences: false,
    references: false,
    enumVariantReferences: false,
    forceCustomCommands: true
  },
  linkedProjects: [],
  lruCapacity: null,
  notifications: { cargoTomlNotFound: true },
  primeCaches: { numThreads: 0 },
  procMacro: { enable: true, server: null, ignored: {} },
  runnables: { overrideCargo: null, cargoExtraArgs: [] },
  rustcSource: null,
  rustfmt: {
    extraArgs: [],
    overrideCommand: null,
    enableRangeFormatting: false
  },
  workspace: {
    symbol: { search: { scope: 'workspace', kind: 'only_types', limit: 128 } }
  },
  updates: { channel: 'nightly', askBeforeDownload: false }
}

@Veykril
Copy link
Member

Veykril commented Apr 23, 2022

Is editor.inlayHints.enabled set to true? and are other features in the files working like completions and hovering?

@lnicola
Copy link
Member

lnicola commented Apr 23, 2022

And which Code version are you using?

@swq123459
Copy link
Author

swq123459 commented Apr 24, 2022

》 code -v
1.66.2
dfd34e8260c270da74b5c2d86d61aee4b6d56977
x64

@swq123459
Copy link
Author

editor.inlayHints.enabled was set to true

@lnicola
Copy link
Member

lnicola commented Apr 24, 2022

You're on an old commit, you should pull and recompile it. Or better, you can remove rust-analyzer.server.path from your settings and use the bundled binary.

@lnicola lnicola added the C-support Category: support questions label Apr 25, 2022
@Veykril Veykril added the A-inlay-hints inlay/inline hints label Apr 25, 2022
@swq123459
Copy link
Author

I use the latest version, and it work when editor.inlayHints.enabled = true, but when use command Toggle inlay hints, I
saw editor.inlayHints.enabled = false was set in settings.json and I can never see inlay hint whatever I Toggle inlay hints from then on

@swq123459
Copy link
Author

i.e. when "editor.inlayHints.enabled": false, inlay hints can not be enable anymore

@EdJoPaTo
Copy link

For me only inlay hints are broken, the rest works fine.

Or better, you can remove rust-analyzer.server.path from your settings and use the bundled binary.

Removing the line from the settings fixes the problem but seems inconvenient to me. I do like having rust-analyzer being managed by a package manager so its installed and updated without the need to open VSCode.
Your comment suggests that using an external rust-analyzer isn't even supported, is that option a deprecated legacy option then?

I installed the extension from the default open registry for Arch Linux Code package which is already 4 months old (0.2.853) while rust-analyzer updates weekly. Switching to the Microsoft Repositories (which can be done with installing code-marketplace from the AUR) the newest version of rust-analyzer (0.2.1030) is installed which also does not show inlay hints with the external language server. Interestingly when using the bundled rust-analyzer the inlay hints also don't work then which indicates some bug in the new version of the server (which was also used with the older version of the extension).

For now I'll use the old extension version with the bundled server as that worked until there is a better/newer working solution.

@Sheepyhead
Copy link

Sheepyhead commented May 3, 2022

I have this issue as well, I didn't have "editor.inlayHints.enabled": false in my settings anywhere and adding it doesn't seem to change anything. I can confirm that the break seems to happen between revision 5fae65d and 5e85158 or between changelogs 119 and 120, and I suspect it's related to "#11445, #11647, #11658 BREAKING: switch to upstream inlay hints (requires Code 1.65)". My vscode version is 1.66.2 and I'm on Windows 10. I've been building rust-analyzer from source and using the server path option to point to my compiled binary.

This feature seems to be broken entirely for me, with the only option to fix it being to revert to an older version of rust-analyzer (such as the one packaged with the vscode extension as suggested by @lnicola ), but obviously this isn't acceptable as this issue will eventually be released with the plugin.

Edit: For reference neither "rust-analyzer.inlayHints.enable": true or "editor.inlayHints.enabled": true seem to change anything, even when used in conjunction

@lnicola
Copy link
Member

lnicola commented May 3, 2022

the only option to fix it being to revert to an older version of rust-analyzer (such as the one packaged with the vscode extension as suggested

@Sheepyhead I'm not sure why the bundled version would be older. And how are you building and installing RA?

@Sheepyhead
Copy link

the only option to fix it being to revert to an older version of rust-analyzer (such as the one packaged with the vscode extension as suggested

@Sheepyhead I'm not sure why the bundled version would be older. And how are you building and installing RA?

You don't normally release directly from latest, normally you release stable versions. I'm building by cloning the repo and running cargo build --release, and installing by using the server path option to point to my compiled server binary.

However, looking at what output I get in vscode I do get this error message

WARN [3.5.2022 12.03.53]: LSP request failed {
method: 'rust-analyzer/inlayHints',
param: { textDocument: { uri: 'file:///d%3A/repo/ra-test/src/main.rs' } },
error: [$i [Error]: unknown request
at Gt (c:\Users\Sheepyhead.vscode\extensions\matklad.rust-analyzer-0.4.0-dev\out\main.js:4:223)
at rn (c:\Users\Sheepyhead.vscode\extensions\matklad.rust-analyzer-0.4.0-dev\out\main.js:3:6520)
at Immediate. (c:\Users\Sheepyhead.vscode\extensions\matklad.rust-analyzer-0.4.0-dev\out\main.js:3:6373)
at processImmediate (node:internal/timers:464:21)] {
code: -32601,
data: undefined
}
}

@Sheepyhead
Copy link

I figured it out! This change also requires you to rerun cargo xtask install to update the extension itself! First time I've run into that issue, but I guess this explains it

@lnicola
Copy link
Member

lnicola commented May 3, 2022

You don't normally release directly from latest, normally you release stable versions.

We release nightlies every night (in UTC) and the one from Sunday/Monday gets promoted to a stable release. You can opt into the nightlies using this option:

image

This change also requires you to rerun cargo xtask install to update the extension itself!

Yeah, you should always use cargo xtask install, but TBH using the pre-built one will avoid these issues.

@lnicola
Copy link
Member

lnicola commented May 3, 2022

For anyone running into this, the smoking gun is the method name. It went through three iterations:

  • rust-analyzer/inlayHints
  • experimental/inlayHints
  • textDocument/inlayHint

If you're getting an error about one of the first two, your Code extension is too old. If you're getting an error about the last one, your LSP server is too old.

@lnicola lnicola closed this as completed May 3, 2022
@lnicola lnicola reopened this May 3, 2022
@lnicola
Copy link
Member

lnicola commented May 4, 2022

@EdJoPaTo

Removing the line from the settings fixes the problem but seems inconvenient to me.
Your comment suggests that using an external rust-analyzer isn't even supported, is that option a deprecated legacy option then?

It is supported as long as the rust-analyzer matches the client implementation you're using. For VS Code, it means they should be built from the same commit.

Using different versions of them usually works, inlay hints just happened to be a high-profile feature which saw some significant changes in a short amount of time.

The option itself is not a deprecated or legacy one, and has its uses, like allowing the usage of a custom-built server on platforms where we don't have official binaries. For mainstream platforms, the Code extension already has a compatible server, and you should probably be using it.

Interestingly when using the bundled rust-analyzer the inlay hints also don't work then which indicates some bug in the new version of the server (which was also used with the older version of the extension).

Which version of VS Code are you using?

@lnicola
Copy link
Member

lnicola commented May 4, 2022

@swq123459

i.e. when "editor.inlayHints.enabled": false, inlay hints can not be enable anymore

Are you sure that the setting doesn't change? Note that we're trying to set it per-language, so it can show up twice in the settings JSON.

There's another issue where the hints don't work immediately after toggling them. You need to type a character or switch files. Maybe you're seeing the same problem?

@swq123459
Copy link
Author

@lnicola setting (unique) can be change when toggle inlayHints, but inlayHints no work

@lnicola
Copy link
Member

lnicola commented May 4, 2022

@swq123459 what if you type something after re-enabling them?

@swq123459
Copy link
Author

nothing happen

@swq123459
Copy link
Author

swq123459 commented May 4, 2022

Is it related to my running dev container?

@lnicola
Copy link
Member

lnicola commented May 4, 2022

I'm not sure. Do they come back after you restart Code?

Maybe we're toggling the local setting instead of the remote one? I don't really remember how these work.

@swq123459
Copy link
Author

when I reload vscode, it work again. After that, when I toggle inlayhint or switch editor.inlayHints.enabled: false(true->false->true) manually, it broken

@Veykril
Copy link
Member

Veykril commented May 4, 2022

We do toggle the setting properly, but it seems if we toggle the hints back on via the command they flicker for a very short time and then disappear again. They do come back after some time for me though, so this feels like it might be a VSCode issue or an issue with how we update the setting?

Edit: For me they come back if I scroll my editor.

@EdJoPaTo
Copy link

EdJoPaTo commented May 4, 2022

@lnicola Thanks for clarifying!

Which version of VS Code are you using?

1.66.0 packaged by Arch Linux

@lnicola
Copy link
Member

lnicola commented May 4, 2022

@Veykril that's #12027, but @swq123459 seems to have a different issue.

@EdJoPaTo I suppose you mean 1.66?

@swq123459
Copy link
Author

@Veykril

Edit: For me they come back if I scroll my editor.

For I work again when I switch my view. lol
more

@lnicola
Copy link
Member

lnicola commented May 5, 2022

@swq123459 sounds like #12027

@EdJoPaTo when you have time can you try to comment out rust-analyzer.server.path and install a VSIX from https://github.com/rust-analyzer/rust-analyzer/releases? I'm not sure why inlay hints aren't working for you.

@EdJoPaTo
Copy link

EdJoPaTo commented May 5, 2022

My currently installed rust-analyzer version is 20220502-1 (via pacman).

tldr: I tried the following and inline hints worked:

  • rust-analyzer-no-server.vsix (2022-05-02) with serverPath
  • rust-analyzer-linux-x64.vsix (2022-05-02) with serverPath
  • rust-analyzer-linux-x64.vsix (2022-05-02) without serverPath
  • 0.2.1040 via the Microsoft extension store with serverPath
  • 0.2.1040 via the Microsoft extension store without serverPath
  • 0.2.1030 via the Microsoft extension store with serverPath
  • 0.2.1030 via the Microsoft extension store without serverPath

rust-analyzer-no-server.vsix (2022-05-02) without serverPath did not work (stating there is no binary for my platform, understandably as its a no-server build).

Even 0.2.1030 which didnt worked last time worked today. No clue what caused that then.

@lnicola
Copy link
Member

lnicola commented May 5, 2022

@EdJoPaTo okay, so it seems fixed for you. Thanks for the comprehensive testing.

@swq123459 let's close this to keep things tidy.

@lnicola lnicola closed this as completed May 5, 2022
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 C-support Category: support questions
Projects
None yet
Development

No branches or pull requests

5 participants