Subject: bug#64101: 29.0.91; Eglot inlay hints rendered out of order

From: Krzysztof Klimonda <[email-masked]>
Date: Thu, 15 Jun 2023 23:23:45 +0200

When using eglot with rust-analyzer some inlay hints are not rendered
correctly. For example, in the following code snippet, inlay hint for
the `let vec =` is rendered as such:

> >>>Vec<Arc<Mutex<Item: 

and not

> : <Vec<Arc<Mutex<Item>>>

It works fine for simple hints (like `let x` in my example).

Looking at what's happening, it seems eglot is creating separate
overlays for each element of the returned `InlayHintLabelPart` with
the same beginning in the buffer. From poking around I've noticed
that overlays have been rewritten recently, and the order of overlays
for the given position no longer seems to be fixed.

Code example below:
---8<---8<---8<---
use std::sync::{Arc, Mutex};

mod static_uninit;

struct Item;

fn test() {
    let vec = vec![Arc::new(Mutex::new(Item))];
    let x = 1;
}
---8<---8<---8<---

In GNU Emacs 29.0.91 (build 1, x86_64-apple-darwin22.3.0, NS
appkit-2299.40 Version 13.2.1 (Build 22D68)) of 2023-06-11 built on
sapphire.local
Windowing system distributor 'Apple', version 10.3.2299
System Description:  macOS 13.2.1

Configured using:
'configure --disable-dependency-tracking --disable-silent-rules
--enable-locallisppath=/usr/local/share/emacs/site-lisp
--infodir=/usr/local/Cellar/emacs-plus@29/29.0.90/share/info/emacs
--prefix=/usr/local/Cellar/emacs-plus@29/29.0.90 --with-xml2
--with-gnutls --with-native-compilation --without-compress-install
--without-dbus --without-imagemagick --with-modules --with-rsvg
--with-ns --disable-ns-self-contained 'CFLAGS=-Os -w -pipe
-march=nehalem -mmacosx-version-min=13
-isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk
-DFD_SETSIZE=10000 -DDARWIN_UNLIMITED_SELECT'
'CPPFLAGS=-I/usr/local/opt/zlib/include -I/usr/local/opt/jpeg/include
-I/usr/local/opt/icu4c/include -I/usr/local/opt/[email-masked]/include
-F/usr/local/Frameworks
-isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk'
'LDFLAGS=-L/usr/local/opt/zlib/lib -L/usr/local/opt/jpeg/lib
-L/usr/local/opt/icu4c/lib -L/usr/local/opt/[email-masked]/lib
-L/usr/local/lib -F/usr/local/Frameworks
-Wl,-headerpad_max_install_names
-isysroot/Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk
-L/usr/local/opt/libgccjit/lib''

Configured features:
ACL GIF GLIB GMP GNUTLS JPEG JSON LCMS2 LIBXML2 MODULES NATIVE_COMP
NOTIFY KQUEUE NS PDUMPER PNG RSVG SQLITE3 THREADS TIFF
TOOLKIT_SCROLL_BARS TREE_SITTER WEBP XIM ZLIB

Important settings:
  value of $LC_CTYPE: UTF-8
  value of $LANG: en_US.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Rust

Minor modes in effect:
  shell-dirtrack-mode: t
  eglot-inlay-hints-mode: t
  eglot--managed-mode: t
  flymake-mode: t
  tooltip-mode: t
  global-eldoc-mode: t
  eldoc-mode: t
  show-paren-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  line-number-mode: t
  indent-tabs-mode: t
  transient-mark-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t

Load-path shadows:
None found.

Features:
(shadow sort mail-extr emacsbug message mailcap yank-media puny dired
dired-loaddefs rfc822 mml mml-sec epa derived epg rfc6068 epg-config
gnus-util mm-decode mm-bodies mm-encode mail-parse rfc2231 mailabbrev
gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums mm-util
mail-prsvr mail-utils misearch multi-isearch pulse color rust-ts-mode
c-ts-common treesit etags fileloop generator time-date shell pcomplete
eglot external-completion array filenotify jsonrpc ert pp ewoc debug
backtrace find-func xref flymake-proc flymake thingatpt compile
text-property-search comint ansi-osc ansi-color ring pcase url-util
url-parse auth-source eieio eieio-core password-cache json map url-vars
project byte-opt imenu vc-git diff-mode easy-mmode vc-dispatcher
cl-loaddefs comp comp-cstr warnings icons subr-x rx cl-seq cl-macs gv
cl-extra help-mode bytecomp byte-compile cl-lib rmc iso-transl tooltip
cconv eldoc paren electric uniquify ediff-hook vc-hooks lisp-float-type
elisp-mode mwheel term/ns-win ns-win ucs-normalize mule-util
term/common-win tool-bar dnd fontset image regexp-opt fringe
tabulated-list replace newcomment text-mode lisp-mode prog-mode register
page tab-bar menu-bar rfn-eshadow isearch easymenu timer select
scroll-bar mouse jit-lock font-lock syntax font-core term/tty-colors
frame minibuffer nadvice seq simple cl-generic indonesian philippine
cham georgian utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao
korean japanese eucjp-ms cp51932 hebrew greek romanian slovak czech
european ethiopic indian cyrillic chinese composite emoji-zwj charscript
charprop case-table epa-hook jka-cmpr-hook help abbrev obarray oclosure
cl-preloaded button loaddefs theme-loaddefs faces cus-face macroexp
files window text-properties overlay sha1 md5 base64 format env
code-pages mule custom widget keymap hashtable-print-readable backquote
threads kqueue cocoa ns lcms2 multi-tty make-network-process
native-compile emacs)

Memory information:
((conses 16 161413 14006)
(symbols 48 12244 0)
(strings 32 41810 3481)
(string-bytes 1 1383853)
(vectors 16 31896)
(vector-slots 8 582797 14839)
(floats 8 140 71)
(intervals 56 375 0)
(buffers 984 22))