clang-tools  8.0.0
ClangdFuzzer.cpp
Go to the documentation of this file.
1 //===-- ClangdFuzzer.cpp - Fuzz clangd ------------------------------------===//
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 /// \file
11 /// \brief This file implements a function that runs clangd on a single input.
12 /// This function is then linked into the Fuzzer library.
13 ///
14 //===----------------------------------------------------------------------===//
15 
16 #include "ClangdLSPServer.h"
17 #include "ClangdServer.h"
18 #include "CodeComplete.h"
19 #include <cstdio>
20 #include <sstream>
21 
22 using namespace clang::clangd;
23 
24 extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {
25  if (size == 0)
26  return 0;
27 
28  // fmemopen isn't portable, but I think we only run the fuzzer on Linux.
29  std::FILE *In = fmemopen(data, size, "r");
30  auto Transport = newJSONTransport(In, llvm::nulls(),
31  /*InMirror=*/nullptr, /*Pretty=*/false,
32  /*Style=*/JSONStreamStyle::Standard);
33  CodeCompleteOptions CCOpts;
34  CCOpts.EnableSnippets = false;
36 
37  // Initialize and run ClangdLSPServer.
38  ClangdLSPServer LSPServer(*Transport, CCOpts, llvm::None, false, Opts);
39  LSPServer.run();
40  return 0;
41 }
int LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
bool EnableSnippets
When true, completion items will contain expandable code snippets in completion (e.g.
Definition: CodeComplete.h:47
bool run()
Run LSP server loop, communicating with the Transport provided in the constructor.
Documents should not be synced at all.
std::unique_ptr< Transport > newJSONTransport(std::FILE *In, llvm::raw_ostream &Out, llvm::raw_ostream *InMirror, bool Pretty, JSONStreamStyle Style)
This class exposes ClangdServer&#39;s capabilities via Language Server Protocol.