🐛 fix(core): dispatch cancellable requests asynchronously
This commit is contained in:
@@ -40,6 +40,77 @@ namespace lsp::test::provider
|
||||
}
|
||||
};
|
||||
|
||||
class FixtureBlock final : public core::IRequestProvider
|
||||
{
|
||||
public:
|
||||
std::string GetMethod() const override
|
||||
{
|
||||
return "test/block";
|
||||
}
|
||||
|
||||
std::string GetProviderName() const override
|
||||
{
|
||||
return "FixtureBlock";
|
||||
}
|
||||
|
||||
std::string ProvideResponse(const protocol::RequestMessage& request,
|
||||
core::ExecutionContext& context) override
|
||||
{
|
||||
const auto deadline =
|
||||
std::chrono::steady_clock::now() + std::chrono::seconds(2);
|
||||
while (!context.GetStopToken().stop_requested() &&
|
||||
std::chrono::steady_clock::now() < deadline)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
||||
}
|
||||
|
||||
protocol::ResponseMessage response;
|
||||
response.id = request.id;
|
||||
response.result = protocol::LSPAny(protocol::string("completed"));
|
||||
return codec::Serialize(response).value();
|
||||
}
|
||||
};
|
||||
|
||||
class FixtureThrow final : public core::IRequestProvider
|
||||
{
|
||||
public:
|
||||
std::string GetMethod() const override
|
||||
{
|
||||
return "test/throw";
|
||||
}
|
||||
|
||||
std::string GetProviderName() const override
|
||||
{
|
||||
return "FixtureThrow";
|
||||
}
|
||||
|
||||
std::string ProvideResponse(const protocol::RequestMessage&,
|
||||
core::ExecutionContext&) override
|
||||
{
|
||||
throw std::runtime_error("fixture request failure");
|
||||
}
|
||||
};
|
||||
|
||||
class FixtureThrowNotification final : public core::INotificationProvider
|
||||
{
|
||||
public:
|
||||
std::string GetMethod() const override
|
||||
{
|
||||
return "test/throwNotification";
|
||||
}
|
||||
|
||||
std::string GetProviderName() const override
|
||||
{
|
||||
return "FixtureThrowNotification";
|
||||
}
|
||||
|
||||
void HandleNotification(const protocol::NotificationMessage&,
|
||||
core::ExecutionContext&) override
|
||||
{
|
||||
throw std::runtime_error("fixture notification failure");
|
||||
}
|
||||
};
|
||||
|
||||
int RunCoreServerFixture()
|
||||
{
|
||||
spdlog::set_level(spdlog::level::off);
|
||||
@@ -48,6 +119,10 @@ namespace lsp::test::provider
|
||||
std::cout,
|
||||
[](core::RequestDispatcher& dispatcher) {
|
||||
dispatcher.RegisterRequestProvider(std::make_shared<FixtureInitialize>());
|
||||
dispatcher.RegisterRequestProvider(std::make_shared<FixtureBlock>());
|
||||
dispatcher.RegisterRequestProvider(std::make_shared<FixtureThrow>());
|
||||
dispatcher.RegisterNotificationProvider(
|
||||
std::make_shared<FixtureThrowNotification>());
|
||||
},
|
||||
2,
|
||||
"");
|
||||
|
||||
Reference in New Issue
Block a user