[clangd] Dex Trigrams: Improve query trigram generation
authorKirill Bobyrev <kbobyrev@google.com>
Tue, 7 Dec 2021 14:46:12 +0000 (15:46 +0100)
committerKirill Bobyrev <kbobyrev@google.com>
Tue, 7 Dec 2021 14:46:13 +0000 (15:46 +0100)
commit976a74d7d2dbd19670614f603caf490cca892fdc
tree5cb43f7c7e99a3cc2c92c765bb702058169f8ca3
parent9094a2285bfc7f7f418e47bb23244078a0ffb165
[clangd] Dex Trigrams: Improve query trigram generation

These are the trigrams for queries right now:

- "va" -> {Trigram("va")}
- "va_" -> {} (empty)

This is suboptimal since the resulting query will discard the query information
and return all symbols, some of which will be later be scored expensively
(fuzzy matching score). This is related to
https://github.com/clangd/clangd/issues/39 but does not fix it. Accidentally,
because of that incorrect behavior, when user types "tok::va" there are no
results (the issue is that `tok::kw___builtin_va_arg` does not have "va" token)
but when "tok::va_" is typed, expected result (`tok::kw___builtin_va_arg`)
shows up by accident. This is because the dex query transformer will only
lookup symbols within the `tok::` namespace. There won't be many, so the
returned results will contain symbol we need; this symbol will be filtered out
by the expensive checks and that will be displayed in the editor.

Reviewed By: sammccall

Differential Revision: https://reviews.llvm.org/D113995
clang-tools-extra/clangd/index/dex/Trigram.cpp
clang-tools-extra/clangd/unittests/DexTests.cpp