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);
33 RealFileSystemProvider FS;
34 CodeCompleteOptions CCOpts;
35 CCOpts.EnableSnippets = false;
36 ClangdServer::Options Opts;
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 }
ClangdServer.h
clang::clangd::CodeCompleteOptions::EnableSnippets
bool EnableSnippets
When true, completion items will contain expandable code snippets in completion (e.g.
Definition: CodeComplete.h:46
clang::clangd::Transport
Definition: Transport.h:34
clang::clangd::ClangdLSPServer::run
bool run()
Run LSP server loop, communicating with the Transport provided in the constructor.
Definition: ClangdLSPServer.cpp:1279
FS
MockFSProvider FS
Definition: HeadersTests.cpp:119
clang::clangd::TextDocumentSyncKind::None
Documents should not be synced at all.
LLVMFuzzerTestOneInput
int LLVMFuzzerTestOneInput(uint8_t *data, size_t size)
Definition: clangd-fuzzer.cpp:24
CodeComplete.h
clang::clangd
Definition: AST.cpp:40
clang::clangd::CodeCompleteOptions
Definition: CodeComplete.h:39
clang::clangd::newJSONTransport
std::unique_ptr< Transport > newJSONTransport(std::FILE *In, llvm::raw_ostream &Out, llvm::raw_ostream *InMirror, bool Pretty, JSONStreamStyle Style)
Definition: JSONTransport.cpp:302
clang::clangd::Delimited
Definition: Transport.h:69
FSProvider.h
clang::clangd::ClangdServer::Options
Definition: ClangdServer.h:82
clang::clangd::ClangdLSPServer
This class exposes ClangdServer&#39;s capabilities via Language Server Protocol.
Definition: ClangdLSPServer.h:35
clang::clangd::RealFileSystemProvider
Definition: FSProvider.h:31
ClangdLSPServer.h