[llvm-branch-commits] [clang-tools-extra] 359e2f9 - [clangd] Introduce config parsing for External blocks
Kadir Cetinkaya via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Nov 22 12:17:45 PST 2020
Author: Kadir Cetinkaya
Date: 2020-11-22T20:59:37+01:00
New Revision: 359e2f988dc560d519c91d3ee96a2ea99983f5d4
URL: https://github.com/llvm/llvm-project/commit/359e2f988dc560d519c91d3ee96a2ea99983f5d4
DIFF: https://github.com/llvm/llvm-project/commit/359e2f988dc560d519c91d3ee96a2ea99983f5d4.diff
LOG: [clangd] Introduce config parsing for External blocks
Enable configuration of remote and static indexes through config files
in addition to command line arguments.
Differential Revision: https://reviews.llvm.org/D90748
Added:
Modified:
clang-tools-extra/clangd/ConfigFragment.h
clang-tools-extra/clangd/ConfigYAML.cpp
clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/ConfigFragment.h b/clang-tools-extra/clangd/ConfigFragment.h
index 766463e11e25..0e4ce638fc72 100644
--- a/clang-tools-extra/clangd/ConfigFragment.h
+++ b/clang-tools-extra/clangd/ConfigFragment.h
@@ -162,6 +162,22 @@ struct Fragment {
/// This is checked for translation units only, not headers they include.
/// Legal values are "Build" or "Skip".
llvm::Optional<Located<std::string>> Background;
+ /// An external index uses data source outside of clangd itself. This is
+ /// usually prepared using clangd-indexer.
+ /// Exactly one source (File/Server) should be configured.
+ struct ExternalBlock {
+ /// Path to an index file generated by clangd-indexer. Relative paths may
+ /// be used, if config fragment is associated with a directory.
+ llvm::Optional<Located<std::string>> File;
+ /// Address and port number for a clangd-index-server. e.g.
+ /// `123.1.1.1:13337`.
+ llvm::Optional<Located<std::string>> Server;
+ /// Source root governed by this index. Default is the directory
+ /// associated with the config fragment. Absolute in case of user config
+ /// and relative otherwise. Should always use forward-slashes.
+ llvm::Optional<Located<std::string>> MountPoint;
+ };
+ llvm::Optional<Located<ExternalBlock>> External;
};
IndexBlock Index;
diff --git a/clang-tools-extra/clangd/ConfigYAML.cpp b/clang-tools-extra/clangd/ConfigYAML.cpp
index 742abb42670f..a3bb1eb29adb 100644
--- a/clang-tools-extra/clangd/ConfigYAML.cpp
+++ b/clang-tools-extra/clangd/ConfigYAML.cpp
@@ -5,7 +5,6 @@
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
-
#include "ConfigFragment.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/SmallSet.h"
@@ -111,6 +110,22 @@ class Parser {
DictParser Dict("Index", this);
Dict.handle("Background",
[&](Node &N) { F.Background = scalarValue(N, "Background"); });
+ Dict.handle("External", [&](Node &N) {
+ Fragment::IndexBlock::ExternalBlock External;
+ parse(External, N);
+ F.External.emplace(std::move(External));
+ F.External->Range = N.getSourceRange();
+ });
+ Dict.parse(N);
+ }
+
+ void parse(Fragment::IndexBlock::ExternalBlock &F, Node &N) {
+ DictParser Dict("External", this);
+ Dict.handle("File", [&](Node &N) { F.File = scalarValue(N, "File"); });
+ Dict.handle("Server",
+ [&](Node &N) { F.Server = scalarValue(N, "Server"); });
+ Dict.handle("MountPoint",
+ [&](Node &N) { F.MountPoint = scalarValue(N, "MountPoint"); });
Dict.parse(N);
}
diff --git a/clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp b/clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
index 9cdfdf9657d3..1da0f3a1cc71 100644
--- a/clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp
@@ -10,6 +10,7 @@
#include "ConfigFragment.h"
#include "ConfigTesting.h"
#include "Protocol.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/Support/SMLoc.h"
#include "llvm/Support/ScopedPrinter.h"
#include "llvm/Support/SourceMgr.h"
@@ -142,6 +143,25 @@ horrible
ASSERT_THAT(Results, IsEmpty());
}
+TEST(ParseYAML, ExternalBlock) {
+ CapturedDiags Diags;
+ Annotations YAML(R"yaml(
+Index:
+ External:
+ File: "foo"
+ Server: ^"bar"
+ MountPoint: "baz"
+ )yaml");
+ auto Results =
+ Fragment::parseYAML(YAML.code(), "config.yaml", Diags.callback());
+ ASSERT_EQ(Results.size(), 1u);
+ ASSERT_TRUE(Results[0].Index.External);
+ EXPECT_THAT(*Results[0].Index.External.getValue()->File, Val("foo"));
+ EXPECT_THAT(*Results[0].Index.External.getValue()->MountPoint, Val("baz"));
+ ASSERT_THAT(Diags.Diagnostics, IsEmpty());
+ EXPECT_THAT(*Results[0].Index.External.getValue()->Server, Val("bar"));
+}
+
} // namespace
} // namespace config
} // namespace clangd
More information about the llvm-branch-commits
mailing list