Skip to content

Commit 6b85739

Browse files
committed
Merge from 'main' to 'sycl-web' (#1)
CONFLICT (content): Merge conflict in clang/include/clang/Driver/Options.td
2 parents 55cf399 + 7025fef commit 6b85739

File tree

368 files changed

+27026
-4332
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

368 files changed

+27026
-4332
lines changed

clang-tools-extra/clangd/ClangdLSPServer.cpp

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,15 @@ class ClangdLSPServer::MessageHandler : public Transport::MessageHandler {
258258
};
259259
}
260260

261+
template <typename Result>
262+
void bind(const char *Method,
263+
void (ClangdLSPServer::*Handler)(Callback<Result>)) {
264+
Calls[Method] = [Handler, this](llvm::json::Value RawParams,
265+
ReplyOnce Reply) {
266+
(Server.*Handler)(std::move(Reply));
267+
};
268+
}
269+
261270
// Bind a reply callback to a request. The callback will be invoked when
262271
// clangd receives the reply from the LSP client.
263272
// Return a call id of the request.
@@ -301,6 +310,12 @@ class ClangdLSPServer::MessageHandler : public Transport::MessageHandler {
301310
};
302311
}
303312

313+
void bind(const char *Method, void (ClangdLSPServer::*Handler)()) {
314+
Notifications[Method] = [Handler, this](llvm::json::Value RawParams) {
315+
(Server.*Handler)();
316+
};
317+
}
318+
304319
private:
305320
// Function object to reply to an LSP call.
306321
// Each instance must be called exactly once, otherwise:
@@ -443,6 +458,14 @@ class ClangdLSPServer::MessageHandler : public Transport::MessageHandler {
443458
};
444459
constexpr int ClangdLSPServer::MessageHandler::MaxReplayCallbacks;
445460

461+
template <>
462+
void ClangdLSPServer::MessageHandler::bind<NoParams>(
463+
const char *Method, void (ClangdLSPServer::*Handler)(const NoParams &)) {
464+
Notifications[Method] = [Handler, this](llvm::json::Value RawParams) {
465+
(Server.*Handler)(NoParams{});
466+
};
467+
}
468+
446469
// call(), notify(), and reply() wrap the Transport, adding logging and locking.
447470
void ClangdLSPServer::callRaw(StringRef Method, llvm::json::Value Params,
448471
Callback<llvm::json::Value> CB) {
@@ -500,6 +523,7 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
500523
if (Opts.UseDirBasedCDB) {
501524
DirectoryBasedGlobalCompilationDatabase::Options CDBOpts(TFS);
502525
CDBOpts.CompileCommandsDir = Opts.CompileCommandsDir;
526+
CDBOpts.ContextProvider = Opts.ContextProvider;
503527
BaseCDB =
504528
std::make_unique<DirectoryBasedGlobalCompilationDatabase>(CDBOpts);
505529
BaseCDB = getQueryDriverDatabase(llvm::makeArrayRef(Opts.QueryDriverGlobs),
@@ -647,17 +671,15 @@ void ClangdLSPServer::onInitialize(const InitializeParams &Params,
647671

648672
void ClangdLSPServer::onInitialized(const InitializedParams &Params) {}
649673

650-
void ClangdLSPServer::onShutdown(const ShutdownParams &Params,
651-
Callback<std::nullptr_t> Reply) {
674+
void ClangdLSPServer::onShutdown(Callback<std::nullptr_t> Reply) {
652675
// Do essentially nothing, just say we're ready to exit.
653676
ShutdownRequestReceived = true;
654677
Reply(nullptr);
655678
}
656679

657680
// sync is a clangd extension: it blocks until all background work completes.
658681
// It blocks the calling thread, so no messages are processed until it returns!
659-
void ClangdLSPServer::onSync(const NoParams &Params,
660-
Callback<std::nullptr_t> Reply) {
682+
void ClangdLSPServer::onSync(Callback<std::nullptr_t> Reply) {
661683
if (Server->blockUntilIdleForTest(/*TimeoutSeconds=*/60))
662684
Reply(nullptr);
663685
else
@@ -1445,8 +1467,7 @@ void ClangdLSPServer::onSemanticTokensDelta(
14451467
});
14461468
}
14471469

1448-
void ClangdLSPServer::onMemoryUsage(const NoParams &,
1449-
Callback<MemoryTree> Reply) {
1470+
void ClangdLSPServer::onMemoryUsage(Callback<MemoryTree> Reply) {
14501471
llvm::BumpPtrAllocator DetailAlloc;
14511472
MemoryTree MT(&DetailAlloc);
14521473
profile(MT);

clang-tools-extra/clangd/ClangdLSPServer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
9393
// Calls have signature void(const Params&, Callback<Response>).
9494
void onInitialize(const InitializeParams &, Callback<llvm::json::Value>);
9595
void onInitialized(const InitializedParams &);
96-
void onShutdown(const ShutdownParams &, Callback<std::nullptr_t>);
97-
void onSync(const NoParams &, Callback<std::nullptr_t>);
96+
void onShutdown(Callback<std::nullptr_t>);
97+
void onSync(Callback<std::nullptr_t>);
9898
void onDocumentDidOpen(const DidOpenTextDocumentParams &);
9999
void onDocumentDidChange(const DidChangeTextDocumentParams &);
100100
void onDocumentDidClose(const DidCloseTextDocumentParams &);
@@ -161,7 +161,7 @@ class ClangdLSPServer : private ClangdServer::Callbacks {
161161
Callback<SemanticTokensOrDelta>);
162162
/// This is a clangd extension. Provides a json tree representing memory usage
163163
/// hierarchy.
164-
void onMemoryUsage(const NoParams &, Callback<MemoryTree>);
164+
void onMemoryUsage(Callback<MemoryTree>);
165165

166166
std::vector<Fix> getFixes(StringRef File, const clangd::Diagnostic &D);
167167

clang-tools-extra/clangd/ClangdServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ void ClangdServer::formatOnType(PathRef File, llvm::StringRef Code,
407407
Result.push_back(replacementToEdit(Code, R));
408408
return CB(Result);
409409
};
410-
WorkScheduler.run("FormatOnType", File, std::move(Action));
410+
WorkScheduler.runQuick("FormatOnType", File, std::move(Action));
411411
}
412412

413413
void ClangdServer::prepareRename(PathRef File, Position Pos,
@@ -635,7 +635,7 @@ void ClangdServer::formatCode(PathRef File, llvm::StringRef Code,
635635
tooling::calculateRangesAfterReplacements(IncludeReplaces, Ranges),
636636
File)));
637637
};
638-
WorkScheduler.run("Format", File, std::move(Action));
638+
WorkScheduler.runQuick("Format", File, std::move(Action));
639639
}
640640

641641
void ClangdServer::findDocumentHighlights(

clang-tools-extra/clangd/CodeComplete.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,9 @@ bool semaCodeComplete(std::unique_ptr<CodeCompleteConsumer> Consumer,
11231123
// skip all includes in this case; these completions are really simple.
11241124
PreambleBounds PreambleRegion =
11251125
ComputePreambleBounds(*CI->getLangOpts(), *ContentsBuffer, 0);
1126-
bool CompletingInPreamble = PreambleRegion.Size > Input.Offset;
1126+
bool CompletingInPreamble = Input.Offset < PreambleRegion.Size ||
1127+
(!PreambleRegion.PreambleEndsAtStartOfLine &&
1128+
Input.Offset == PreambleRegion.Size);
11271129
if (Input.Patch)
11281130
Input.Patch->apply(*CI);
11291131
// NOTE: we must call BeginSourceFile after prepareCompilerInstance. Otherwise

clang-tools-extra/clangd/Config.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,19 @@ struct Config {
5252
Config(Config &&) = default;
5353
Config &operator=(Config &&) = default;
5454

55+
struct CDBSearchSpec {
56+
enum { Ancestors, FixedDir, NoCDBSearch } Policy = Ancestors;
57+
// Absolute, native slashes, no trailing slash.
58+
llvm::Optional<std::string> FixedCDBPath;
59+
};
60+
5561
/// Controls how the compile command for the current file is determined.
5662
struct {
57-
// Edits to apply to the compile command, in sequence.
63+
/// Edits to apply to the compile command, in sequence.
5864
std::vector<llvm::unique_function<void(std::vector<std::string> &) const>>
5965
Edits;
66+
/// Where to search for compilation databases for this file's flags.
67+
CDBSearchSpec CDBSearch = {CDBSearchSpec::Ancestors, llvm::None};
6068
} CompileFlags;
6169

6270
enum class BackgroundPolicy { Build, Skip };

clang-tools-extra/clangd/ConfigCompile.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,36 @@ struct FragmentCompiler {
263263
});
264264
});
265265
}
266+
267+
if (F.CompilationDatabase) {
268+
llvm::Optional<Config::CDBSearchSpec> Spec;
269+
if (**F.CompilationDatabase == "Ancestors") {
270+
Spec.emplace();
271+
Spec->Policy = Config::CDBSearchSpec::Ancestors;
272+
} else if (**F.CompilationDatabase == "None") {
273+
Spec.emplace();
274+
Spec->Policy = Config::CDBSearchSpec::NoCDBSearch;
275+
} else {
276+
if (auto Path =
277+
makeAbsolute(*F.CompilationDatabase, "CompilationDatabase",
278+
llvm::sys::path::Style::native)) {
279+
// Drop trailing slash to put the path in canonical form.
280+
// Should makeAbsolute do this?
281+
llvm::StringRef Rel = llvm::sys::path::relative_path(*Path);
282+
if (!Rel.empty() && llvm::sys::path::is_separator(Rel.back()))
283+
Path->pop_back();
284+
285+
Spec.emplace();
286+
Spec->Policy = Config::CDBSearchSpec::FixedDir;
287+
Spec->FixedCDBPath = std::move(Path);
288+
}
289+
}
290+
if (Spec)
291+
Out.Apply.push_back(
292+
[Spec(std::move(*Spec))](const Params &, Config &C) {
293+
C.CompileFlags.CDBSearch = Spec;
294+
});
295+
}
266296
}
267297

268298
void compile(Fragment::IndexBlock &&F) {

clang-tools-extra/clangd/ConfigFragment.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,13 @@ struct Fragment {
151151
///
152152
/// Flags added by the same CompileFlags entry will not be removed.
153153
std::vector<Located<std::string>> Remove;
154+
155+
/// Directory to search for compilation database (compile_comands.json etc).
156+
/// Valid values are:
157+
/// - A single path to a directory (absolute, or relative to the fragment)
158+
/// - Ancestors: search all parent directories (the default)
159+
/// - None: do not use a compilation database, just default flags.
160+
llvm::Optional<Located<std::string>> CompilationDatabase;
154161
};
155162
CompileFlagsBlock CompileFlags;
156163

clang-tools-extra/clangd/ConfigYAML.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class Parser {
9595
if (auto Values = scalarValues(N))
9696
F.Remove = std::move(*Values);
9797
});
98+
Dict.handle("CompilationDatabase", [&](Node &N) {
99+
F.CompilationDatabase = scalarValue(N, "CompilationDatabase");
100+
});
98101
Dict.parse(N);
99102
}
100103

0 commit comments

Comments
 (0)