2019-03-01 17:52:53 +08:00
|
|
|
//===-- QualityTests.cpp ----------------------------------------*- C++ -*-===//
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Evaluating scoring functions isn't a great fit for assert-based tests.
|
|
|
|
// For interesting cases, both exact scores and "X beats Y" are too brittle to
|
|
|
|
// make good hard assertions.
|
|
|
|
//
|
|
|
|
// Here we test the signal extraction and sanity-check that signals point in
|
|
|
|
// the right direction. This should be supplemented by quality metrics which
|
|
|
|
// we can compute from a corpus of queries and preferred rankings.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2018-07-03 16:09:29 +08:00
|
|
|
#include "FileDistance.h"
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
#include "Quality.h"
|
2018-06-15 16:58:12 +08:00
|
|
|
#include "TestFS.h"
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
#include "TestTU.h"
|
2018-07-05 16:14:04 +08:00
|
|
|
#include "clang/AST/Decl.h"
|
|
|
|
#include "clang/AST/DeclCXX.h"
|
2018-07-24 16:51:52 +08:00
|
|
|
#include "clang/AST/Type.h"
|
2018-07-23 18:56:37 +08:00
|
|
|
#include "clang/Sema/CodeCompleteConsumer.h"
|
2018-07-05 16:14:04 +08:00
|
|
|
#include "llvm/Support/Casting.h"
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
#include "gmock/gmock.h"
|
|
|
|
#include "gtest/gtest.h"
|
2018-10-17 19:19:02 +08:00
|
|
|
#include <vector>
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
|
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
2018-06-15 16:58:12 +08:00
|
|
|
|
|
|
|
// Force the unittest URI scheme to be linked,
|
|
|
|
static int LLVM_ATTRIBUTE_UNUSED UnittestSchemeAnchorDest =
|
|
|
|
UnittestSchemeAnchorSource;
|
|
|
|
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
TEST(QualityTests, SymbolQualitySignalExtraction) {
|
|
|
|
auto Header = TestTU::withHeaderCode(R"cpp(
|
2018-06-08 17:36:34 +08:00
|
|
|
int _X;
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
|
|
|
|
[[deprecated]]
|
2018-06-08 17:36:34 +08:00
|
|
|
int _f() { return _X; }
|
2018-10-18 20:23:05 +08:00
|
|
|
|
|
|
|
#define DECL_NAME(x, y) x##_##y##_Decl
|
|
|
|
#define DECL(x, y) class DECL_NAME(x, y) {};
|
|
|
|
DECL(X, Y); // X_Y_Decl
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
)cpp");
|
2018-10-18 20:23:05 +08:00
|
|
|
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
auto Symbols = Header.headerSymbols();
|
|
|
|
auto AST = Header.build();
|
|
|
|
|
|
|
|
SymbolQualitySignals Quality;
|
2018-06-08 17:36:34 +08:00
|
|
|
Quality.merge(findSymbol(Symbols, "_X"));
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
EXPECT_FALSE(Quality.Deprecated);
|
2018-10-18 20:23:05 +08:00
|
|
|
EXPECT_FALSE(Quality.ImplementationDetail);
|
2018-06-08 17:36:34 +08:00
|
|
|
EXPECT_TRUE(Quality.ReservedName);
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
EXPECT_EQ(Quality.References, SymbolQualitySignals().References);
|
2018-06-06 16:53:36 +08:00
|
|
|
EXPECT_EQ(Quality.Category, SymbolQualitySignals::Variable);
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
|
2018-10-18 20:23:05 +08:00
|
|
|
Quality.merge(findSymbol(Symbols, "X_Y_Decl"));
|
|
|
|
EXPECT_TRUE(Quality.ImplementationDetail);
|
|
|
|
|
2018-06-08 17:36:34 +08:00
|
|
|
Symbol F = findSymbol(Symbols, "_f");
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
F.References = 24; // TestTU doesn't count references, so fake it.
|
|
|
|
Quality = {};
|
|
|
|
Quality.merge(F);
|
2018-09-07 02:52:26 +08:00
|
|
|
EXPECT_TRUE(Quality.Deprecated);
|
2018-06-08 17:36:34 +08:00
|
|
|
EXPECT_FALSE(Quality.ReservedName);
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
EXPECT_EQ(Quality.References, 24u);
|
2018-06-06 16:53:36 +08:00
|
|
|
EXPECT_EQ(Quality.Category, SymbolQualitySignals::Function);
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
|
|
|
|
Quality = {};
|
2018-06-08 17:36:34 +08:00
|
|
|
Quality.merge(CodeCompletionResult(&findDecl(AST, "_f"), /*Priority=*/42));
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
EXPECT_TRUE(Quality.Deprecated);
|
2018-06-08 17:36:34 +08:00
|
|
|
EXPECT_FALSE(Quality.ReservedName);
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
EXPECT_EQ(Quality.References, SymbolQualitySignals().References);
|
2018-06-06 16:53:36 +08:00
|
|
|
EXPECT_EQ(Quality.Category, SymbolQualitySignals::Function);
|
2018-06-14 21:42:21 +08:00
|
|
|
|
|
|
|
Quality = {};
|
|
|
|
Quality.merge(CodeCompletionResult("if"));
|
|
|
|
EXPECT_EQ(Quality.Category, SymbolQualitySignals::Keyword);
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QualityTests, SymbolRelevanceSignalExtraction) {
|
2018-06-04 22:50:59 +08:00
|
|
|
TestTU Test;
|
|
|
|
Test.HeaderCode = R"cpp(
|
2018-07-11 22:49:49 +08:00
|
|
|
int header();
|
|
|
|
int header_main();
|
|
|
|
|
|
|
|
namespace hdr { class Bar {}; } // namespace hdr
|
|
|
|
|
|
|
|
#define DEFINE_FLAG(X) \
|
|
|
|
namespace flags { \
|
|
|
|
int FLAGS_##X; \
|
|
|
|
} \
|
|
|
|
|
|
|
|
DEFINE_FLAG(FOO)
|
|
|
|
)cpp";
|
2018-06-04 22:50:59 +08:00
|
|
|
Test.Code = R"cpp(
|
2018-07-11 22:49:49 +08:00
|
|
|
using hdr::Bar;
|
2018-06-04 22:50:59 +08:00
|
|
|
|
2018-07-11 22:49:49 +08:00
|
|
|
using flags::FLAGS_FOO;
|
|
|
|
|
|
|
|
int ::header_main() {}
|
|
|
|
int main();
|
2018-06-06 00:30:25 +08:00
|
|
|
|
2018-07-11 22:49:49 +08:00
|
|
|
[[deprecated]]
|
|
|
|
int deprecated() { return 0; }
|
|
|
|
|
|
|
|
namespace { struct X { void y() { int z; } }; }
|
[clangd] Errors in TestTU cause test failures unless suppressed with error-ok.
Summary:
The historic behavior of TestTU is to gather diagnostics and otherwise ignore
them. So if a test has a syntax error, and doesn't assert diagnostics, it
silently misbehaves.
This can be annoying when developing tests, as evidenced by various tests
gaining "assert no diagnostics" where that's not really the point of the test.
This patch aims to make that default behavior. For the first error
(not warning), TestTU will call ADD_FAILURE().
This can be suppressed with a comment containing "error-ok". For now that will
suppress any errors in the TU. We can make this stricter later -verify style.
(-verify itself is hard to reuse because of DiagnosticConsumer interfaces...)
A magic-comment was chosen over a TestTU option because of table-driven tests.
In addition to the behavior change, this patch:
- adds //error-ok where we're knowingly testing invalid code
(e.g. for diagnostics, crash-resilience, or token-level tests)
- fixes a bunch of errors in the checked-in tests, mostly trivial (missing ;)
- removes a bunch of now-redundant instances of "assert no diagnostics"
Reviewers: kadircet
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D73199
2020-01-22 23:38:41 +08:00
|
|
|
struct S{};
|
2018-06-04 22:50:59 +08:00
|
|
|
)cpp";
|
|
|
|
auto AST = Test.build();
|
|
|
|
|
2018-06-05 20:22:43 +08:00
|
|
|
SymbolRelevanceSignals Relevance;
|
|
|
|
Relevance.merge(CodeCompletionResult(&findDecl(AST, "deprecated"),
|
|
|
|
/*Priority=*/42, nullptr, false,
|
|
|
|
/*Accessible=*/false));
|
|
|
|
EXPECT_EQ(Relevance.NameMatch, SymbolRelevanceSignals().NameMatch);
|
|
|
|
EXPECT_TRUE(Relevance.Forbidden);
|
2021-01-29 21:59:16 +08:00
|
|
|
EXPECT_EQ(Relevance.Scope, SymbolRelevanceSignals::GlobalScope);
|
2018-06-05 20:22:43 +08:00
|
|
|
|
|
|
|
Relevance = {};
|
|
|
|
Relevance.merge(CodeCompletionResult(&findDecl(AST, "main"), 42));
|
2018-10-17 19:19:02 +08:00
|
|
|
EXPECT_FLOAT_EQ(Relevance.SemaFileProximityScore, 1.0f)
|
|
|
|
<< "Decl in current file";
|
2018-06-05 20:22:43 +08:00
|
|
|
Relevance = {};
|
|
|
|
Relevance.merge(CodeCompletionResult(&findDecl(AST, "header"), 42));
|
2018-10-17 19:19:02 +08:00
|
|
|
EXPECT_FLOAT_EQ(Relevance.SemaFileProximityScore, 0.6f) << "Decl from header";
|
2018-06-05 20:22:43 +08:00
|
|
|
Relevance = {};
|
|
|
|
Relevance.merge(CodeCompletionResult(&findDecl(AST, "header_main"), 42));
|
2018-10-17 19:19:02 +08:00
|
|
|
EXPECT_FLOAT_EQ(Relevance.SemaFileProximityScore, 1.0f)
|
2018-06-15 16:58:12 +08:00
|
|
|
<< "Current file and header";
|
2018-06-06 00:30:25 +08:00
|
|
|
|
2018-07-11 22:49:49 +08:00
|
|
|
auto constructShadowDeclCompletionResult = [&](const std::string DeclName) {
|
|
|
|
auto *Shadow =
|
2018-11-09 20:56:49 +08:00
|
|
|
*dyn_cast<UsingDecl>(&findDecl(AST, [&](const NamedDecl &ND) {
|
|
|
|
if (const UsingDecl *Using = dyn_cast<UsingDecl>(&ND))
|
|
|
|
if (Using->shadow_size() &&
|
|
|
|
Using->getQualifiedNameAsString() == DeclName)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}))->shadow_begin();
|
2018-07-11 22:49:49 +08:00
|
|
|
CodeCompletionResult Result(Shadow->getTargetDecl(), 42);
|
|
|
|
Result.ShadowDecl = Shadow;
|
|
|
|
return Result;
|
|
|
|
};
|
|
|
|
|
|
|
|
Relevance = {};
|
|
|
|
Relevance.merge(constructShadowDeclCompletionResult("Bar"));
|
2018-10-17 19:19:02 +08:00
|
|
|
EXPECT_FLOAT_EQ(Relevance.SemaFileProximityScore, 1.0f)
|
2018-07-11 22:49:49 +08:00
|
|
|
<< "Using declaration in main file";
|
|
|
|
Relevance.merge(constructShadowDeclCompletionResult("FLAGS_FOO"));
|
2018-10-17 19:19:02 +08:00
|
|
|
EXPECT_FLOAT_EQ(Relevance.SemaFileProximityScore, 1.0f)
|
2018-07-11 22:49:49 +08:00
|
|
|
<< "Using declaration in main file";
|
|
|
|
|
2018-06-06 00:30:25 +08:00
|
|
|
Relevance = {};
|
2018-11-09 20:56:49 +08:00
|
|
|
Relevance.merge(CodeCompletionResult(&findUnqualifiedDecl(AST, "X"), 42));
|
2021-01-29 21:59:16 +08:00
|
|
|
EXPECT_EQ(Relevance.Scope, SymbolRelevanceSignals::FileScope);
|
2018-06-06 00:30:25 +08:00
|
|
|
Relevance = {};
|
2018-11-09 20:56:49 +08:00
|
|
|
Relevance.merge(CodeCompletionResult(&findUnqualifiedDecl(AST, "y"), 42));
|
2021-01-29 21:59:16 +08:00
|
|
|
EXPECT_EQ(Relevance.Scope, SymbolRelevanceSignals::ClassScope);
|
2018-06-06 00:30:25 +08:00
|
|
|
Relevance = {};
|
2018-11-09 20:56:49 +08:00
|
|
|
Relevance.merge(CodeCompletionResult(&findUnqualifiedDecl(AST, "z"), 42));
|
2021-01-29 21:59:16 +08:00
|
|
|
EXPECT_EQ(Relevance.Scope, SymbolRelevanceSignals::FunctionScope);
|
2018-06-27 19:43:54 +08:00
|
|
|
// The injected class name is treated as the outer class name.
|
|
|
|
Relevance = {};
|
|
|
|
Relevance.merge(CodeCompletionResult(&findDecl(AST, "S::S"), 42));
|
2021-01-29 21:59:16 +08:00
|
|
|
EXPECT_EQ(Relevance.Scope, SymbolRelevanceSignals::GlobalScope);
|
2018-10-24 21:45:17 +08:00
|
|
|
|
|
|
|
Relevance = {};
|
|
|
|
EXPECT_FALSE(Relevance.InBaseClass);
|
2018-11-09 20:56:49 +08:00
|
|
|
auto BaseMember = CodeCompletionResult(&findUnqualifiedDecl(AST, "y"), 42);
|
2018-10-24 21:45:17 +08:00
|
|
|
BaseMember.InBaseClass = true;
|
|
|
|
Relevance.merge(BaseMember);
|
|
|
|
EXPECT_TRUE(Relevance.InBaseClass);
|
2019-02-01 21:07:37 +08:00
|
|
|
|
|
|
|
auto Index = Test.index();
|
|
|
|
FuzzyFindRequest Req;
|
|
|
|
Req.Query = "X";
|
|
|
|
Req.AnyScope = true;
|
2019-02-02 18:35:39 +08:00
|
|
|
bool Matched = false;
|
|
|
|
Index->fuzzyFind(Req, [&](const Symbol &S) {
|
|
|
|
Matched = true;
|
|
|
|
Relevance = {};
|
|
|
|
Relevance.merge(S);
|
2021-01-29 21:59:16 +08:00
|
|
|
EXPECT_EQ(Relevance.Scope, SymbolRelevanceSignals::FileScope);
|
2019-02-02 18:35:39 +08:00
|
|
|
});
|
|
|
|
EXPECT_TRUE(Matched);
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Do the signals move the scores in the direction we expect?
|
|
|
|
TEST(QualityTests, SymbolQualitySignalsSanity) {
|
|
|
|
SymbolQualitySignals Default;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_EQ(Default.evaluateHeuristics(), 1);
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
|
|
|
|
SymbolQualitySignals Deprecated;
|
|
|
|
Deprecated.Deprecated = true;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_LT(Deprecated.evaluateHeuristics(), Default.evaluateHeuristics());
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
|
2018-06-08 17:36:34 +08:00
|
|
|
SymbolQualitySignals ReservedName;
|
|
|
|
ReservedName.ReservedName = true;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_LT(ReservedName.evaluateHeuristics(), Default.evaluateHeuristics());
|
2018-06-08 17:36:34 +08:00
|
|
|
|
2018-10-18 20:23:05 +08:00
|
|
|
SymbolQualitySignals ImplementationDetail;
|
|
|
|
ImplementationDetail.ImplementationDetail = true;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_LT(ImplementationDetail.evaluateHeuristics(),
|
|
|
|
Default.evaluateHeuristics());
|
2018-10-18 20:23:05 +08:00
|
|
|
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
SymbolQualitySignals WithReferences, ManyReferences;
|
2018-06-29 00:51:12 +08:00
|
|
|
WithReferences.References = 20;
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
ManyReferences.References = 1000;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_GT(WithReferences.evaluateHeuristics(), Default.evaluateHeuristics());
|
|
|
|
EXPECT_GT(ManyReferences.evaluateHeuristics(),
|
|
|
|
WithReferences.evaluateHeuristics());
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
|
2018-11-30 19:17:15 +08:00
|
|
|
SymbolQualitySignals Keyword, Variable, Macro, Constructor, Function,
|
|
|
|
Destructor, Operator;
|
2018-06-14 21:42:21 +08:00
|
|
|
Keyword.Category = SymbolQualitySignals::Keyword;
|
2018-06-06 16:53:36 +08:00
|
|
|
Variable.Category = SymbolQualitySignals::Variable;
|
|
|
|
Macro.Category = SymbolQualitySignals::Macro;
|
2018-07-24 16:51:52 +08:00
|
|
|
Constructor.Category = SymbolQualitySignals::Constructor;
|
2018-11-30 19:17:15 +08:00
|
|
|
Destructor.Category = SymbolQualitySignals::Destructor;
|
|
|
|
Destructor.Category = SymbolQualitySignals::Destructor;
|
|
|
|
Operator.Category = SymbolQualitySignals::Operator;
|
2018-07-24 16:51:52 +08:00
|
|
|
Function.Category = SymbolQualitySignals::Function;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_GT(Variable.evaluateHeuristics(), Default.evaluateHeuristics());
|
|
|
|
EXPECT_GT(Keyword.evaluateHeuristics(), Variable.evaluateHeuristics());
|
|
|
|
EXPECT_LT(Macro.evaluateHeuristics(), Default.evaluateHeuristics());
|
|
|
|
EXPECT_LT(Operator.evaluateHeuristics(), Default.evaluateHeuristics());
|
|
|
|
EXPECT_LT(Constructor.evaluateHeuristics(), Function.evaluateHeuristics());
|
|
|
|
EXPECT_LT(Destructor.evaluateHeuristics(), Constructor.evaluateHeuristics());
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QualityTests, SymbolRelevanceSignalsSanity) {
|
|
|
|
SymbolRelevanceSignals Default;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_EQ(Default.evaluateHeuristics(), 1);
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
|
|
|
|
SymbolRelevanceSignals Forbidden;
|
|
|
|
Forbidden.Forbidden = true;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_LT(Forbidden.evaluateHeuristics(), Default.evaluateHeuristics());
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
|
|
|
|
SymbolRelevanceSignals PoorNameMatch;
|
2018-05-18 22:53:32 +08:00
|
|
|
PoorNameMatch.NameMatch = 0.2f;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_LT(PoorNameMatch.evaluateHeuristics(), Default.evaluateHeuristics());
|
2018-06-04 22:50:59 +08:00
|
|
|
|
2018-10-17 19:19:02 +08:00
|
|
|
SymbolRelevanceSignals WithSemaFileProximity;
|
|
|
|
WithSemaFileProximity.SemaFileProximityScore = 0.2f;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_GT(WithSemaFileProximity.evaluateHeuristics(),
|
|
|
|
Default.evaluateHeuristics());
|
2018-10-17 19:19:02 +08:00
|
|
|
|
|
|
|
ScopeDistance ScopeProximity({"x::y::"});
|
|
|
|
|
|
|
|
SymbolRelevanceSignals WithSemaScopeProximity;
|
|
|
|
WithSemaScopeProximity.ScopeProximityMatch = &ScopeProximity;
|
|
|
|
WithSemaScopeProximity.SemaSaysInScope = true;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_GT(WithSemaScopeProximity.evaluateHeuristics(),
|
|
|
|
Default.evaluateHeuristics());
|
2018-10-17 19:19:02 +08:00
|
|
|
|
|
|
|
SymbolRelevanceSignals WithIndexScopeProximity;
|
|
|
|
WithIndexScopeProximity.ScopeProximityMatch = &ScopeProximity;
|
2021-01-29 21:59:16 +08:00
|
|
|
WithIndexScopeProximity.SymbolScope = "x::";
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_GT(WithSemaScopeProximity.evaluateHeuristics(),
|
|
|
|
Default.evaluateHeuristics());
|
2018-07-03 16:09:29 +08:00
|
|
|
|
|
|
|
SymbolRelevanceSignals IndexProximate;
|
|
|
|
IndexProximate.SymbolURI = "unittest:/foo/bar.h";
|
2019-01-07 23:45:19 +08:00
|
|
|
llvm::StringMap<SourceParams> ProxSources;
|
2018-07-03 16:09:29 +08:00
|
|
|
ProxSources.try_emplace(testPath("foo/baz.h"));
|
|
|
|
URIDistance Distance(ProxSources);
|
|
|
|
IndexProximate.FileProximityMatch = &Distance;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_GT(IndexProximate.evaluateHeuristics(), Default.evaluateHeuristics());
|
2018-07-03 16:09:29 +08:00
|
|
|
SymbolRelevanceSignals IndexDistant = IndexProximate;
|
|
|
|
IndexDistant.SymbolURI = "unittest:/elsewhere/path.h";
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_GT(IndexProximate.evaluateHeuristics(),
|
|
|
|
IndexDistant.evaluateHeuristics())
|
2018-07-03 16:09:29 +08:00
|
|
|
<< IndexProximate << IndexDistant;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_GT(IndexDistant.evaluateHeuristics(), Default.evaluateHeuristics());
|
2018-06-06 00:30:25 +08:00
|
|
|
|
|
|
|
SymbolRelevanceSignals Scoped;
|
2021-01-29 21:59:16 +08:00
|
|
|
Scoped.Scope = SymbolRelevanceSignals::FileScope;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_LT(Scoped.evaluateHeuristics(), Default.evaluateHeuristics());
|
2018-06-06 00:30:25 +08:00
|
|
|
Scoped.Query = SymbolRelevanceSignals::CodeComplete;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_GT(Scoped.evaluateHeuristics(), Default.evaluateHeuristics());
|
2018-07-23 18:56:37 +08:00
|
|
|
|
|
|
|
SymbolRelevanceSignals Instance;
|
|
|
|
Instance.IsInstanceMember = false;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_EQ(Instance.evaluateHeuristics(), Default.evaluateHeuristics());
|
2018-07-23 18:56:37 +08:00
|
|
|
Instance.Context = CodeCompletionContext::CCC_DotMemberAccess;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_LT(Instance.evaluateHeuristics(), Default.evaluateHeuristics());
|
2018-07-23 18:56:37 +08:00
|
|
|
Instance.IsInstanceMember = true;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_EQ(Instance.evaluateHeuristics(), Default.evaluateHeuristics());
|
2018-10-24 21:45:17 +08:00
|
|
|
|
|
|
|
SymbolRelevanceSignals InBaseClass;
|
|
|
|
InBaseClass.InBaseClass = true;
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_LT(InBaseClass.evaluateHeuristics(), Default.evaluateHeuristics());
|
2019-05-06 18:25:10 +08:00
|
|
|
|
|
|
|
llvm::StringSet<> Words = {"one", "two", "three"};
|
|
|
|
SymbolRelevanceSignals WithoutMatchingWord;
|
|
|
|
WithoutMatchingWord.ContextWords = &Words;
|
|
|
|
WithoutMatchingWord.Name = "four";
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_EQ(WithoutMatchingWord.evaluateHeuristics(),
|
|
|
|
Default.evaluateHeuristics());
|
2019-05-06 18:25:10 +08:00
|
|
|
SymbolRelevanceSignals WithMatchingWord;
|
|
|
|
WithMatchingWord.ContextWords = &Words;
|
|
|
|
WithMatchingWord.Name = "TheTwoTowers";
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_GT(WithMatchingWord.evaluateHeuristics(),
|
|
|
|
Default.evaluateHeuristics());
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
}
|
|
|
|
|
2018-10-17 19:19:02 +08:00
|
|
|
TEST(QualityTests, ScopeProximity) {
|
|
|
|
SymbolRelevanceSignals Relevance;
|
|
|
|
ScopeDistance ScopeProximity({"x::y::z::", "x::", "llvm::", ""});
|
|
|
|
Relevance.ScopeProximityMatch = &ScopeProximity;
|
|
|
|
|
2021-01-29 21:59:16 +08:00
|
|
|
Relevance.SymbolScope = "other::";
|
2020-09-29 01:19:51 +08:00
|
|
|
float NotMatched = Relevance.evaluateHeuristics();
|
2018-10-17 19:19:02 +08:00
|
|
|
|
2021-01-29 21:59:16 +08:00
|
|
|
Relevance.SymbolScope = "";
|
2020-09-29 01:19:51 +08:00
|
|
|
float Global = Relevance.evaluateHeuristics();
|
2018-10-17 19:19:02 +08:00
|
|
|
EXPECT_GT(Global, NotMatched);
|
|
|
|
|
2021-01-29 21:59:16 +08:00
|
|
|
Relevance.SymbolScope = "llvm::";
|
2020-09-29 01:19:51 +08:00
|
|
|
float NonParent = Relevance.evaluateHeuristics();
|
2018-10-17 19:19:02 +08:00
|
|
|
EXPECT_GT(NonParent, Global);
|
|
|
|
|
2021-01-29 21:59:16 +08:00
|
|
|
Relevance.SymbolScope = "x::";
|
2020-09-29 01:19:51 +08:00
|
|
|
float GrandParent = Relevance.evaluateHeuristics();
|
2018-10-17 19:19:02 +08:00
|
|
|
EXPECT_GT(GrandParent, Global);
|
|
|
|
|
2021-01-29 21:59:16 +08:00
|
|
|
Relevance.SymbolScope = "x::y::";
|
2020-09-29 01:19:51 +08:00
|
|
|
float Parent = Relevance.evaluateHeuristics();
|
2018-10-17 19:19:02 +08:00
|
|
|
EXPECT_GT(Parent, GrandParent);
|
|
|
|
|
2021-01-29 21:59:16 +08:00
|
|
|
Relevance.SymbolScope = "x::y::z::";
|
2020-09-29 01:19:51 +08:00
|
|
|
float Enclosing = Relevance.evaluateHeuristics();
|
2018-10-17 19:19:02 +08:00
|
|
|
EXPECT_GT(Enclosing, Parent);
|
|
|
|
}
|
|
|
|
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
TEST(QualityTests, SortText) {
|
2018-07-11 22:49:49 +08:00
|
|
|
EXPECT_LT(sortText(std::numeric_limits<float>::infinity()),
|
|
|
|
sortText(1000.2f));
|
2018-05-18 22:53:32 +08:00
|
|
|
EXPECT_LT(sortText(1000.2f), sortText(1));
|
|
|
|
EXPECT_LT(sortText(1), sortText(0.3f));
|
|
|
|
EXPECT_LT(sortText(0.3f), sortText(0));
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
EXPECT_LT(sortText(0), sortText(-10));
|
|
|
|
EXPECT_LT(sortText(-10), sortText(-std::numeric_limits<float>::infinity()));
|
|
|
|
|
|
|
|
EXPECT_LT(sortText(1, "z"), sortText(0, "a"));
|
|
|
|
EXPECT_LT(sortText(0, "a"), sortText(0, "z"));
|
|
|
|
}
|
|
|
|
|
2018-07-05 16:14:04 +08:00
|
|
|
TEST(QualityTests, NoBoostForClassConstructor) {
|
|
|
|
auto Header = TestTU::withHeaderCode(R"cpp(
|
|
|
|
class Foo {
|
|
|
|
public:
|
|
|
|
Foo(int);
|
|
|
|
};
|
|
|
|
)cpp");
|
|
|
|
auto Symbols = Header.headerSymbols();
|
|
|
|
auto AST = Header.build();
|
|
|
|
|
|
|
|
const NamedDecl *Foo = &findDecl(AST, "Foo");
|
|
|
|
SymbolRelevanceSignals Cls;
|
|
|
|
Cls.merge(CodeCompletionResult(Foo, /*Priority=*/0));
|
|
|
|
|
2018-11-09 20:56:49 +08:00
|
|
|
const NamedDecl *CtorDecl = &findDecl(AST, [](const NamedDecl &ND) {
|
2018-07-05 16:14:04 +08:00
|
|
|
return (ND.getQualifiedNameAsString() == "Foo::Foo") &&
|
2018-10-20 23:30:37 +08:00
|
|
|
isa<CXXConstructorDecl>(&ND);
|
2018-07-05 16:14:04 +08:00
|
|
|
});
|
|
|
|
SymbolRelevanceSignals Ctor;
|
|
|
|
Ctor.merge(CodeCompletionResult(CtorDecl, /*Priority=*/0));
|
|
|
|
|
2021-01-29 21:59:16 +08:00
|
|
|
EXPECT_EQ(Cls.Scope, SymbolRelevanceSignals::GlobalScope);
|
|
|
|
EXPECT_EQ(Ctor.Scope, SymbolRelevanceSignals::GlobalScope);
|
2018-07-05 16:14:04 +08:00
|
|
|
}
|
|
|
|
|
2018-07-23 18:56:37 +08:00
|
|
|
TEST(QualityTests, IsInstanceMember) {
|
|
|
|
auto Header = TestTU::withHeaderCode(R"cpp(
|
|
|
|
class Foo {
|
|
|
|
public:
|
|
|
|
static void foo() {}
|
|
|
|
|
|
|
|
template <typename T> void tpl(T *t) {}
|
|
|
|
|
|
|
|
void bar() {}
|
|
|
|
};
|
|
|
|
)cpp");
|
|
|
|
auto Symbols = Header.headerSymbols();
|
|
|
|
|
|
|
|
SymbolRelevanceSignals Rel;
|
|
|
|
const Symbol &FooSym = findSymbol(Symbols, "Foo::foo");
|
|
|
|
Rel.merge(FooSym);
|
|
|
|
EXPECT_FALSE(Rel.IsInstanceMember);
|
|
|
|
const Symbol &BarSym = findSymbol(Symbols, "Foo::bar");
|
|
|
|
Rel.merge(BarSym);
|
|
|
|
EXPECT_TRUE(Rel.IsInstanceMember);
|
|
|
|
|
2019-01-03 21:28:05 +08:00
|
|
|
Rel.IsInstanceMember = false;
|
2018-07-23 18:56:37 +08:00
|
|
|
const Symbol &TplSym = findSymbol(Symbols, "Foo::tpl");
|
|
|
|
Rel.merge(TplSym);
|
|
|
|
EXPECT_TRUE(Rel.IsInstanceMember);
|
|
|
|
|
|
|
|
auto AST = Header.build();
|
|
|
|
const NamedDecl *Foo = &findDecl(AST, "Foo::foo");
|
|
|
|
const NamedDecl *Bar = &findDecl(AST, "Foo::bar");
|
|
|
|
const NamedDecl *Tpl = &findDecl(AST, "Foo::tpl");
|
|
|
|
|
|
|
|
Rel.IsInstanceMember = false;
|
|
|
|
Rel.merge(CodeCompletionResult(Foo, /*Priority=*/0));
|
|
|
|
EXPECT_FALSE(Rel.IsInstanceMember);
|
|
|
|
Rel.merge(CodeCompletionResult(Bar, /*Priority=*/0));
|
|
|
|
EXPECT_TRUE(Rel.IsInstanceMember);
|
|
|
|
Rel.IsInstanceMember = false;
|
|
|
|
Rel.merge(CodeCompletionResult(Tpl, /*Priority=*/0));
|
|
|
|
EXPECT_TRUE(Rel.IsInstanceMember);
|
|
|
|
}
|
|
|
|
|
2018-11-30 19:17:15 +08:00
|
|
|
TEST(QualityTests, ConstructorDestructor) {
|
2018-07-24 16:51:52 +08:00
|
|
|
auto Header = TestTU::withHeaderCode(R"cpp(
|
|
|
|
class Foo {
|
|
|
|
public:
|
|
|
|
Foo(int);
|
2018-11-30 19:17:15 +08:00
|
|
|
~Foo();
|
2018-07-24 16:51:52 +08:00
|
|
|
};
|
|
|
|
)cpp");
|
|
|
|
auto Symbols = Header.headerSymbols();
|
|
|
|
auto AST = Header.build();
|
|
|
|
|
2018-11-09 20:56:49 +08:00
|
|
|
const NamedDecl *CtorDecl = &findDecl(AST, [](const NamedDecl &ND) {
|
2018-07-24 16:51:52 +08:00
|
|
|
return (ND.getQualifiedNameAsString() == "Foo::Foo") &&
|
2018-10-20 23:30:37 +08:00
|
|
|
isa<CXXConstructorDecl>(&ND);
|
2018-07-24 16:51:52 +08:00
|
|
|
});
|
2018-11-30 19:17:15 +08:00
|
|
|
const NamedDecl *DtorDecl = &findDecl(AST, [](const NamedDecl &ND) {
|
|
|
|
return (ND.getQualifiedNameAsString() == "Foo::~Foo") &&
|
|
|
|
isa<CXXDestructorDecl>(&ND);
|
|
|
|
});
|
2018-07-24 16:51:52 +08:00
|
|
|
|
2018-11-30 19:17:15 +08:00
|
|
|
SymbolQualitySignals CtorQ;
|
|
|
|
CtorQ.merge(CodeCompletionResult(CtorDecl, /*Priority=*/0));
|
|
|
|
EXPECT_EQ(CtorQ.Category, SymbolQualitySignals::Constructor);
|
2018-07-24 16:51:52 +08:00
|
|
|
|
2018-11-30 19:17:15 +08:00
|
|
|
CtorQ.Category = SymbolQualitySignals::Unknown;
|
2018-07-24 16:51:52 +08:00
|
|
|
const Symbol &CtorSym = findSymbol(Symbols, "Foo::Foo");
|
2018-11-30 19:17:15 +08:00
|
|
|
CtorQ.merge(CtorSym);
|
|
|
|
EXPECT_EQ(CtorQ.Category, SymbolQualitySignals::Constructor);
|
|
|
|
|
|
|
|
SymbolQualitySignals DtorQ;
|
|
|
|
DtorQ.merge(CodeCompletionResult(DtorDecl, /*Priority=*/0));
|
|
|
|
EXPECT_EQ(DtorQ.Category, SymbolQualitySignals::Destructor);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(QualityTests, Operator) {
|
|
|
|
auto Header = TestTU::withHeaderCode(R"cpp(
|
|
|
|
class Foo {
|
|
|
|
public:
|
2018-12-21 17:32:49 +08:00
|
|
|
bool operator<(const Foo& f1);
|
2018-11-30 19:17:15 +08:00
|
|
|
};
|
|
|
|
)cpp");
|
|
|
|
auto AST = Header.build();
|
|
|
|
|
|
|
|
const NamedDecl *Operator = &findDecl(AST, [](const NamedDecl &ND) {
|
|
|
|
if (const auto *OD = dyn_cast<FunctionDecl>(&ND))
|
|
|
|
if (OD->isOverloadedOperator())
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
SymbolQualitySignals Q;
|
|
|
|
Q.merge(CodeCompletionResult(Operator, /*Priority=*/0));
|
|
|
|
EXPECT_EQ(Q.Category, SymbolQualitySignals::Operator);
|
2018-07-24 16:51:52 +08:00
|
|
|
}
|
|
|
|
|
2018-08-08 16:59:29 +08:00
|
|
|
TEST(QualityTests, ItemWithFixItsRankedDown) {
|
|
|
|
CodeCompleteOptions Opts;
|
|
|
|
Opts.IncludeFixIts = true;
|
|
|
|
|
|
|
|
auto Header = TestTU::withHeaderCode(R"cpp(
|
|
|
|
int x;
|
|
|
|
)cpp");
|
|
|
|
auto AST = Header.build();
|
|
|
|
|
|
|
|
SymbolRelevanceSignals RelevanceWithFixIt;
|
|
|
|
RelevanceWithFixIt.merge(CodeCompletionResult(&findDecl(AST, "x"), 0, nullptr,
|
|
|
|
false, true, {FixItHint{}}));
|
|
|
|
EXPECT_TRUE(RelevanceWithFixIt.NeedsFixIts);
|
|
|
|
|
|
|
|
SymbolRelevanceSignals RelevanceWithoutFixIt;
|
|
|
|
RelevanceWithoutFixIt.merge(
|
|
|
|
CodeCompletionResult(&findDecl(AST, "x"), 0, nullptr, false, true, {}));
|
|
|
|
EXPECT_FALSE(RelevanceWithoutFixIt.NeedsFixIts);
|
|
|
|
|
2020-09-29 01:19:51 +08:00
|
|
|
EXPECT_LT(RelevanceWithFixIt.evaluateHeuristics(),
|
|
|
|
RelevanceWithoutFixIt.evaluateHeuristics());
|
2018-08-08 16:59:29 +08:00
|
|
|
}
|
|
|
|
|
[clangd] Extract scoring/ranking logic, and shave yaks.
Summary:
Code completion scoring was embedded in CodeComplete.cpp, which is bad:
- awkward to test. The mechanisms (extracting info from index/sema) can be
unit-tested well, the policy (scoring) should be quantitatively measured.
Neither was easily possible, and debugging was hard.
The intermediate signal struct makes this easier.
- hard to reuse. This is a bug in workspaceSymbols: it just presents the
results in the index order, which is not sorted in practice, it needs to rank
them!
Also, index implementations care about scoring (both query-dependent and
independent) in order to truncate result lists appropriately.
The main yak shaved here is the build() function that had 3 variants across
unit tests is unified in TestTU.h (rather than adding a 4th variant).
Reviewers: ilya-biryukov
Subscribers: klimek, mgorny, ioeric, MaskRay, jkorous, mgrang, cfe-commits
Differential Revision: https://reviews.llvm.org/D46524
llvm-svn: 332378
2018-05-16 01:43:27 +08:00
|
|
|
} // namespace
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|