From 18739ba87e25aad5c492a0ebcef44039d6a4c790 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 29 Oct 2020 23:19:56 +0100 Subject: [PATCH] LanguageServers/Cpp: Find the right token under the cursor When the cursor is immediately to the right of a token, the cursor's column will be token.end.column + 1, so take this into account when choosing which token to autocomplete. --- DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.cpp b/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.cpp index 86c445b8c2..90d48756d6 100644 --- a/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.cpp +++ b/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.cpp @@ -64,9 +64,11 @@ Optional AutoComplete::token_in_position(const Vector& token { for (size_t token_index = 0; token_index < tokens.size(); ++token_index) { auto& token = tokens[token_index]; + if (token.m_start.line != token.m_end.line) + continue; if (token.m_start.line != position.line()) continue; - if (token.m_start.column > position.column() || token.m_end.column < position.column()) + if (token.m_start.column + 1 > position.column() || token.m_end.column + 1 < position.column()) continue; return token_index; }