mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-04-02 13:12:09 +00:00
[clangd] Remove Bind, use C++14 lambda captures instead. NFC
llvm-svn: 369089
This commit is contained in:
parent
75be1a9e58
commit
b3c2f5d2ee
@ -603,8 +603,11 @@ void ClangdLSPServer::onCommand(const ExecuteCommandParams &Params,
|
|||||||
// 6. The editor applies the changes (applyEdit), and sends us a reply
|
// 6. The editor applies the changes (applyEdit), and sends us a reply
|
||||||
// 7. We unwrap the reply and send a reply to the editor.
|
// 7. We unwrap the reply and send a reply to the editor.
|
||||||
ApplyEdit(*Params.workspaceEdit,
|
ApplyEdit(*Params.workspaceEdit,
|
||||||
Bind(ReplyAfterApplyingEdit, std::move(Reply),
|
[Reply = std::move(Reply), ReplyAfterApplyingEdit](
|
||||||
std::string("Fix applied.")));
|
llvm::Expected<ApplyWorkspaceEditResponse> Response) mutable {
|
||||||
|
ReplyAfterApplyingEdit(std::move(Reply), "Fix applied.",
|
||||||
|
std::move(Response));
|
||||||
|
});
|
||||||
} else if (Params.command == ExecuteCommandParams::CLANGD_APPLY_TWEAK &&
|
} else if (Params.command == ExecuteCommandParams::CLANGD_APPLY_TWEAK &&
|
||||||
Params.tweakArgs) {
|
Params.tweakArgs) {
|
||||||
auto Code = DraftMgr.getDraft(Params.tweakArgs->file.file());
|
auto Code = DraftMgr.getDraft(Params.tweakArgs->file.file());
|
||||||
@ -624,8 +627,13 @@ void ClangdLSPServer::onCommand(const ExecuteCommandParams &Params,
|
|||||||
WorkspaceEdit WE;
|
WorkspaceEdit WE;
|
||||||
WE.changes.emplace();
|
WE.changes.emplace();
|
||||||
(*WE.changes)[File.uri()] = replacementsToEdits(Code, *R->ApplyEdit);
|
(*WE.changes)[File.uri()] = replacementsToEdits(Code, *R->ApplyEdit);
|
||||||
ApplyEdit(std::move(WE), Bind(ReplyAfterApplyingEdit, std::move(Reply),
|
ApplyEdit(
|
||||||
std::string("Tweak applied.")));
|
std::move(WE),
|
||||||
|
[Reply = std::move(Reply), ReplyAfterApplyingEdit](
|
||||||
|
llvm::Expected<ApplyWorkspaceEditResponse> Response) mutable {
|
||||||
|
ReplyAfterApplyingEdit(std::move(Reply), "Tweak applied.",
|
||||||
|
std::move(Response));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (R->ShowMessage) {
|
if (R->ShowMessage) {
|
||||||
ShowMessageParams Msg;
|
ShowMessageParams Msg;
|
||||||
|
@ -27,62 +27,6 @@ namespace clangd {
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
using Callback = llvm::unique_function<void(llvm::Expected<T>)>;
|
using Callback = llvm::unique_function<void(llvm::Expected<T>)>;
|
||||||
|
|
||||||
/// Stores a callable object (Func) and arguments (Args) and allows to call the
|
|
||||||
/// callable with provided arguments later using `operator ()`. The arguments
|
|
||||||
/// are std::forward'ed into the callable in the body of `operator()`. Therefore
|
|
||||||
/// `operator()` can only be called once, as some of the arguments could be
|
|
||||||
/// std::move'ed into the callable on first call.
|
|
||||||
template <class Func, class... Args> struct ForwardBinder {
|
|
||||||
using Tuple = std::tuple<typename std::decay<Func>::type,
|
|
||||||
typename std::decay<Args>::type...>;
|
|
||||||
Tuple FuncWithArguments;
|
|
||||||
#ifndef NDEBUG
|
|
||||||
bool WasCalled = false;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public:
|
|
||||||
ForwardBinder(Tuple FuncWithArguments)
|
|
||||||
: FuncWithArguments(std::move(FuncWithArguments)) {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
template <std::size_t... Indexes, class... RestArgs>
|
|
||||||
auto CallImpl(std::integer_sequence<std::size_t, Indexes...> Seq,
|
|
||||||
RestArgs &&... Rest)
|
|
||||||
-> decltype(std::get<0>(this->FuncWithArguments)(
|
|
||||||
std::forward<Args>(std::get<Indexes + 1>(this->FuncWithArguments))...,
|
|
||||||
std::forward<RestArgs>(Rest)...)) {
|
|
||||||
return std::get<0>(this->FuncWithArguments)(
|
|
||||||
std::forward<Args>(std::get<Indexes + 1>(this->FuncWithArguments))...,
|
|
||||||
std::forward<RestArgs>(Rest)...);
|
|
||||||
}
|
|
||||||
|
|
||||||
public:
|
|
||||||
template <class... RestArgs>
|
|
||||||
auto operator()(RestArgs &&... Rest)
|
|
||||||
-> decltype(this->CallImpl(std::index_sequence_for<Args...>(),
|
|
||||||
std::forward<RestArgs>(Rest)...)) {
|
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
assert(!WasCalled && "Can only call result of Bind once.");
|
|
||||||
WasCalled = true;
|
|
||||||
#endif
|
|
||||||
return CallImpl(std::index_sequence_for<Args...>(),
|
|
||||||
std::forward<RestArgs>(Rest)...);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Creates an object that stores a callable (\p F) and first arguments to the
|
|
||||||
/// callable (\p As) and allows to call \p F with \Args at a later point.
|
|
||||||
/// Similar to std::bind, but also works with move-only \p F and \p As.
|
|
||||||
///
|
|
||||||
/// The returned object must be called no more than once, as \p As are
|
|
||||||
/// std::forwarded'ed (therefore can be moved) into \p F during the call.
|
|
||||||
template <class Func, class... Args>
|
|
||||||
ForwardBinder<Func, Args...> Bind(Func F, Args &&... As) {
|
|
||||||
return ForwardBinder<Func, Args...>(
|
|
||||||
std::make_tuple(std::forward<Func>(F), std::forward<Args>(As)...));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// An Event<T> allows events of type T to be broadcast to listeners.
|
/// An Event<T> allows events of type T to be broadcast to listeners.
|
||||||
template <typename T> class Event {
|
template <typename T> class Event {
|
||||||
public:
|
public:
|
||||||
|
@ -40,11 +40,9 @@ template <typename T> struct CaptureProxy {
|
|||||||
operator llvm::unique_function<void(T)>() && {
|
operator llvm::unique_function<void(T)>() && {
|
||||||
assert(!Future.valid() && "conversion to callback called multiple times");
|
assert(!Future.valid() && "conversion to callback called multiple times");
|
||||||
Future = Promise.get_future();
|
Future = Promise.get_future();
|
||||||
return Bind(
|
return [Promise = std::move(Promise)](T Value) mutable {
|
||||||
[](std::promise<std::shared_ptr<T>> Promise, T Value) {
|
Promise.set_value(std::make_shared<T>(std::move(Value)));
|
||||||
Promise.set_value(std::make_shared<T>(std::move(Value)));
|
};
|
||||||
},
|
|
||||||
std::move(Promise));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~CaptureProxy() {
|
~CaptureProxy() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user