summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/Protocol.cpp
diff options
context:
space:
mode:
authorKadir Cetinkaya <kadircet@google.com>2019-03-19 09:27:04 +0000
committerKadir Cetinkaya <kadircet@google.com>2019-03-19 09:27:04 +0000
commit8665802202689b4014bde7f5aa64f0a3c1a045f7 (patch)
tree4d71078bd62a9c906c00b6b182c410fd2d4de8f7 /clang-tools-extra/clangd/Protocol.cpp
parentad78768d5933bfa50009e8b6f84150291a8aba8f (diff)
downloadbcm5719-llvm-8665802202689b4014bde7f5aa64f0a3c1a045f7.tar.gz
bcm5719-llvm-8665802202689b4014bde7f5aa64f0a3c1a045f7.zip
[clangd] Add support for type hierarchy (super types only for now)
Summary: Patch by Nathan Ridge(@nridge)! This is an LSP extension proposed here: https://github.com/Microsoft/vscode-languageserver-node/pull/426 An example client implementation can be found here: https://github.com/theia-ide/theia/pull/3802 Reviewers: kadircet, sammccall Reviewed By: kadircet Subscribers: jdoerfert, sammccall, cfe-commits, mgorny, dschaefer, simark, ilya-biryukov, ioeric, MaskRay, jkorous, arphaman, kadircet Tags: #clang Differential Revision: https://reviews.llvm.org/D56370 llvm-svn: 356445
Diffstat (limited to 'clang-tools-extra/clangd/Protocol.cpp')
-rw-r--r--clang-tools-extra/clangd/Protocol.cpp115
1 files changed, 115 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp
index 4864eedcb87..dfd130a77a5 100644
--- a/clang-tools-extra/clangd/Protocol.cpp
+++ b/clang-tools-extra/clangd/Protocol.cpp
@@ -211,6 +211,61 @@ SymbolKind adjustKindToCapability(SymbolKind Kind,
}
}
+SymbolKind indexSymbolKindToSymbolKind(index::SymbolKind Kind) {
+ switch (Kind) {
+ case index::SymbolKind::Unknown:
+ return SymbolKind::Variable;
+ case index::SymbolKind::Module:
+ return SymbolKind::Module;
+ case index::SymbolKind::Namespace:
+ return SymbolKind::Namespace;
+ case index::SymbolKind::NamespaceAlias:
+ return SymbolKind::Namespace;
+ case index::SymbolKind::Macro:
+ return SymbolKind::String;
+ case index::SymbolKind::Enum:
+ return SymbolKind::Enum;
+ case index::SymbolKind::Struct:
+ return SymbolKind::Struct;
+ case index::SymbolKind::Class:
+ return SymbolKind::Class;
+ case index::SymbolKind::Protocol:
+ return SymbolKind::Interface;
+ case index::SymbolKind::Extension:
+ return SymbolKind::Interface;
+ case index::SymbolKind::Union:
+ return SymbolKind::Class;
+ case index::SymbolKind::TypeAlias:
+ return SymbolKind::Class;
+ case index::SymbolKind::Function:
+ return SymbolKind::Function;
+ case index::SymbolKind::Variable:
+ return SymbolKind::Variable;
+ case index::SymbolKind::Field:
+ return SymbolKind::Field;
+ case index::SymbolKind::EnumConstant:
+ return SymbolKind::EnumMember;
+ case index::SymbolKind::InstanceMethod:
+ case index::SymbolKind::ClassMethod:
+ case index::SymbolKind::StaticMethod:
+ return SymbolKind::Method;
+ case index::SymbolKind::InstanceProperty:
+ case index::SymbolKind::ClassProperty:
+ case index::SymbolKind::StaticProperty:
+ return SymbolKind::Property;
+ case index::SymbolKind::Constructor:
+ case index::SymbolKind::Destructor:
+ return SymbolKind::Method;
+ case index::SymbolKind::ConversionFunction:
+ return SymbolKind::Function;
+ case index::SymbolKind::Parameter:
+ return SymbolKind::Variable;
+ case index::SymbolKind::Using:
+ return SymbolKind::Namespace;
+ }
+ llvm_unreachable("invalid symbol kind");
+}
+
bool fromJSON(const llvm::json::Value &Params, ClientCapabilities &R) {
const llvm::json::Object *O = Params.getAsObject();
if (!O)
@@ -812,6 +867,66 @@ bool fromJSON(const llvm::json::Value &Params, InitializationOptions &Opts) {
return true;
}
+bool fromJSON(const llvm::json::Value &E, TypeHierarchyDirection &Out) {
+ auto T = E.getAsInteger();
+ if (!T)
+ return false;
+ if (*T < static_cast<int>(TypeHierarchyDirection::Children) ||
+ *T > static_cast<int>(TypeHierarchyDirection::Both))
+ return false;
+ Out = static_cast<TypeHierarchyDirection>(*T);
+ return true;
+}
+
+bool fromJSON(const llvm::json::Value &Params, TypeHierarchyParams &R) {
+ llvm::json::ObjectMapper O(Params);
+ return O && O.map("textDocument", R.textDocument) &&
+ O.map("position", R.position) && O.map("resolve", R.resolve) &&
+ O.map("direction", R.direction);
+}
+
+llvm::raw_ostream &operator<<(llvm::raw_ostream &O,
+ const TypeHierarchyItem &I) {
+ return O << I.name << " - " << toJSON(I);
+}
+
+llvm::json::Value toJSON(const TypeHierarchyItem &I) {
+ llvm::json::Object Result{{"name", I.name},
+ {"kind", static_cast<int>(I.kind)},
+ {"range", I.range},
+ {"selectionRange", I.selectionRange},
+ {"uri", I.uri}};
+
+ if (I.detail)
+ Result["detail"] = I.detail;
+ if (I.deprecated)
+ Result["deprecated"] = I.deprecated;
+ if (I.parents)
+ Result["parents"] = I.parents;
+ if (I.children)
+ Result["children"] = I.children;
+ return std::move(Result);
+}
+
+bool fromJSON(const llvm::json::Value &Params, TypeHierarchyItem &I) {
+ llvm::json::ObjectMapper O(Params);
+
+ // Required fields.
+ if (!(O && O.map("name", I.name) && O.map("kind", I.kind) &&
+ O.map("uri", I.uri) && O.map("range", I.range) &&
+ O.map("selectionRange", I.selectionRange))) {
+ return false;
+ }
+
+ // Optional fields.
+ O.map("detail", I.detail);
+ O.map("deprecated", I.deprecated);
+ O.map("parents", I.parents);
+ O.map("children", I.children);
+
+ return true;
+}
+
bool fromJSON(const llvm::json::Value &Params, ReferenceParams &R) {
TextDocumentPositionParams &Base = R;
return fromJSON(Params, Base);
OpenPOWER on IntegriCloud