[clangd] Add instrumentation mode in clangd for metrics collection.
authorUtkarsh Saxena <usx@google.com>
Wed, 4 Mar 2020 12:25:02 +0000 (13:25 +0100)
committerUtkarsh Saxena <usx@google.com>
Thu, 5 Mar 2020 11:39:15 +0000 (12:39 +0100)
commite397a0a5c3c0fa1912fbac23b550fa7d239196ba
tree4383914096a12a449035ea2af8869fffa9effb77
parentef38283a0980c0ca3d4e866eceec189807eec7f9
[clangd] Add instrumentation mode in clangd for metrics collection.

Summary:
This patch adds an instrumentation mode for clangd (enabled by
corresponding option in cc_opts).
If this mode is enabled then user can specify callbacks to run on the
final code completion result.

Moreover the CodeCompletion::Score will contain the detailed Quality and
Relevance signals used to compute the score when this mode is enabled.
These are required because we do not any place in which the final
candidates (scored and sorted) are available along with the above
signals. The signals are temporary structures in `addCandidate`.

The callback is needed as it gives access to many data structures that
are internal to CodeCompleteFlow and are available once Sema has run. Eg:
ScopeDistnace and FileDistance.

If this mode is disabled (as in default) then Score would just contain 2
shared pointers (null). Thus cost(memory/time) increase for the default
mode would be fairly cheap and insignificant.

Reviewers: sammccall

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D75603
clang-tools-extra/clangd/CodeComplete.cpp
clang-tools-extra/clangd/CodeComplete.h
clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp