diff options
| author | Ilya Biryukov <ibiryukov@google.com> | 2018-11-23 15:21:19 +0000 |
|---|---|---|
| committer | Ilya Biryukov <ibiryukov@google.com> | 2018-11-23 15:21:19 +0000 |
| commit | 19d75608f8c646df4cb89b83ef7004c0e4a437aa (patch) | |
| tree | 57cc6433b8ef0e612d8de1aa87097ff397ad8735 /clang-tools-extra/clangd/Protocol.cpp | |
| parent | 0fc5dcd1c8826fcbf68348cb0081518eb5411480 (diff) | |
| download | bcm5719-llvm-19d75608f8c646df4cb89b83ef7004c0e4a437aa.tar.gz bcm5719-llvm-19d75608f8c646df4cb89b83ef7004c0e4a437aa.zip | |
[clangd] Add support for hierarchical documentSymbol
Reviewers: ioeric, sammccall, simark
Reviewed By: sammccall
Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits
Differential Revision: https://reviews.llvm.org/D52311
llvm-svn: 347498
Diffstat (limited to 'clang-tools-extra/clangd/Protocol.cpp')
| -rw-r--r-- | clang-tools-extra/clangd/Protocol.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/Protocol.cpp b/clang-tools-extra/clangd/Protocol.cpp index d8369f3dcc1..bf32a969088 100644 --- a/clang-tools-extra/clangd/Protocol.cpp +++ b/clang-tools-extra/clangd/Protocol.cpp @@ -18,6 +18,7 @@ #include "llvm/ADT/SmallString.h" #include "llvm/Support/Format.h" #include "llvm/Support/FormatVariadic.h" +#include "llvm/Support/JSON.h" #include "llvm/Support/Path.h" #include "llvm/Support/raw_ostream.h" @@ -222,6 +223,11 @@ bool fromJSON(const json::Value &Params, ClientCapabilities &R) { if (CodeAction->getObject("codeActionLiteralSupport")) R.CodeActionStructure = true; } + if (auto *DocumentSymbol = TextDocument->getObject("documentSymbol")) { + if (auto HierarchicalSupport = + DocumentSymbol->getBoolean("hierarchicalDocumentSymbolSupport")) + R.HierarchicalDocumentSymbol = *HierarchicalSupport; + } } if (auto *Workspace = O->getObject("workspace")) { if (auto *Symbol = Workspace->getObject("symbol")) { @@ -449,6 +455,25 @@ json::Value toJSON(const CodeAction &CA) { return std::move(CodeAction); } +llvm::raw_ostream &operator<<(llvm::raw_ostream &O, const DocumentSymbol &S) { + return O << S.name << " - " << toJSON(S); +} + +llvm::json::Value toJSON(const DocumentSymbol &S) { + json::Object Result{{"name", S.name}, + {"kind", static_cast<int>(S.kind)}, + {"range", S.range}, + {"selectionRange", S.selectionRange}}; + + if (!S.detail.empty()) + Result["detail"] = S.detail; + if (!S.children.empty()) + Result["children"] = S.children; + if (S.deprecated) + Result["deprecated"] = true; + return Result; +} + json::Value toJSON(const WorkspaceEdit &WE) { if (!WE.changes) return json::Object{}; |

