1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 02:37:42 +00:00

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.
This commit is contained in:
Andreas Kling 2020-10-29 23:19:56 +01:00
parent d28127c807
commit 18739ba87e

View file

@ -64,9 +64,11 @@ Optional<size_t> AutoComplete::token_in_position(const Vector<Cpp::Token>& 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;
}