Fix crash when activating code completion item
Reapplying to master, somehow got lost in merge commit 49e2e165c17dc108113d4c7e0c8144b6d37ea031
(cherry picked from commit 8e3304857aad1f7e84c61fa9ec1877ea26b9dc5c)