10#include "clang/Basic/LLVM.h"
11#include "llvm/ADT/SmallString.h"
12#include "llvm/Support/LineIterator.h"
13#include "llvm/Support/MemoryBuffer.h"
14#include "llvm/Support/Path.h"
15#include "llvm/Support/raw_ostream.h"
21typedef const char *(*clangd_xpc_get_bundle_identifier_t)(void);
29 llvm_unreachable(
"Call to dladdr() failed");
30 llvm::SmallString<128> LibClangPath;
31 LibClangPath = llvm::sys::path::parent_path(
32 llvm::sys::path::parent_path(info.dli_fname));
33 llvm::sys::path::append(LibClangPath,
"lib",
"ClangdXPC.framework",
35 return std::string(LibClangPath.str());
39 xpc_type_t
Type = xpc_get_type(Object);
40 if (
Type == XPC_TYPE_DICTIONARY) {
48int main(
int argc,
char *argv[]) {
51 void *dlHandle = dlopen(LibPath.c_str(), RTLD_LOCAL | RTLD_FIRST);
53 llvm::errs() <<
"Failed to load framework from \'" << LibPath <<
"\'\n";
60 dlHandle,
"clangd_xpc_get_bundle_identifier");
61 xpc_connection_t conn = xpc_connection_create(
65 xpc_connection_set_event_handler(conn, ^(xpc_object_t event) {
66 if (event == XPC_ERROR_CONNECTION_INVALID) {
67 llvm::errs() <<
"Received XPC_ERROR_CONNECTION_INVALID.";
70 if (event == XPC_ERROR_CONNECTION_INTERRUPTED) {
71 llvm::errs() <<
"Received XPC_ERROR_CONNECTION_INTERRUPTED.";
79 xpc_connection_resume(conn);
82 llvm::ErrorOr<std::unique_ptr<MemoryBuffer>> Stdin =
83 llvm::MemoryBuffer::getSTDIN();
85 llvm::errs() <<
"Failed to get STDIN!\n";
88 for (llvm::line_iterator It(**Stdin,
true,
90 !It.is_at_eof(); ++It) {
92 if (
auto Request = json::parse(
Line)) {
94 xpc_connection_send_message(conn, Object);
96 llvm::errs() << llvm::Twine(
"JSON parse error: ")
97 << llvm::toString(Request.takeError());
static std::string getLibraryPath()
int main(int argc, char *argv[])
static void dumpXPCObject(xpc_object_t Object, llvm::raw_ostream &OS)
const char *(* clangd_xpc_get_bundle_identifier_t)(void)
const char * clangd_xpc_get_bundle_identifier()
Returns the bundle identifier of the Clangd XPC service.
xpc_object_t jsonToXpc(const json::Value &JSON)
json::Value xpcToJson(const xpc_object_t &XPCObject)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Some operations such as code completion produce a set of candidates.