2019-09-16 19:29:35 +08:00
|
|
|
//===-- SemanticSelectionTests.cpp ----------------*- C++ -*--------------===//
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Annotations.h"
|
2019-09-17 18:28:05 +08:00
|
|
|
#include "ClangdServer.h"
|
2019-09-16 19:29:35 +08:00
|
|
|
#include "Matchers.h"
|
|
|
|
#include "Protocol.h"
|
|
|
|
#include "SemanticSelection.h"
|
|
|
|
#include "SourceCode.h"
|
2019-09-17 18:28:05 +08:00
|
|
|
#include "SyncAPI.h"
|
|
|
|
#include "TestFS.h"
|
2019-09-16 19:29:35 +08:00
|
|
|
#include "TestTU.h"
|
|
|
|
#include "clang/Basic/SourceLocation.h"
|
|
|
|
#include "clang/Basic/SourceManager.h"
|
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.
The next steps for textDocument/foldingRange support would be:
* Implementing FoldingRangeClientCapabilities and respecting respect client
preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)
Tested: (Neo)Vim (coc-clangd) and VSCode.
Related issue: https://github.com/clangd/clangd/issues/310
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: nridge, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 15:28:38 +08:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2019-09-16 19:29:35 +08:00
|
|
|
#include "llvm/Support/Error.h"
|
|
|
|
#include "gmock/gmock.h"
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
#include <vector>
|
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.
The next steps for textDocument/foldingRange support would be:
* Implementing FoldingRangeClientCapabilities and respecting respect client
preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)
Tested: (Neo)Vim (coc-clangd) and VSCode.
Related issue: https://github.com/clangd/clangd/issues/310
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: nridge, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 15:28:38 +08:00
|
|
|
|
2019-09-16 19:29:35 +08:00
|
|
|
namespace clang {
|
|
|
|
namespace clangd {
|
|
|
|
namespace {
|
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.
The next steps for textDocument/foldingRange support would be:
* Implementing FoldingRangeClientCapabilities and respecting respect client
preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)
Tested: (Neo)Vim (coc-clangd) and VSCode.
Related issue: https://github.com/clangd/clangd/issues/310
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: nridge, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 15:28:38 +08:00
|
|
|
|
2020-03-25 07:51:50 +08:00
|
|
|
using ::testing::ElementsAre;
|
2019-09-16 19:29:35 +08:00
|
|
|
using ::testing::ElementsAreArray;
|
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.
The next steps for textDocument/foldingRange support would be:
* Implementing FoldingRangeClientCapabilities and respecting respect client
preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)
Tested: (Neo)Vim (coc-clangd) and VSCode.
Related issue: https://github.com/clangd/clangd/issues/310
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: nridge, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 15:28:38 +08:00
|
|
|
using ::testing::UnorderedElementsAreArray;
|
2019-09-16 19:29:35 +08:00
|
|
|
|
2020-03-25 07:51:50 +08:00
|
|
|
// front() is SR.range, back() is outermost range.
|
|
|
|
std::vector<Range> gatherRanges(const SelectionRange &SR) {
|
|
|
|
std::vector<Range> Ranges;
|
|
|
|
for (const SelectionRange *S = &SR; S; S = S->parent.get())
|
|
|
|
Ranges.push_back(S->range);
|
|
|
|
return Ranges;
|
|
|
|
}
|
|
|
|
|
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.
The next steps for textDocument/foldingRange support would be:
* Implementing FoldingRangeClientCapabilities and respecting respect client
preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)
Tested: (Neo)Vim (coc-clangd) and VSCode.
Related issue: https://github.com/clangd/clangd/issues/310
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: nridge, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 15:28:38 +08:00
|
|
|
std::vector<Range>
|
|
|
|
gatherFoldingRanges(llvm::ArrayRef<FoldingRange> FoldingRanges) {
|
|
|
|
std::vector<Range> Ranges;
|
|
|
|
Range NextRange;
|
|
|
|
for (const auto &R : FoldingRanges) {
|
|
|
|
NextRange.start.line = R.startLine;
|
|
|
|
NextRange.start.character = R.startCharacter;
|
|
|
|
NextRange.end.line = R.endLine;
|
|
|
|
NextRange.end.character = R.endCharacter;
|
|
|
|
Ranges.push_back(NextRange);
|
|
|
|
}
|
|
|
|
return Ranges;
|
|
|
|
}
|
|
|
|
|
2019-09-16 19:29:35 +08:00
|
|
|
TEST(SemanticSelection, All) {
|
|
|
|
const char *Tests[] = {
|
|
|
|
R"cpp( // Single statement in a function body.
|
|
|
|
[[void func() [[{
|
|
|
|
[[[[int v = [[1^00]]]];]]
|
|
|
|
}]]]]
|
|
|
|
)cpp",
|
|
|
|
R"cpp( // Expression
|
|
|
|
[[void func() [[{
|
|
|
|
int a = 1;
|
|
|
|
// int v = (10 + 2) * (a + a);
|
|
|
|
[[[[int v = [[[[([[[[10^]] + 2]])]] * (a + a)]]]];]]
|
|
|
|
}]]]]
|
|
|
|
)cpp",
|
|
|
|
R"cpp( // Function call.
|
|
|
|
int add(int x, int y) { return x + y; }
|
|
|
|
[[void callee() [[{
|
|
|
|
// int res = add(11, 22);
|
|
|
|
[[[[int res = [[add([[1^1]], 22)]]]];]]
|
|
|
|
}]]]]
|
|
|
|
)cpp",
|
|
|
|
R"cpp( // Tricky macros.
|
|
|
|
#define MUL ) * (
|
|
|
|
[[void func() [[{
|
|
|
|
// int var = (4 + 15 MUL 6 + 10);
|
|
|
|
[[[[int var = [[[[([[4 + [[1^5]]]] MUL]] 6 + 10)]]]];]]
|
|
|
|
}]]]]
|
|
|
|
)cpp",
|
|
|
|
R"cpp( // Cursor inside a macro.
|
|
|
|
#define HASH(x) ((x) % 10)
|
|
|
|
[[void func() [[{
|
|
|
|
[[[[int a = [[HASH([[[[2^3]] + 34]])]]]];]]
|
|
|
|
}]]]]
|
|
|
|
)cpp",
|
|
|
|
R"cpp( // Cursor on a macro.
|
|
|
|
#define HASH(x) ((x) % 10)
|
|
|
|
[[void func() [[{
|
|
|
|
[[[[int a = [[HA^SH(23)]]]];]]
|
|
|
|
}]]]]
|
|
|
|
)cpp",
|
|
|
|
R"cpp( // Multiple declaration.
|
|
|
|
[[void func() [[{
|
|
|
|
[[[[int var1, var^2]], var3;]]
|
|
|
|
}]]]]
|
|
|
|
)cpp",
|
|
|
|
R"cpp( // Before comment.
|
|
|
|
[[void func() [[{
|
|
|
|
int var1 = 1;
|
|
|
|
[[[[int var2 = [[[[var1]]^ /*some comment*/ + 41]]]];]]
|
|
|
|
}]]]]
|
|
|
|
)cpp",
|
|
|
|
// Empty file.
|
2020-03-25 07:51:50 +08:00
|
|
|
"[[^]]",
|
2019-09-16 19:29:35 +08:00
|
|
|
// FIXME: We should get the whole DeclStmt as a range.
|
|
|
|
R"cpp( // Single statement in TU.
|
|
|
|
[[int v = [[1^00]]]];
|
|
|
|
)cpp",
|
|
|
|
R"cpp( // Cursor at end of VarDecl.
|
2019-11-28 18:24:04 +08:00
|
|
|
[[int v = [[100]]^]];
|
2019-09-16 19:29:35 +08:00
|
|
|
)cpp",
|
|
|
|
// FIXME: No node found associated to the position.
|
|
|
|
R"cpp( // Cursor in between spaces.
|
|
|
|
void func() {
|
2020-03-25 07:51:50 +08:00
|
|
|
int v = 100 + [[^]] 100;
|
2019-09-16 19:29:35 +08:00
|
|
|
}
|
|
|
|
)cpp",
|
|
|
|
// Structs.
|
|
|
|
R"cpp(
|
|
|
|
struct AAA { struct BBB { static int ccc(); };};
|
|
|
|
[[void func() [[{
|
|
|
|
// int x = AAA::BBB::ccc();
|
|
|
|
[[[[int x = [[[[AAA::BBB::c^cc]]()]]]];]]
|
|
|
|
}]]]]
|
|
|
|
)cpp",
|
|
|
|
R"cpp(
|
|
|
|
struct AAA { struct BBB { static int ccc(); };};
|
|
|
|
[[void func() [[{
|
|
|
|
// int x = AAA::BBB::ccc();
|
|
|
|
[[[[int x = [[[[[[[[[[AA^A]]::]]BBB::]]ccc]]()]]]];]]
|
|
|
|
}]]]]
|
|
|
|
)cpp",
|
|
|
|
R"cpp( // Inside struct.
|
|
|
|
struct A { static int a(); };
|
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.
The next steps for textDocument/foldingRange support would be:
* Implementing FoldingRangeClientCapabilities and respecting respect client
preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)
Tested: (Neo)Vim (coc-clangd) and VSCode.
Related issue: https://github.com/clangd/clangd/issues/310
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: nridge, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 15:28:38 +08:00
|
|
|
[[struct B {
|
2019-09-16 19:29:35 +08:00
|
|
|
[[static int b() [[{
|
|
|
|
[[return [[[[1^1]] + 2]]]];
|
|
|
|
}]]]]
|
|
|
|
}]];
|
|
|
|
)cpp",
|
|
|
|
// Namespaces.
|
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.
The next steps for textDocument/foldingRange support would be:
* Implementing FoldingRangeClientCapabilities and respecting respect client
preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)
Tested: (Neo)Vim (coc-clangd) and VSCode.
Related issue: https://github.com/clangd/clangd/issues/310
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: nridge, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 15:28:38 +08:00
|
|
|
R"cpp(
|
|
|
|
[[namespace nsa {
|
|
|
|
[[namespace nsb {
|
2019-09-16 19:29:35 +08:00
|
|
|
static int ccc();
|
|
|
|
[[void func() [[{
|
|
|
|
// int x = nsa::nsb::ccc();
|
|
|
|
[[[[int x = [[[[nsa::nsb::cc^c]]()]]]];]]
|
|
|
|
}]]]]
|
|
|
|
}]]
|
|
|
|
}]]
|
|
|
|
)cpp",
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
for (const char *Test : Tests) {
|
|
|
|
auto T = Annotations(Test);
|
|
|
|
auto AST = TestTU::withCode(T.code()).build();
|
2020-03-25 07:51:50 +08:00
|
|
|
EXPECT_THAT(gatherRanges(llvm::cantFail(getSemanticRanges(AST, T.point()))),
|
2019-09-16 19:29:35 +08:00
|
|
|
ElementsAreArray(T.ranges()))
|
|
|
|
<< Test;
|
|
|
|
}
|
|
|
|
}
|
2019-09-17 18:28:05 +08:00
|
|
|
|
2020-03-25 07:51:50 +08:00
|
|
|
TEST(SemanticSelection, RunViaClangdServer) {
|
2020-06-17 17:53:32 +08:00
|
|
|
MockFS FS;
|
2019-09-17 18:28:05 +08:00
|
|
|
MockCompilationDatabase CDB;
|
2020-01-24 21:08:56 +08:00
|
|
|
ClangdServer Server(CDB, FS, ClangdServer::optsForTest());
|
2019-09-17 18:28:05 +08:00
|
|
|
|
|
|
|
auto FooH = testPath("foo.h");
|
|
|
|
FS.Files[FooH] = R"cpp(
|
|
|
|
int foo(int x);
|
|
|
|
#define HASH(x) ((x) % 10)
|
|
|
|
)cpp";
|
|
|
|
|
|
|
|
auto FooCpp = testPath("Foo.cpp");
|
|
|
|
const char *SourceContents = R"cpp(
|
|
|
|
#include "foo.h"
|
|
|
|
[[void bar(int& inp) [[{
|
|
|
|
// inp = HASH(foo(inp));
|
|
|
|
[[inp = [[HASH([[foo([[in^p]])]])]]]];
|
|
|
|
}]]]]
|
2020-03-25 07:51:50 +08:00
|
|
|
$empty[[^]]
|
2019-09-17 18:28:05 +08:00
|
|
|
)cpp";
|
|
|
|
Annotations SourceAnnotations(SourceContents);
|
2020-01-29 03:23:46 +08:00
|
|
|
FS.Files[FooCpp] = std::string(SourceAnnotations.code());
|
2019-09-17 18:28:05 +08:00
|
|
|
Server.addDocument(FooCpp, SourceAnnotations.code());
|
|
|
|
|
2020-03-25 07:51:50 +08:00
|
|
|
auto Ranges = runSemanticRanges(Server, FooCpp, SourceAnnotations.points());
|
2019-09-17 18:28:05 +08:00
|
|
|
ASSERT_TRUE(bool(Ranges))
|
|
|
|
<< "getSemanticRange returned an error: " << Ranges.takeError();
|
2020-03-25 07:51:50 +08:00
|
|
|
ASSERT_EQ(Ranges->size(), SourceAnnotations.points().size());
|
|
|
|
EXPECT_THAT(gatherRanges(Ranges->front()),
|
|
|
|
ElementsAreArray(SourceAnnotations.ranges()));
|
|
|
|
EXPECT_THAT(gatherRanges(Ranges->back()),
|
|
|
|
ElementsAre(SourceAnnotations.range("empty")));
|
2019-09-17 18:28:05 +08:00
|
|
|
}
|
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.
The next steps for textDocument/foldingRange support would be:
* Implementing FoldingRangeClientCapabilities and respecting respect client
preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)
Tested: (Neo)Vim (coc-clangd) and VSCode.
Related issue: https://github.com/clangd/clangd/issues/310
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: nridge, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 15:28:38 +08:00
|
|
|
|
|
|
|
TEST(FoldingRanges, All) {
|
|
|
|
const char *Tests[] = {
|
|
|
|
R"cpp(
|
2020-10-27 23:44:52 +08:00
|
|
|
#define FOO int foo() {\
|
|
|
|
int Variable = 42; \
|
|
|
|
}
|
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.
The next steps for textDocument/foldingRange support would be:
* Implementing FoldingRangeClientCapabilities and respecting respect client
preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)
Tested: (Neo)Vim (coc-clangd) and VSCode.
Related issue: https://github.com/clangd/clangd/issues/310
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: nridge, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 15:28:38 +08:00
|
|
|
|
2020-10-27 23:44:52 +08:00
|
|
|
// Do not generate folding range for braces within macro expansion.
|
|
|
|
FOO
|
|
|
|
|
|
|
|
// Do not generate folding range within macro arguments.
|
|
|
|
#define FUNCTOR(functor) functor
|
|
|
|
void func() {[[
|
|
|
|
FUNCTOR([](){});
|
|
|
|
]]}
|
|
|
|
|
|
|
|
// Do not generate folding range with a brace coming from macro.
|
|
|
|
#define LBRACE {
|
|
|
|
void bar() LBRACE
|
|
|
|
int X = 42;
|
|
|
|
}
|
|
|
|
)cpp",
|
|
|
|
R"cpp(
|
|
|
|
void func() {[[
|
|
|
|
int Variable = 100;
|
|
|
|
|
|
|
|
if (Variable > 5) {[[
|
|
|
|
Variable += 42;
|
|
|
|
]]} else if (Variable++)
|
|
|
|
++Variable;
|
|
|
|
else {[[
|
|
|
|
Variable--;
|
|
|
|
]]}
|
|
|
|
|
|
|
|
// Do not generate FoldingRange for empty CompoundStmts.
|
|
|
|
for (;;) {}
|
|
|
|
|
|
|
|
// If there are newlines between {}, we should generate one.
|
|
|
|
for (;;) {[[
|
|
|
|
|
|
|
|
]]}
|
|
|
|
]]}
|
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.
The next steps for textDocument/foldingRange support would be:
* Implementing FoldingRangeClientCapabilities and respecting respect client
preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)
Tested: (Neo)Vim (coc-clangd) and VSCode.
Related issue: https://github.com/clangd/clangd/issues/310
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: nridge, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 15:28:38 +08:00
|
|
|
)cpp",
|
|
|
|
R"cpp(
|
2020-10-27 23:44:52 +08:00
|
|
|
class Foo {
|
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.
The next steps for textDocument/foldingRange support would be:
* Implementing FoldingRangeClientCapabilities and respecting respect client
preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)
Tested: (Neo)Vim (coc-clangd) and VSCode.
Related issue: https://github.com/clangd/clangd/issues/310
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: nridge, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 15:28:38 +08:00
|
|
|
public:
|
2020-10-27 23:44:52 +08:00
|
|
|
Foo() {[[
|
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.
The next steps for textDocument/foldingRange support would be:
* Implementing FoldingRangeClientCapabilities and respecting respect client
preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)
Tested: (Neo)Vim (coc-clangd) and VSCode.
Related issue: https://github.com/clangd/clangd/issues/310
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: nridge, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 15:28:38 +08:00
|
|
|
int X = 1;
|
2020-10-27 23:44:52 +08:00
|
|
|
]]}
|
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.
The next steps for textDocument/foldingRange support would be:
* Implementing FoldingRangeClientCapabilities and respecting respect client
preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)
Tested: (Neo)Vim (coc-clangd) and VSCode.
Related issue: https://github.com/clangd/clangd/issues/310
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: nridge, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 15:28:38 +08:00
|
|
|
|
|
|
|
private:
|
2020-10-27 23:44:52 +08:00
|
|
|
int getBar() {[[
|
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.
The next steps for textDocument/foldingRange support would be:
* Implementing FoldingRangeClientCapabilities and respecting respect client
preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)
Tested: (Neo)Vim (coc-clangd) and VSCode.
Related issue: https://github.com/clangd/clangd/issues/310
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: nridge, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 15:28:38 +08:00
|
|
|
return 42;
|
2020-10-27 23:44:52 +08:00
|
|
|
]]}
|
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.
The next steps for textDocument/foldingRange support would be:
* Implementing FoldingRangeClientCapabilities and respecting respect client
preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)
Tested: (Neo)Vim (coc-clangd) and VSCode.
Related issue: https://github.com/clangd/clangd/issues/310
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: nridge, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 15:28:38 +08:00
|
|
|
|
2020-10-27 23:44:52 +08:00
|
|
|
// Braces are located at the same line: no folding range here.
|
|
|
|
void getFooBar() { }
|
|
|
|
};
|
[clangd] Implement textDocument/foldingRange
Summary:
This patch introduces basic textDocument/foldingRange support. It relies on
textDocument/documentSymbols to collect all symbols and uses takes ranges
to create folds.
The next steps for textDocument/foldingRange support would be:
* Implementing FoldingRangeClientCapabilities and respecting respect client
preferences
* Specifying folding range kind
* Migrating from DocumentSymbol implementation to custom RecursiveASTVisitor flow that will allow more flexibility
* Supporting more folding range types: comments, PP conditional regions, includes and other code regions (e.g. public/private/protected sections of classes, control flow statement bodies)
Tested: (Neo)Vim (coc-clangd) and VSCode.
Related issue: https://github.com/clangd/clangd/issues/310
Reviewers: sammccall
Reviewed By: sammccall
Subscribers: nridge, ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D82436
2020-07-14 15:28:38 +08:00
|
|
|
)cpp",
|
|
|
|
};
|
|
|
|
for (const char *Test : Tests) {
|
|
|
|
auto T = Annotations(Test);
|
|
|
|
auto AST = TestTU::withCode(T.code()).build();
|
|
|
|
EXPECT_THAT(gatherFoldingRanges(llvm::cantFail(getFoldingRanges(AST))),
|
|
|
|
UnorderedElementsAreArray(T.ranges()))
|
|
|
|
<< Test;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-16 19:29:35 +08:00
|
|
|
} // namespace
|
|
|
|
} // namespace clangd
|
|
|
|
} // namespace clang
|