I'm trying to divide my list of theorems by chapter, similar to what is done in here. I'm using the thmtools package, and I'm quite close of getting it to work. I've used the following code from the link I posted:
\documentclass[a4paper]{book}
\usepackage{amsthm,thmtools}
\usepackage{xcolor}
\usepackage{framed}
\colorlet{shadecolor}{lightgray!25}
\newtheorem{thm}{Theorem}[chapter]
\newtheoremstyle{definitionsty}{3pt}{3pt}{\slshape}{}{\bfseries}{.}{.5em}{}
\theoremstyle{definitionsty}
\newtheorem{tdefn}{Definition}[chapter]
\newenvironment{defn}
{\begin{shaded}\begin{tdefn}}
{\end{tdefn}\end{shaded}}
\usepackage{etoolbox}
\makeatletter
\patchcmd\thmtlo@chaptervspacehack
{\addtocontents{loe}{\protect\addvspace{10\p@}}}
{\addtocontents{loe}{\protect\thmlopatch@endchapter\protect\thmlopatch@chapter{\thechapter}}}
{}{}
\AtEndDocument{\addtocontents{loe}{\protect\thmlopatch@endchapter}}
\long\def\thmlopatch@chapter#1#2\thmlopatch@endchapter{%
\setbox\z@=\vbox{#2}%
\ifdim\ht\z@>\z@
\hbox{\bfseries\chaptername\ #1}\nobreak
#2
\addvspace{10\p@}
\fi
}
\def\thmlopatch@endchapter{}
\makeatother
\renewcommand{\thmtformatoptarg}[1]{ -- #1}
\renewcommand{\listtheoremname}{List of definitions}
\begin{document}
\frontmatter
\listoftheorems[ignoreall,show={tdefn}]
\mainmatter
\chapter{X}
\begin{defn}[My hilarious definition]
bla bla
\end{defn}
\chapter{Y}
\begin{thm}
b
\end{thm}
\chapter{Z}
\begin{defn}[My hilarious definition 2]
bla bla
\end{defn}
\begin{thm}
a
\end{thm}
\end{document}
The only "problem" with this solution is that I'd like to have the full chapter name, not only the number. How does one modify this code in order to achieve this? I've tried tweaking this code by my-self, but I was not able to get it working.

\thmtlo@chaptervspacehackdoesn't have access to the chapter name. It is called by every theorem and checks for changes in the chapter counter. The advantage of this approach is that chapters without theorems don't get listed. You also need to hack\@chapterto store the title (#1 short, #2 long) into a global macro. – John Kormylo Oct 26 '21 at 01:44