clang-tools  10.0.0
clangd-fuzzer.cpp
Go to the documentation of this file.
1 //===-- ClangdFuzzer.cpp - Fuzz clangd ------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 ///
9 /// \file
10 /// This file implements a function that runs clangd on a single input.
11 /// This function is then linked into the Fuzzer library.
12 ///
13 //===----------------------------------------------------------------------===//
14 
15 #include "ClangdLSPServer.h"
16 #include "ClangdServer.h"
17 #include "CodeComplete.h"
18 #include "FSProvider.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::Delimited);
34  CodeCompleteOptions CCOpts;
35  CCOpts.EnableSnippets = false;
37 
38  // Initialize and run ClangdLSPServer.
39  ClangdLSPServer LSPServer(*Transport, FS, CCOpts, llvm::None, false,
40  llvm::None, Opts);
41  LSPServer.run();
42  return 0;
43 }
bool EnableSnippets
When true, completion items will contain expandable code snippets in completion (e.g.
Definition: CodeComplete.h:46
bool run()
Run LSP server loop, communicating with the Transport provided in the constructor.
MockFSProvider FS
Documents should not be synced at all.
int LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
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.