[clangd] Clangd running with --experimental-modules-support crashes… · llvm/llvm-project@922c991 (original) (raw)

2 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -833,6 +833,10 @@ bool OverlayCDB::setCompileCommand(PathRef File,
833 833 std::unique_ptr
834 834 OverlayCDB::getProjectModules(PathRef File) const {
835 835 auto MDB = DelegatingCDB::getProjectModules(File);
836 +if (!MDB) {
837 +log("Failed to get compilation Database for {0}", File);
838 +return {};
839 + }
836 840 MDB->setCommandMangler([&Mangler = Mangler](tooling::CompileCommand &Command,
837 841 PathRef CommandPath) {
838 842 Mangler(Command, CommandPath);
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
1 +# A smoke test to check that clangd works without compilation database
2 +#
3 +# Windows have different escaping modes.
4 +# FIXME: We should add one for windows.
5 +# UNSUPPORTED: system-windows
6 +#
7 +# RUN: rm -fr %t
8 +# RUN: mkdir -p %t
9 +# RUN: split-file %s %t
10 +#
11 +# RUN: sed -e "s|DIR
12 +#
13 +# RUN: clangd -experimental-modules-support -lit-test < %t/definition.jsonrpc \
14 +# RUN: | FileCheck -strict-whitespace %t/definition.jsonrpc
15 +
16 +#--- A.h
17 +void printA();
18 +
19 +#--- Use.cpp
20 +#include "A.h"
21 +void foo() {
22 + print
23 +}
24 +
25 +#--- definition.jsonrpc.tmpl
26 +{
27 + "jsonrpc": "2.0",
28 + "id": 0,
29 + "method": "initialize",
30 + "params": {
31 + "processId": 123,
32 + "rootPath": "clangd",
33 + "capabilities": {
34 + "textDocument": {
35 + "completion": {
36 + "completionItem": {
37 + "snippetSupport": true
38 + }
39 + }
40 + }
41 + },
42 + "trace": "off"
43 + }
44 +}
45 +---
46 +{
47 + "jsonrpc": "2.0",
48 + "method": "textDocument/didOpen",
49 + "params": {
50 + "textDocument": {
51 + "uri": "file://DIR/Use.cpp",
52 + "languageId": "cpp",
53 + "version": 1,
54 + "text": "#include \"A.h\"\nvoid foo() {\n print\n}\n"
55 + }
56 + }
57 +}
58 +
59 +# CHECK: "message"{{.*}}printA{{.*}}(fix available)
60 +
61 +---
62 +{"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file://DIR/Use.cpp"},"context":{"triggerKind":1},"position":{"line":2,"character":6}}}
63 +---
64 +{"jsonrpc":"2.0","id":2,"method":"shutdown"}
65 +---
66 +{"jsonrpc":"2.0","method":"exit"}