See https://github.com/microsoft/qsharp/pull/1863#discussion_r1723657101 for more context -- there's some difficult-to-follow code in completions.rs.