clang-tools  8.0.0
Conversion.cpp
Go to the documentation of this file.
1 //===--- Conversion.cpp - LSP data (de-)serialization through XPC - C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "xpc/Conversion.h"
11 #include "Logger.h"
12 #include "llvm/ADT/StringRef.h"
13 #include "llvm/Support/ScopedPrinter.h"
14 #include <string>
15 #include <vector>
16 
17 using namespace llvm;
18 namespace clang {
19 namespace clangd {
20 
21 xpc_object_t jsonToXpc(const json::Value &JSON) {
22  const char *const Key = "LSP";
23  xpc_object_t PayloadObj = xpc_string_create(llvm::to_string(JSON).c_str());
24  return xpc_dictionary_create(&Key, &PayloadObj, 1);
25 }
26 
27 json::Value xpcToJson(const xpc_object_t &XPCObject) {
28  if (xpc_get_type(XPCObject) == XPC_TYPE_DICTIONARY) {
29  const char *const LSP = xpc_dictionary_get_string(XPCObject, "LSP");
30  auto Json = json::parse(llvm::StringRef(LSP));
31  if (Json)
32  return *Json;
33  else
34  elog("JSON parse error: {0}", toString(Json.takeError()));
35  }
36  return json::Value(nullptr);
37 }
38 
39 } // namespace clangd
40 } // namespace clang
Some operations such as code completion produce a set of candidates.
static llvm::StringRef toString(SpecialMemberFunctionsCheck::SpecialMemberFunctionKind K)
Values in a Context are indexed by typed keys.
Definition: Context.h:41
void elog(const char *Fmt, Ts &&... Vals)
Definition: Logger.h:57
json::Value xpcToJson(const xpc_object_t &XPCObject)
Definition: Conversion.cpp:27
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
xpc_object_t jsonToXpc(const json::Value &JSON)
Definition: Conversion.cpp:21