[clangd] Fix division by zero when computing scores
authorKadir Cetinkaya <kadircet@google.com>
Fri, 15 Jan 2021 10:12:11 +0000 (11:12 +0100)
committerKadir Cetinkaya <kadircet@google.com>
Wed, 20 Jan 2021 11:50:25 +0000 (12:50 +0100)
commita1d4649a5b176bf826685cac5cc4416b6498bdf9
tree8711addec797fec5fa4ef734251f09101b620f40
parentf07403eb1a5f781b1bcc2b0c18ef7f632e1a0fdc
[clangd] Fix division by zero when computing scores

NameMatch could be a float close to zero, in such cases we were
dividing by zero and moreover propogating a "NaN" to clients, which is invalid
per JSON.

This fixes the issue by only using Quality scores whenever the NameMatch is low,
as we do in CodeCompletion ranking.

Fixes https://github.com/clangd/clangd/issues/648.

Differential Revision: https://reviews.llvm.org/D94755
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/FindSymbols.cpp